Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource


sagginigel

Recommended Posts

I receive the below error for my code

 

Warning: mysql_fetch_array() expects parameter 1 to be resource

 

Please help"

 

 

 

<!DOCTYPE html>

<html>

<body>

 

 

<?php

 

$fname=$_POST['fname'];

$lname=$_POST['lname'];

$uname=$_POST['uname'];

$pwd=$_POST['pwd'];

$email=$_POST['email'];

 

echo $fname."<br>";

 

echo $lname."<br>";

echo $uname."<br>";

echo $pwd."<br>";

echo $email."<br>";

 

 

 

mysql_connect("localhost","","") or

die("Could not connect: " . mysql_error());

 

mysql_select_db("projecto");

 

$result = mysql_query("SELECT uname,firstname FROM udata");

 

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

printf("ID: %s Name: %s", $row1[0], $row1[1]);

}

 

mysql_free_result($result);

 

 

 

 

/*

 

 

 

 

//$result = mysql_query("SELECT fname,password FROM udata");

 

if ($db_found)

{

$result = mysql_query("SELECT fname,password FROM udata");

while ( $db_field = mysql_fetch_assoc($result) )

{

if ($db_field['uname']==$uname && $db_field['password']==$pwd)

header( 'Location: www.youtube.com' ) ;

 

print $db_field['fname'] . "<BR>";

print $db_field['lname'] . "<BR>";

print $db_field['uname'] . "<BR>";

print $db_field['password'] . "<BR>";

 

}

 

 

 

}

else

{

 

print "Database NOT Found ";

mysql_close($db_handle);

 

 

}

*/

mysql_close($con);

?>

 

 

</body>

</html>

Link to comment
Share on other sites

I used the or DIE to evaluate step by step. the problem was root was the user name so the database was not getting selected in the first place.

Code after change

 

 

mysql_connect("localhost","root","") or DIE("Could not connect: " );//. mysql_error());

 

mysql_select_db("projecto") or DIE('Database name is not available!');

 

$result = mysql_query("SELECT uname,firstname FROM udata");

//echo $result;

 

if (false === $result) {

echo mysql_error();

}

 

 

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

printf("ID: %s Name: %s", $row[0], $row[1]);

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.