Jump to content

Niss3

New Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by Niss3

  1. I'm using $_POST[] and $_SESSION[] arrays for a homemade quiz. When I turned display errors on in my PHP file I got alot of "undefined array" errors for those ones. Is there anyway I can allow those two variables to be undefined? Like, everything is working fine and I've accounted for them beeing NULL at times.
  2. Thank you, turning display errors on in the PHP file was incredible helpful! I will try to get the PDO working again!
  3. When I try this: $result = mysqli_query($opendb, "SELECT * FROM quiz"); $row = mysqli_fetch_assoc($result); print_r($row['namn']); I get niss3 printed. So everything seems to be working individually. Something with the if and while logic that isn't working? ------------ edit; I got it working. I had forgotten a simple ) after the while function. Still my original question remains, why do I have to use mysql_query (why doesn't query-> work).
  4. This is what I am trying to do: $mysqli = new mysqli("localhost", $username, $password, $database); $query = "SELECT * FROM table_name"; echo '<table border="0" cellspacing="2" cellpadding="2"> <tr> <td> <font face="Arial">Value1</font> </td> <td> <font face="Arial">Value2</font> </td> <td> <font face="Arial">Value3</font> </td> <td> <font face="Arial">Value4</font> </td> <td> <font face="Arial">Value5</font> </td> </tr>'; if ($result = $mysqli->query($query)) { while ($row = $result->fetch_assoc()) { $field1name = $row["col1"]; $field2name = $row["col2"]; $field3name = $row["col3"]; $field4name = $row["col4"]; $field5name = $row["col5"]; echo '<tr> <td>'.$field1name.'</td> <td>'.$field2name.'</td> <td>'.$field3name.'</td> <td>'.$field4name.'</td> <td>'.$field5name.'</td> </tr>'; } $result->free(); } And this is how I am trying to do it, but it doesn't work for some reason I can't figure out: <?php $opendb = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die(mysqli_error($opendb)); $query = ("SELECT * FROM quiz"); echo '<table border="0" cellspacing="2" cellpadding="2"> <tr> <td> <font face="Arial">Value1</font> </td> <td> <font face="Arial">Value2</font> </td> <td> <font face="Arial">Value3</font> </td> <td> <font face="Arial">Value4</font> </td> <td> <font face="Arial">Value5</font> </td> </tr>'; if ($result = mysqli_query($opendb, $query)) { while ($row = mysqli_fetch_assoc($result) { $field1name = $row["id"]; $field2name = $row["namn"]; $field3name = $row["points"]; $field4name = $row["level"]; echo '<tr> <td>'.$field1name.'</td> <td>'.$field2name.'</td> <td>'.$field3name.'</td> <td>'.$field4name.'</td> <td>'.$field5name.'</td> </tr>'; } mysqli_free($result); } mysqli_close($opendb); ?> This is what my database "quiz" looks like:
  5. I'm trying to print data from my SQL table, but there is something wrong, or something I don't get. Depending on which tutorial I am following certain commands simply just don't work for me. In this example, I should write; try{ $opendb = NEW PDO('mysql:host=$dbhost;dbname=$dbname','$dbuser','$dbpass'); }catch(PDOException $e){ die($e->getMessage()); } $result = $opendb->query("SELECT * FROM quiz"); $all = $result->fetchAll(); echo "<pre>"; print_r($all); But I couldn't get it working no matter what I tried. I think it might be the mysql -> commands that isn't working for me? But I am not sure. I rewrote the example with code I've been using earlier so it looked like this: $opendb = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die(mysqli_error($opendb)); $result = mysqli_query($opendb, "SELECT * FROM quiz"); $all = mysqli_fetch_all($result); echo("<pre>"); print_r($all); This one works just fine. I'm in the process of learning and I have no idea why the given example isn't working but it does exactly what it should when I use mysql_command() instead of ->command.
  6. $filn=("f\aquick".$spelb); include($filn.".php"); This is the sollution I came up with. Using include("path".$variable."filending") didnt work so I made some of it into a variable and it worked! I have no idea what the double quote string thingy is. It did not accept "fraga" as filename either, so I guess it is complex when putting files in folders.
  7. I didn't think of that, thanks! I did a quick test but it appears I have made some other misstake now. I will try again tomorrow and return here with the sollution I came up with, but I will definitly try to add a prefix to the files!
  8. Hello! I am a beginner in PHP and made a simple quiz page. I named the quiz questions 1.php 2.php 3.php and so on to make coding simple when loading next question. Now when I am done I wanted to "clean" things up. So I tried putting all the questions in a folder. That turned out to be a problem though. When I use; include(foldername\1.php); The file is not loaded. It works fine if I put it back in the main directory. After some error-searching I tried using letters instead of numbers, so I renamed 1.php to a.php and then suddenly it worked. I really would like to keep the filenames as numbers, so if anyone here could help me figure out how to allow single digit number php files in a folder with the include command, please do! Thank you very much!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.