Jump to content

Mysql_Fetch_Array Argument Not Valid


chwebdesigns

Recommended Posts

Hi,

 

When I try and execute the following PHP code, I get the following error message:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

What I am trying to do is 'copy' the data from a mysql table back into the same table but with one of the fields with a different number, if that makes sense? The PHP code I am working with which brings the error message is:

 

include("../setup/dbconnect.php");
   $sql = "select * from classes where term='$import'";
   #execute the query
$conn = @mysql_query($sql )
	  or die("Could not execute query");
   while ($row = mysql_fetch_array( $conn ) )
{
$day = $row['day'];
$time = $row['time'];
$grade = $row['grade'];
$teacher = $row['teacher'];
$sqlvalues = "('$day', '$time', '$grade', '$TermID', '$teacher')";
$sql2 = "insert into classes (day,time,grade,term,teacher) values $sqlvalues";
include("../setup/dbconnect.php");
#execute the query
$conn = @mysql_query($sql2 )
	  or die(mysql_error());
   if ($conn) {
 echo"<br />Classes Copied";
   }
}

 

Any help will be much appreciated. If you need any more info just let me know.

 

Many thanks in advance,

 

Cal

Link to comment
https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/
Share on other sites

I think the problem is you're overwriting $conn within the while loop:

 

#execute the query

$conn = @mysql_query($sql2 )

or die(mysql_error());

if ($conn) {

echo"<br />Classes Copied";

}

 

Instead, maybe try:

 

#execute the query

$conn2 = @mysql_query($sql2 )

or die(mysql_error());

if ($conn2) {

echo"<br />Classes Copied";

}

I don't know if it's the forum's editor that cause your indenting to become that way, though I doubt it. However, if your code does look like that, you really need to be indenting it properly. It'll make it a lot easier to read, and thus you avoid problems in the future. Not to mention it'll make it easier for others to help you.

 

Oh, and phpfreak is correct.

Archived

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

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