justineaguas Posted November 12, 2009 Share Posted November 12, 2009 I am using an array to check and compare the values in one variable, If the variable exists, the set of values will be inserted in the table of the variable. I am successful in inserting the values inside the mySQL table. However, I receive an error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\datbas\do_addpage_off.php on line 98 while ($row=mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error())) //error here LINE 98 { $temp=$row['BRGY_name']; if ($temp==$brgy) { include ('connect.php'); $get = "SELECT BRGY_id FROM BRGY_info WHERE BRGY_name='$brgy'"; $res = mysql_query($get) or die(mysql_error()) or die(mysql_error()); $row = mysql_fetch_array($res, MYSQL_ASSOC); $sql = "INSERT INTO OFF_info(OFF_fname,OFF_lname,OFF_position,OFF_contact,BRGY_id,OFF_status)VALUES('$fname','$lname','$position','$contact','{$row['BRGY_id']}','$num')"; $result = mysql_query($sql) or die(mysql_error()); echo " <br /><br /> <center> Thank you for adding a new barangay.<br /> <span class='linkBody'> <a href='addpage.php'>Add Another?</a> </span> <br /> <br /> </center>"; } Quote Link to comment https://forums.phpfreaks.com/topic/181256-solved-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 12, 2009 Share Posted November 12, 2009 Your code inside of the while() loop is reusing the $result variable, so the next time the while() condition is evaluated, you have a TRUE/FALSE value instead of the original result resource. Please be careful when reusing variables. Quote Link to comment https://forums.phpfreaks.com/topic/181256-solved-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-956206 Share on other sites More sharing options...
justineaguas Posted November 12, 2009 Author Share Posted November 12, 2009 So how do I fix this? I'm sorry I'm a newbie in PHP Quote Link to comment https://forums.phpfreaks.com/topic/181256-solved-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-956208 Share on other sites More sharing options...
sasa Posted November 12, 2009 Share Posted November 12, 2009 change variable name $result to $resul1 in this $sql = "INSERT INTO OFF_info(OFF_fname,OFF_lname,OFF_position,OFF_contact,BRGY_id,OFF_status)VALUES('$fname','$lname','$position','$contact','{$row['BRGY_id']}','$num')"; $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/181256-solved-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-956221 Share on other sites More sharing options...
justineaguas Posted November 12, 2009 Author Share Posted November 12, 2009 Thanks!! It fixed Quote Link to comment https://forums.phpfreaks.com/topic/181256-solved-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-956227 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.