Jump to content

Archived

This topic is now archived and is closed to further replies.

justineaguas

[SOLVED] Warning: mysql_fetch_array() expects parameter 1 to be resource

Recommended Posts

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>";
				}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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