Mobile app version of vmapp.org
Login or Join
Ravi8258870

: 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

@Ravi8258870

Posted in: #Mysql #Php #Phpmyadmin #Sql

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Pope3001725

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();
}

?>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme