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

}

Link to comment
Share on other sites

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.

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.