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:
<?
$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 " \n";
echo "<a href=\"showprod4.php\">NO</a>\n";
}
?>