Jump to content

Help with supplied argument


cs1h

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/76423-help-with-supplied-argument/
Share on other sites

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());

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.