cs1h Posted November 12, 2007 Share Posted November 12, 2007 Hi, I have a script that moves data from one table to another and then deletes the original data, but I keep getting the following error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhosts\myroho.com\httpdocs\temp2\condeleteitems.php on line 17 The script is, <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database"); $sql = "SELECT * FROM items WHERE id = '$abc'"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "<img src=http://www.myroho.com/sorry_no_match.png>"; } else { while($row = mysql_fetch_array($result)) { $name = $row['name']; $Continent = $row['Continent']; $country = $row['country']; $town = $row['town']; $type = $row['type']; $alltype = $row['alltype']; $Email = $row['Email']; $Title = $row['Title']; $Abstract = $row['Abstract']; $Article = $row['Article']; $photo = $row['photo']; $sql2 = "insert into `old` (`name`, `Continent`, `country`, `town`, `type`, `alltype`, `Email`, `Title`, `Abstract`, `Article`, `photo`) values ('$name', '$Continent', '$country', '$town', '$type', '$alltype', '$Email', '$Title', '$Abstract', '$Article', '$photo')"; $query2 = mysql_query($sql2); ?> <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "DELETE FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); echo "<img src=http://www.myroho.com/item_deleted.png>"; } } ?> Does anyone know how to solve this? All help is very much appriciated, Colin Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 12, 2007 Share Posted November 12, 2007 It looks like you have an error in your query. You need to check and see if you have any mysql errors: <?php $con = mysql_connect($server, $db_user, $db_pass); if ($con === FALSE) { die(mysql_error()); } if (mysql_select_db("$database", $con) === FALSE) { die(mysql_error()); } $sql = "SELECT * FROM items WHERE id = '$abc'"; $result = mysql_query($sql); if ($result === FALSE) { die(mysql_error()); } ?> Use this type of checking for everything you send to a mysql call. Quote Link to comment Share on other sites More sharing options...
cs1h Posted November 12, 2007 Author Share Posted November 12, 2007 Hi, thanks for the reply, I changed my script so that it should tell me any errors. It now looks likle this. <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "SELECT * FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "<img src=http://www.myroho.com/sorry_no_match.png>"; } else { while($row = mysql_fetch_array($result)) { $name = $row['name']; $Continent = $row['Continent']; $country = $row['country']; $town = $row['town']; $type = $row['type']; $alltype = $row['alltype']; $Email = $row['Email']; $Title = $row['Title']; $Abstract = $row['Abstract']; $Article = $row['Article']; $photo = $row['photo']; $sql2 = "insert into `old` (`name`, `Continent`, `country`, `town`, `type`, `alltype`, `Email`, `Title`, `Abstract`, `Article`, `photo`) values ('$name', '$Continent', '$country', '$town', '$type', '$alltype', '$Email', '$Title', '$Abstract', '$Article', '$photo')"; $query2 = mysql_query($sql2) or die(mysql_error()); ?> <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "DELETE FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); echo "<img src=http://www.myroho.com/item_deleted.png>"; } } ?> <meta http-equiv="refresh" content="7; URL=expage.php"> The script actually works but the error always comes up. Any ideas? Thanks, Colin Quote Link to comment Share on other sites More sharing options...
cs1h Posted November 12, 2007 Author Share Posted November 12, 2007 Hi, thanks for the reply, I changed my script so that it should tell me any errors. It now looks likle this. <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "SELECT * FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "<img src=http://www.myroho.com/sorry_no_match.png>"; } else { while($row = mysql_fetch_array($result)) { $name = $row['name']; $Continent = $row['Continent']; $country = $row['country']; $town = $row['town']; $type = $row['type']; $alltype = $row['alltype']; $Email = $row['Email']; $Title = $row['Title']; $Abstract = $row['Abstract']; $Article = $row['Article']; $photo = $row['photo']; $sql2 = "insert into `old` (`name`, `Continent`, `country`, `town`, `type`, `alltype`, `Email`, `Title`, `Abstract`, `Article`, `photo`) values ('$name', '$Continent', '$country', '$town', '$type', '$alltype', '$Email', '$Title', '$Abstract', '$Article', '$photo')"; $query2 = mysql_query($sql2) or die(mysql_error()); ?> <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "DELETE FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); echo "<img src=http://www.myroho.com/item_deleted.png>"; } } ?> <meta http-equiv="refresh" content="7; URL=expage.php"> The script actually works but the error always comes up. Any ideas? Thanks, Colin Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 12, 2007 Share Posted November 12, 2007 Try keeping the while loop outside the if statement, hope it works... <?php include "dog.php"; $abc=$_POST['hiddenField']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db("$database") or die(mysql_error()) ; $sql = "SELECT * FROM items WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { if($num_rows == 0) { echo "<img src=http://www.myroho.com/sorry_no_match.png>"; } else { //while($row = mysql_fetch_array($result)) { $name = $row['name']; $Continent = $row['Continent']; $country = $row['country']; $town = $row['town']; $type = $row['type']; $alltype = $row['alltype']; $Email = $row['Email']; $Title = $row['Title']; $Abstract = $row['Abstract']; $Article = $row['Article']; $photo = $row['photo']; $sql2 = "insert into `old` (`name`, `Continent`, `country`, `town`, `type`, `alltype`, `Email`, `Title`, `Abstract`, `Article`, `photo`) values ('$name', '$Continent', '$country', '$town', '$type', '$alltype', '$Email', '$Title', '$Abstract', '$Article', '$photo')"; $query2 = mysql_query($sql2) or die(mysql_error()); } } ?> Quote Link to comment 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.