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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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