Deepashika Deepashika - 3 months ago 18x
SQL Question

How to fix Warning: mysqli_query() expects parameter 2 to be string

<?php include_once 'db.php'; ?>
<form action='update.php' method='post'>
<table border='1'>
<?php $sql=m ysqli_query($con, "SELECT *FROM `experience` WHERE job_id=1"); $result=m ysqli_query($con,$sql); if ($result) { // The query was successful! } else { // The query failed. Show an error or something. } while($row=m ysqli_fetch_array($result)){
echo "<tr>"; echo "<td><input type='hidden' name='experi_id[]' value='".$row[ 'exp_id']. "' /></td>"; echo "<td>Experince :<input type='text' name='experi[]' value='".$row[ 'experience']. "' /></td>"; echo
"<td>year :<input type='text' name='year[]' value='".$row[ 'year']. "' /></td>"; echo "<td>job id :<input type='text' name='job_id[]' value='".$row[ 'job_id']. "' /></td>"; echo "</tr>"; } echo "<input type='submit' name='update' value='UPDATE' />"; mysqli_close($con); ?>

I need to echo all the experiences of
job_id 1
when I execute my code it gives following error

Warning: mysqli_query() expects parameter 2 to be string,

here is my code,

<!-- begin snippet: js hide: false console: true babel: false -->

Plz help me to fix the error


You can remove


Rename your $sql to $result.

Reason: You are trying to assing the resource genetated by first mysqli_query to your second mysqli_query call. In the second call of mysqli_query the second parameter is not a string but resource returned from your first call.