: Warning: mysql_fetch_array() expects parameter 1 to be resource I was trying to connect to my database through PHP but I keep getting the error: Warning: mysql_fetch_array() expects parameter
I was trying to connect to my database through PHP but I keep getting the error:
Warning: mysql_fetch_array() expects parameter 1 to be resource
I do not know what the problem is?
This is the code I have:
<?php
//Connect to the server
$connect = mysql_connect("localhost","root","");
//Connect to the database
mysql_select_db("firstdatab");
$query = mysql_query("SELECT * FROM users WHERE FavNumber = '44' ");
//Get Results
$rows = mysql_fetch_array($query);
$first_name = $rows['Name'];
echo "$first_name";
?>
Can someone tell me what is wrong?
More posts by @Ravi8258870
1 Comments
Sorted by latest first Latest Oldest Best
Everything in your code looks fine so your problem lies elsewhere. You need to use mysql_error() to tell you what you problem is.
<?php
//Connect to the server
$connect = mysql_connect("localhost","root","");
//Connect to the database
mysql_select_db("firstdatab");
$results = mysql_query("SELECT * FROM users WHERE FavNumber = '44' ");
if ($results)
{
$rows = mysql_fetch_array($results);
$first_name = $rows['Name'];
echo "$first_name";
}
else
{
echo mysql_error();
}
?>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.