evansste Posted March 8, 2012 Share Posted March 8, 2012 What I'm trying to do seems pretty simple and straight forward. However, I continue to get this same warning. The warning reads: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/vhosts/mysite.com/httpdocs/test.php on line 12 I'm trying to add the contents of one table to another. The following is the entire program that I'm trying to run. I've only changed, the "username" and "password". <?php$con = mysql_connect("localhost","username","xxxxxxx");if (!$con){ die('Could not connect: ' . mysql_error());}mysql_select_db("data",$con); $workarg = "INSERT INTO list1 SELECT * FROM list1R";$result = mysql_query($workarg) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "try it.",'<br />';}mysql_close($con);?> There's something about line 12 that the computer just doesn't like. As you can see, I used the "or die" option as a suggestion from other posts, but it doesn't even say why I get the warning. This may be because the program doesn't actually stop. It does function. It adds the contents of table "list1R" to "list1". But I still don't know why I get this message. Does anyone have any ideas as to why this may be happening? Thanks for your time, and any help you may be willing to offer. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2012 Share Posted March 8, 2012 Are you trying to use $workarg, or $result? The warning is correct, $result is not a MySQL resource. Link to comment Share on other sites More sharing options...
evansste Posted March 8, 2012 Author Share Posted March 8, 2012 "$workarg" is the argument for "mysql_query". I decided to place the argument in a variable so that the lines wouldn't be so long. I'm trying to use "mysql_fetch_array" on "$result", which gives me the warning. So why isn't "$result" a valid MySQL resource? I thought that maybe I had the syntax wrong for "$workarg". So I tried using the following for "$workarg": $workarg = "INSERT INTO list1 (rank,URL,IDnum) SELECT * FROM list1R"; I thought that because I didn't declare the columns for "list1" that this was the reason for the warning. However, even after using the above line for "$workarg", I still get the warning. I still don't understand why. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2012 Share Posted March 8, 2012 I read that code wrong, that's right. If the script isn't dying and you get the warning then I would use var_dump($result) after running the query to see what that variable is. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2012 Share Posted March 8, 2012 Whoops, I wasn't paying enough attention. Your query is an INSERT query. An INSERT query does not return a result, a SELECT query does. Check the notes for return values in the manual: http://www.php.net/manual/en/function.mysql-query.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.