Jump to content

[SOLVED] Help finding error


cs1h

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

		}
	}

?>

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.