Shane
Shane

Reputation: 244

error deleting row from mysql database

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'>&nbsp;Add A     New product&nbsp;</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

Answers (4)

Vishnu Kant Maurya
Vishnu Kant Maurya

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'>&nbsp;Add A     New product&nbsp;</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

DannyTheDev
DannyTheDev

Reputation: 4173

You're missing a closing } after your $result and before your ?>

Upvotes: 1

Mihai
Mihai

Reputation: 26784

"DELETE FROM products WHERE prodID='".$prodID."'"

Upvotes: 0

echo_Me
echo_Me

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

Related Questions