Reputation: 244
I have written syntax to delete a row from a MYSQL database. This works fine however i am now moving this to another page (copied and pasted) and for some reason it will not work on the new page
I'm not sure how to add error reporting so just get server error
Here is the code
<?php
$prodID = $_GET["q"];
if ($prodID <= "0") {
echo("
<h3>This Product Does Not Exist</h2>
<table border='0'>
<tr>
<td>
<a href=catalogue.html'><button class='btn btn-info'><font color='white'> Add A New product </font></a></button>
</td>
<td>
<a href='manageproducts.php'><button class='btn btn-info'><font color='white'>Back to Products</font> </a>
</td>
</tr>
</table>
");
} else {
$con = mysql_connect("localhost", "cl49-xxx", "xxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
@mysql_select_db("cl49-XXX", $con) or die("Unable to select database");
$result = mysql_query("DELETE FROM products WHERE prodID=$prodID") or die(mysql_error());
?>
Upvotes: 0
Views: 380
Reputation: 15
<?php
$prodID = $_GET["q"];
if ($prodID <= "0") {
echo("
<h3>This Product Does Not Exist</h2>
<table border='0'>
<tr>
<td>
<a href=catalogue.html'><button class='btn btn-info'><font color='white'> Add A New product </font></a></button>
</td>
<td>
<a href='manageproducts.php'><button class='btn btn-info'><font color='white'>Back to Products</font> </a>
</td>
</tr>
</table>
");
} else {
$con = mysql_connect("localhost", "cl49-xxx", "xxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
@mysql_select_db("cl49-XXX", $con) or die("Unable to select database");
$result = mysql_query("DELETE FROM products WHERE prodID=$prodID") or die(mysql_error());
}
?>
Upvotes: 0
Reputation: 4173
You're missing a closing }
after your $result
and before your ?>
Upvotes: 1
Reputation: 37233
you are checking math operators with strings.
use this instead. thats why you got 0 value in your delete query which is wrong
if ($prodID <= 0)
edit:
use this.
mysql_query("DELETE FROM products WHERE prodID=$prodID") ;
instead of
$result = mysql_query("DELETE FROM products WHERE prodID=$prodID")
EDIT:
try remove @
before mysql_select_db
Upvotes: 0