Jump to content

Mysqli error


studentict
 Share

Recommended Posts

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...

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.