Page 1 of 2

need help with confirm to delete page

Posted: Mon May 17, 2004 1:06 pm
by mikewooten
i'm creating a confirm to delete page and i'm getting many errors.
can someone help me in getting these errors fixed.
the errors that i'm getting is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/delete_confirm5.php on line 28
line 28 is $num=mysql_num_rows($result);

and

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/mwooten1/public_html/wootenmusic7/admintest/delete_confirm5.php on line 73
line 73 is while($query_data = mysql_fetch_array($result)) {

i have a page where there are many items in the database. i have a link that deletes a row, and a link that confirms the delete before the row is deleted. i need help with getting the confirm page working. can anyone help me with this code that i have so that it works right and no errors show up.
any help would be appreciated.
thanks

here's my code:

Code: Select all

<?php




$dbname = "database"; 
$tblname = "tablename"; 
$linkid = mysql_connect("localhost", "username", "password")  
or die("Couldn't connect."); 
$db = mysql_select_db($dbname, $linkid) 
    or die("Couldn't select database."); 
mysql_query ("SELECT * FROM $tblname where itemId = $itemId"); 
echo "$select<br>";				
	$host    ="localhost";
	$dbuser="username";
	$dbpass="password";
	$database="database";	
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");    
$query="SELECT * FROM $tblname where itemId = $itemId ORDER BY itemId ASC";  
$result=mysql_query($query, $linkid);
$num=mysql_num_rows($result);  
echo "$num";
include("db2.php");
	switch($_GET["action"])
	{
    case "delete_item_row":
		{
			DeleteItemRow($_GET["id"]);		
			break;
		}		
		case "delete_proditem_row":
		{
			DeleteProdItemRow($_GET["id"]);		
			break;		
		}		
		case "delete_order_row":
		{
			DeleteOrderRow($_GET["id"]);		
			break;
		}		
		case "show_item_row":
		{
			ShowItemRow($_GET["id"]);		
			break;
		}		
		case "update_item_row":
				UpdateItemRow($_GET["id"]);		
        default:    
   }  
   function DeleteItemRow($itemId)
	{
		// Uses an SQL delete statement to remove an item from the users cart
		global $dbServer, $dbUser, $dbPass, $dbName;
		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);		 
        $result = mysql_query("DELETE FROM user WHERE itemId=$itemId");
	}
    function DeleteProdItemRow($itemId)
	{
		// Uses an SQL delete statement to remove an item from the users cart
		global $dbServer, $dbUser, $dbPass, $dbName;
		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);		 
        $result = mysql_query("DELETE FROM items WHERE itemId=$itemId");
	}   
    function DeleteOrderRow($id)
	{
		// Uses an SQL delete statement to remove an item from the users cart
		global $dbServer, $dbUser, $dbPass, $dbName;
		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);		 
		//mysql_query("delete * from cart");
        $result = mysql_query("DELETE FROM checkout WHERE id=$id");
	}
   function ShowItemRow($itemId)
	{
		// Uses an SQL delete statement to remove an item from the users cart
		global $dbServer, $dbUser, $dbPass, $dbName;
		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);		 
        $result = mysql_query("SELECT * FROM items WHERE itemId=$itemId");
	}	
	 function UpdateItemRow($itemId)
	{
		// Uses an SQL delete statement to remove an item from the users cart
		global $dbServer, $dbUser, $dbPass, $dbName;
		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
		 $txtItemName = $_POST['txtItemName'];
            $txtItemDesc = $_POST['txtItemDesc'];
            $txtItemPrice = $_POST['txtItemPrice'];
            $txtItemImage = $_POST['txtItemImage'];			
		 $result = mysql_query("update items set itemName='$txtItemName', itemDesc='$txtItemDesc', itemPrice='$txtItemPrice', itemPrice='$txtItemPrice', ItemImage='$txtItemImage' where itemID = $txtItemID");
	} 
echo "<strong><center>Customers</center></strong>";
echo "<br><br>";  
echo "<a href='http://www.wootenmedia.com/folder1/folder2/showprod4.php'>SHOW products</a> | <a href='http://www.wootenmedia.com/folder1/folder2/add3_1.php'>ADD products</a> | <a href='http://www.wootenmedia.com/folder1/folder2/customers.php'>VIEW customers</a> | <a href='http://www.wootenmedia.com/folder1/folder2/orders.php'>VIEW orders</a> | <a href='http://www.wootenmedia.com/folder1/folder2/update1_1.php'>UPDATE products</a> |"; 
echo "<br><br>";  
echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' width='100%'>";  
echo "<tr>";
echo "<td width='5%'><strong><center>cat id</center></strong></td>";
echo "<td width='6%'><strong><center>item id</center></strong></td>";
echo "<td width='10%'><strong><center>product item</center></strong></td>"; 
echo "<td width='10%'><strong><center>item name</center></strong></td>"; 
echo "<td width='20%'><strong><center>item image</center></strong></td>";
echo "<td width='30%'><strong><center>item desc</center></strong></td>";
echo "<td width='14%'><strong><center>item price</center></strong></td>";
echo "<td width='5%'><strong><center>Delete</td>";
echo "</tr>";
while($query_data = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>$query_data[0]</td>";
echo "<td>$query_data[1]</td>";
echo "<td>$query_data[2]</td>"; 
echo "<td>$query_data[3]</td>";
echo "<td>$query_data[4]</td>";
echo "<td>$query_data[5]</td>";
echo "<td>$query_data[6]</td>";
echo "<td>";
?>
<a href="add4_5.php?action=update_item_row&id=<?php echo $query_data[1];  ?>">update</a>
<br>
<br>
<a href="showprod4.php?action=delete_item_row&id=<?php echo $query_data[1];  ?>">delete</a>
<br>
<br>
<a href="delete_confirm4_1.php?action=show_item_row&id=<?php echo $query_data[1];  ?>">confirm</a>
<?
echo "</td>";
echo "</tr>";
}     
echo "</table>"; 
if (isset($itemId)) { 
echo "Confirm the information below ..............................<br>\n"; 
echo "<a href="delete_confirm5.php?id=$id">YES</a>\n"; 
echo "&nbsp;&nbsp;&nbsp;&nbsp;\n"; 
echo "<a href="showprod4.php">NO</a>\n"; 
}
                                                                            




?>

Posted: Mon May 17, 2004 5:09 pm
by tim
maybe if you added a few

or die (mysql_error()); at the end of your MySQL commands

you would see why your query is failing.

:? 8O :? 8O

Posted: Mon May 17, 2004 9:45 pm
by d3ad1ysp0rk
Why do you connect to the same host twice..?

and you also have a random SELECT query in the beggining that does nothing..

Posted: Mon May 17, 2004 9:56 pm
by mikewooten
which connection should i get rid of?
which select query does nothing and
which select query should i get rid of?
thanks

?

Posted: Tue May 18, 2004 12:14 pm
by mikewooten
??

Posted: Tue May 18, 2004 1:39 pm
by ol4pr0
not sure but i think he is referring to this part

Code: Select all

$linkid = mysql_connect("localhost", "username", "password") 
or die("Couldn't connect.");
$db = mysql_select_db($dbname, $linkid)
    or die("Couldn't select database.");
mysql_query ("SELECT * FROM $tblname where itemId = $itemId");
echo "$select<br>";            
   $host    ="localhost";
   $dbuser="username";
   $dbpass="password";
   $database="database";

Posted: Tue May 18, 2004 5:42 pm
by mikewooten
what else should i try to get rid of the error? i added the mysql_error() and i still get the same error message.
what should i try so that this will work?
thanks

Posted: Tue May 18, 2004 5:50 pm
by tim
might help for you to tell us the error msg your getting.


8)

Posted: Tue May 18, 2004 6:01 pm
by mikewooten
i'm gettting the same error message as above which is

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/update.php on line 33

and

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/update.php on line 52

line 33 is : $num=mysql_num_rows($result);
line 52 is : while($query_data = mysql_fetch_row($result)) {

thanks

Posted: Tue May 18, 2004 6:08 pm
by feyd
mikewooten wrote:i'm gettting the same error message as above which is

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/update.php on line 33
$result=mysql_query($query, $linkid);
failed, most likely.
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/update.php on line 52
this fails because $result isn't really set by that point. All your functions don't return their $result.

Posted: Tue May 18, 2004 6:35 pm
by zenabi
mikewooten wrote:which connection should i get rid of?
which select query does nothing and
which select query should i get rid of?
thanks
Try only having one connection and one SELECT statement. Which ones? The ones you need, you should know.

Once you have done that, but still get errors then post your updated code.

Posted: Tue May 18, 2004 8:25 pm
by mikewooten
how do you set result?
thanks

Posted: Tue May 18, 2004 8:35 pm
by feyd
in your case statements...

Code: Select all

$result = <your function call here>
in your functions...

Code: Select all

// all the function code goes before this..
return $result;
}

Posted: Tue May 18, 2004 8:45 pm
by mikewooten
here's my new updated code and i still get the same errors:
how can this be fixed so that i don't get these errors?
thanks
the errors are
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/username/public_html/wootenmusic7/admintest/update.php on line 32

line 32 is $num=mysql_num_rows($result);

and

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/mwooten1/public_html/wootenmusic7/admintest/update.php on line 52

line 52 is while($query_data = mysql_fetch_row($result)) {

Code: Select all

<?php

$dbname = "database"; 
$tblname = "items"; 

$linkid = mysql_connect("localhost", "username", "password") or die(mysql_error());  

$db = mysql_select_db($dbname, $linkid) or die(mysql_error());  


$query = mysql_query("SELECT * FROM items WHERE itemId='$itemId'") or die(mysql_error()); 
$result=mysql_query($query);
$num=mysql_num_rows($result);
echo "$num";
echo "$result";
return $result;


echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' width='100%'>";  

echo "<tr>";
echo "<td width='5%'><strong><center>cat id</center></strong></td>";
echo "<td width='6%'><strong><center>item id</center></strong></td>";
echo "<td width='10%'><strong><center>product item</center></strong></td>"; 
echo "<td width='10%'><strong><center>item name</center></strong></td>"; 
echo "<td width='20%'><strong><center>item image</center></strong></td>";
echo "<td width='30%'><strong><center>item desc</center></strong></td>";
echo "<td width='14%'><strong><center>item price</center></strong></td>";
echo "</tr>";

while($query_data = mysql_fetch_row($result)) {

echo "<tr>";
echo "<td>$query_data[0]</td>";
echo "<td>$query_data[1]</td>";
echo "<td>$query_data[2]</td>"; 
echo "<td>$query_data[3]</td>";
echo "<td>$query_data[4]</td>";
echo "<td>$query_data[5]</td>";
echo "<td>$query_data[6]</td>";

echo "</tr>";

}     
echo "</table>";  


?>

?

Posted: Tue May 18, 2004 9:31 pm
by mikewooten
??