0

I have a php document that is connected to my database. I tried to get it to write a table with information from said database. However it will not write anything, not even an errormessage. I have tried the connection, it works. below is my code and a picture of the database. I am wery gratefull for all help. Thank you in advance!

  <?php

    //phpinfo();

        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);


$tjener= "localhost";
$brukernavn="root";
$passord="";
$database="karakterer";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$kobling= new mysqli($tjener, $brukernavn, $passord, $database);

if($kobling->connect_error){
  die( "noe gikk galt" . $kobling->connect_error);
}
else {
  echo "eg kjører";
}
$kobling->set_charset("utf8");

$sql= "select elevinfo.fNavn, elevinfo.ENavn, fødselsdato, lærer.fnavn, lærer.enavn, fagnavn, opprettet
from fag
join studieret
on fag.idStudieretning= studieret.idstudieretning
join lærer
on fag.idlærer = lærer.idlærer
join elevinfo
on studieret.idstudieretning = elevinfo.idstudieret";


$resultat= $kobling->query($sql);

echo "<table>";

while($rad=$resultat->fetch_assoc() ){
  var_dump($rad);
  // echo "hei";
  // $elevfnavn=$rad["elevinfo.fnavn"];
  // $elevenavn=$rad["elevinfo.ENavn"];
  // $fødselsdato=$rad["fødselsdato"];
  // $lærerF=$rad["lærer.fnavn"];
  // $fag =$rad["fagnavn"];
  //
  // echo "<tr>";
  // echo "<td>$elevfnavn</td>";
  // echo "<td> $elevenavn </td>";
  // echo "<td> $fødselsdato </td>";
  // echo "<td> $lærerF </td>";
  // echo "<td> $fag </td>";
  // echo "</tr>";
}
echo "</table>"


     ?>

database structure

line2509
  • 51
  • 7
  • What do you see if you turn on error reporting? https://stackoverflow.com/q/1053424/296555 and also https://phpdelusions.net/mysqli/error_reporting. – waterloomatt Nov 05 '19 at 19:50
  • you should add error management to you mysqli code to see if there is somthing mysql doesn't like – nbk Nov 05 '19 at 19:50
  • i tried pasting in This always works for me: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); and it did nothing. however i do get error messages if i purposely mess something up, like a semicolon or something – line2509 Nov 05 '19 at 19:51
  • Hoping _This always works for me:_ is just a typo. Please also apply the single line from the 2nd link. See any errors? Also, update your question with any edits your make to your code so we can all be on the same page. Thx – waterloomatt Nov 05 '19 at 19:53
  • yes it is:) - tried it, still no errormessages! – line2509 Nov 05 '19 at 19:55
  • Can you get any PHP to execute and display? Try a simple `phpinfo();` on line #1. – waterloomatt Nov 05 '19 at 19:56
  • try echo "". $elevfnavn . " "; I think you just need to concat the php variables inside the string – Wilco Nov 05 '19 at 19:57
  • 1
    @waterloomatt a lot of things suddenly happened.. got a big blue table with a lot of information – line2509 Nov 05 '19 at 19:58
  • @Jdub ... hmm it seems that it does not make any difference.. – line2509 Nov 05 '19 at 20:03
  • noticed i pasted the wrong code some time ago.. i am sorry. the newest updates are the correct code – line2509 Nov 05 '19 at 20:05
  • `display_errors = on;` should not be there (that is a php.ini directive), but your issue is at a lower level since you can't even output anything from `phpinfo();`. Final note from me, can you please rename your `$lærer` variable to match `$lærerF`? – waterloomatt Nov 05 '19 at 20:05
  • _got a big blue table with a lot of information_ - cool - remove `phpinfo()`. That just dumps out your configuration. If that it displaying, then you can move on to the next debugging step. – waterloomatt Nov 05 '19 at 20:06
  • @waterloomatt thank you for all you help. i tried renaming too, did not work. i am new at this so it is proabaly a beginners mistake – line2509 Nov 05 '19 at 20:07
  • @waterloomatt it seems that the problem lies with my while loop as everything i write outside it now shows up on the site – line2509 Nov 05 '19 at 20:09
  • Nice. To debug that, comment out everything inside your loop, and add `var_dump($rad);`. This will dump out the contents of each row. Now replace your commented out code making sure that the array key (`$rad["->elevinfo.fnavn – waterloomatt Nov 05 '19 at 20:16
  • it did not dump out anything.. – line2509 Nov 05 '19 at 20:33
  • Then your query isn't returning any results and therefore not going into your while loop. Have you tried running your query directly in your database? Ex. do you have phpMyAdmin or another tool to run queries against? – waterloomatt Nov 05 '19 at 20:37
  • Yes, i use mysql workbench. i ran my select there and it worked. – line2509 Nov 05 '19 at 20:38
  • Hello @waterloomatt Thanks for all help.i made a new document and pasted the old code in there. suddenly it worked. i have truly no idea why. thank you so much again for your time and effort. i have learned a lot. :) – line2509 Nov 05 '19 at 20:45

0 Answers0