This question already has an answer here:
I have this PHP code:
$con = mysqli_connect("localhost","root","","dbjobsheetsf");
$sql1 = "SELECT colDate FROM tbljs ";
$queryR = mysql_query($sql1);
$p = 0;
echo "<select name=\"jsGetDate\">";
while($r = mysql_fetch_array($queryR)) {
echo "<option value=".$r["colDate"].">".$r["colDate"]."</option>";
}
echo "</select>";
mysqli_close($con);
I'm getting the error:
mysql_fetch_array() expects parameter 1 to be resource, boolean given
Is there anyway to solve this problem?
Problem Solved Thank you sir John Robertson you were a big help!
</div>
Be consistent on using mysqli_* functions
otherwise it will mess up your program. So use mysqli_* functions
since mysql_* functions
are deprecated and will no longer be used in the future.
NOTICE: mysqli_query
requires two parameters the $link and the query. Make sure that you are doing the query to the exact table and table column
$con = mysqli_connect("localhost","root","","dbjobsheetsf");
$sql1 = "SELECT colDate FROM tbljs ";
$queryR = mysqli_query($con, $sql1);
$p = 0;
echo "<select name=\"jsGetDate\">";
while($r = mysqli_fetch_array($queryR)) {
echo "<option value=".$r["colDate"].">".$r["colDate"]."</option>";
}
echo "</select>";
mysqli_close($con);
boolean always happen when you have input wrong table . are you sure that your table name is tbljs ? i also have experienced this. you should try look out on your $con and your table name. if they are correct, i think there are no error in mysql_fetch_array
Dont mix mysql
and mysqli
change the following lines to mysqli
$con = mysqli_connect("localhost","root","","dbjobsheetsf");
$sql1 = "SELECT colDate FROM tbljs ";
$queryR = mysqli_query($con, $sql1);
$p = 0;
echo "<select name=\"jsGetDate\">";
while($r = mysqli_fetch_array($queryR)) {
echo "<option value=".$r["colDate"].">".$r["colDate"]."</option>";
}
echo "</select>";
mysqli_close($con);