chwebdesigns Posted September 24, 2012 Share Posted September 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/ Share on other sites More sharing options...
phpfreak Posted September 24, 2012 Share Posted September 24, 2012 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/#findComment-1380625 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/#findComment-1380650 Share on other sites More sharing options...
Barand Posted September 24, 2012 Share Posted September 24, 2012 Oh, and phpfreak is correct. I'm sure he'll be truly ecstatic to know he has your endorsement Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/#findComment-1380663 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 <accent type="british_upperclass">I should certainly hope so.</accent> Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/#findComment-1380672 Share on other sites More sharing options...
chwebdesigns Posted September 25, 2012 Author Share Posted September 25, 2012 Many thanks @phpfreak , has worked now Also @Christian F. it is a slight mix between the 2 really, it is intendented slightly different in my code editor, but I know they aren't the best indentations!! Thanks, Cal Quote Link to comment https://forums.phpfreaks.com/topic/268748-mysql_fetch_array-argument-not-valid/#findComment-1380799 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.