Jump to content

Object of class mysqli_result could not be converted to string


yami
 Share

Go to solution Solved by Barand,

Recommended Posts

$resulti = mysqli_query($connection , "INSERT INTO cart(idItem,idUser) VALUES('$idd','$iduser')");
				
					if(!$resulti){
						die('Query failed!' . mysqli_error($connection));
					  }

I am just trying to insert some data into a db table but this error keeps showing..any ideas how to fix it?

Link to comment
Share on other sites

Are you sure about the line?  I don't see any attempt to convert a var unless it is the two Values in your query statement.  Try separating the query build from the query call and see what happens.

$q  =......

mysqli__query($connection, $q);

Link to comment
Share on other sites

I tried that too..I tried to separate them but it shows the same error!

I have the same query in another php file but it does not show any error so I cannot tell what is wrong..

Link to comment
Share on other sites

So I have an if-else statement full of queries and it is the else part where there is an error and here it is:

else{
				$nameuser = $_SESSION['username'];
				$iduser = $connection->query("SELECT idCustomer FROM customer WHERE username='$nameuser'");
				if(!$iduser){
					die('Query failed!' . mysqli_error($connection));
				  }

				if (isset($_POST['idd']) && $_POST['idd']!=""){
					$idd = $_POST['idd'];
				// echo $idd;
			
	
				// $query ="INSERT INTO cart(idItem,idUser) VALUES('$idd','$iduser')";
				$resulti = mysqli_query($connection , "INSERT INTO cart(idItem,idUser) VALUES('$idd','$iduser')");
				
					if(!$resulti){
						die('Query failed!' . mysqli_error($connection));
					  }
				

			}
		}
<input type='hidden' name='idd' id='idd' >

the exact error message: Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\wamp64\www\index.php on line 134

it is the last query's line

is it enough?

Link to comment
Share on other sites

  • Solution
Posted (edited)

Your problem is with $iduser

image.png.9ed56ec37bd5b6cc989ffd4566670fcf.png

It is the result of the first query yet you are attemping to insert it as a value in the second query. You need to fetch the id from the resultset to use its value.

Edited by Barand
  • Thanks 1
Link to comment
Share on other sites

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.