studentict Posted May 6, 2014 Share Posted May 6, 2014 Hi everyone, I'm studying ICT in Belgium and we have the task to design a website. So I'm working on a website for like parties, events and stuff. So I wrote the following code : <?php $link = mysqli_connect("localhost","root","","partyguide") or die ('Er ging iets mis: ' . mysqli_connect_error($link)); $sql = "SELECT * FROM evenementen"; if(!empty($_POST)) { $sql.="WHERE id='" .$_POST["evenement_datum"]."'"; } $result = mysqli_query($link,$sql); ?> <html> <head> <title>Evenementen</title> </head> <body> <?php if(empty($_POST)) { $link = mysqli_connect("localhost","root","","partyguide") or die ('Er ging iets mis: ' . mysqli_connect_error($link)); ?> <form name="form1" action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post"> Kies een datum : <select name="evenement_datum"> <?php while($rij = mysqli_fetch_array($result)){ echo("<option value=\"".$rij['datum']."\">".$rij['datum']."</option>\n"); }?> </select> <input type="Submit" value="Toon evenementen!"> </form> <?php }else{ ?> <table width="1000" height="500" align="center" border="1" bordercolor="blue"> <?php while($rij = mysqli_fetch_array($result)){ ?> <tr> <td><?php echo $rij['datum']; ?></td> <td><?php echo $rij['plaats']; ?></td> <td><?php echo $rij['tijdstip']; ?></td> <td><?php echo $rij['naam'] ?></td> </tr> <?php } ?> </table> <?php } ?> </body> </html> So I'm trying to have an option box which displays the date's of events in my database, If i click a date, it has to display all the events in a table, but whenever I click one, following error pops up : Catchable fatal error: Object of class mysqli_result could not be converted to string in D:\www\evenementen.php on line 11 Can anyone help me with this? My teacher doesn't know how to solve this so I hope anyone of you could... Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/ Share on other sites More sharing options...
mac_gyver Posted May 6, 2014 Share Posted May 6, 2014 the error means you are trying to use $result as a string (echo it, concatenate it...). since the posted code doesn't contain anything like that anywhere, let alone line 11, the posted code doesn't correspond to the error message. the error is either from some other file or the code you posted wasn't saved/uploaded to the server. note: mysqli_connect_error() does NOT have a call time parameter. you use of mysqli_connect_error($link) may cause an error unto itself should a connection error occur. also, why are you making a database connection in two places in your code? once would be enough. Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478495 Share on other sites More sharing options...
studentict Posted May 6, 2014 Author Share Posted May 6, 2014 I'm sorry, that was the wrong error, this is the one of this file which i'm having trouble with : Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\www\evenementen.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478496 Share on other sites More sharing options...
Psycho Posted May 6, 2014 Share Posted May 6, 2014 I'm sorry, that was the wrong error, this is the one of this file which i'm having trouble with : Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\www\evenementen.php on line 38 That almost always mean that the query failed and the result of the query is a Boolean (i.e FALSE). You need to check your query calls for errors since those errors occur in MySQL and not in PHP. This is the quick and dirty way to check it, but should not be used when used in a production environment $result = mysqli_query($link,$sql) or die("Query: $sql<br>Error: " . mysqli_error($link); Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478498 Share on other sites More sharing options...
studentict Posted May 6, 2014 Author Share Posted May 6, 2014 The error is now solved but it doesn't read the data in a table, can you someone see what's miss with my table? From line 38 till 47? Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478499 Share on other sites More sharing options...
jazzman1 Posted May 7, 2014 Share Posted May 7, 2014 How did you fix the error(s)? Why are you overriding the link identifier? Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478506 Share on other sites More sharing options...
studentict Posted May 7, 2014 Author Share Posted May 7, 2014 I just added a space at line 7, in front of WHERE, but now it doesn't read my data in a table Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478608 Share on other sites More sharing options...
Psycho Posted May 7, 2014 Share Posted May 7, 2014 (edited) Then, most likely, there are no matching records in the database.Echo the query to the page and then run it in PHPMyAdmin, or whatever DB management app you are using. You could also add some debugging code to verify this $result = mysqli_query($link,$sql); //Debugging lines $rowcount = mysqli_num_rows($result); echo "There were {$rowcount} record returned for the query:<br>{$sql}"; Edited May 7, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/288294-mysqli-error/#findComment-1478610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.