cs1h Posted November 7, 2007 Share Posted November 7, 2007 Hi, I have a script that moves data from one table to another and then it deletes it from the original one. The problem is that I get this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhosts\myroho.com\httpdocs\temp2\delete_test.php on line 17 Can anyone tell me how to solve this, 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") or die(mysql_error()) ; $sql = "SELECT * FROM test 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']; mysql_query($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')"); ?> <?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 test WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); echo 'The query was: '.$sql.'<br />'; echo "Deletion success<br /> <a href='proeditor.php'>Click here</a> to return to the admin home."; } } ?> Thanks, Colin Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 7, 2007 Share Posted November 7, 2007 The second query isn't right. So change this mysql_query($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')"); To $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()); Add die() statements to the end of all your queries $sql = "SELECT * FROM test WHERE id = '$abc'"; $result = mysql_query($sql)or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
cs1h Posted November 7, 2007 Author Share Posted November 7, 2007 I made those changes and I am still getting the same errors. The script now looks like 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 jobs 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)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 jobs WHERE id = '$abc'"; $result = mysql_query($sql) or die(mysql_error()); echo 'The query was: '.$sql.'<br />'; echo "Deletion success<br /> <a href='expage.php'>Click here</a> to return home."; } } ?> Any ideas? Colin Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 7, 2007 Share Posted November 7, 2007 You forgot your die() on this line $result = mysql_query($sql); Quote Link to comment Share on other sites More sharing options...
cs1h Posted November 9, 2007 Author Share Posted November 9, 2007 I made the change to 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 'The query was: '.$sql.'<br />'; echo "Deletion success<br /> <a href='expage.php'>Click here</a> to return home."; } } ?> But I still get this 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 Any one got any ideas? Thanks, Colin Quote Link to comment Share on other sites More sharing options...
Grodo Posted November 9, 2007 Share Posted November 9, 2007 could be that your missing a space $result = mysql_query($sql)or die(mysql_error()); try this $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
cs1h Posted November 9, 2007 Author Share Posted November 9, 2007 no sorry still getting an error. Any more ideas? Cheers for the help so far Colin 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.