sagginigel Posted January 30, 2013 Share Posted January 30, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
sagginigel Posted January 31, 2013 Author Share Posted January 31, 2013 Please help me I am stuck with this. Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1409301 Share on other sites More sharing options...
KentZen Posted January 31, 2013 Share Posted January 31, 2013 (edited) You can use var_dump method to print $result variable from '$result = mysql_query("SELECT uname,firstname FROM udata");';Issue that in this topic. let me see whether the variable is empty or not . ok? Edited January 31, 2013 by KentZen Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1409302 Share on other sites More sharing options...
sagginigel Posted January 31, 2013 Author Share Posted January 31, 2013 This is solved.... I managed. Will come back if I need more Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1409304 Share on other sites More sharing options...
sagginigel Posted January 31, 2013 Author Share Posted January 31, 2013 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]); } Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1409305 Share on other sites More sharing options...
KentZen Posted January 31, 2013 Share Posted January 31, 2013 (edited) OK.What 's the url of your facebook.give me Edited January 31, 2013 by KentZen Quote Link to comment https://forums.phpfreaks.com/topic/273845-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1409308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.