0

hi all! i have here a code to delete a record

<?php

    define ('DB_NAME', 'vincegac_vince');
    define ('DB_USER', 'root');
    define ('DB_PASSWORD', '');
    define ('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
    $value1 = $_POST["emp_number"];
    $value2 = $_POST["fname"];
    $value3 = $_POST["mname"];
    $value4 = $_POST["lname"];
    $value5 = $_POST["homeadd"];
    $value6 = $_POST["emailadd"];
    $value7 = $_POST["ofcnum"];
    $value8 = $_POST["mobilenum"];
    $value9 = $_POST["homenum"];
    $value10 = $_POST["position"];
    $value11 = $_POST["practice"];
    $value12 = $_POST["projname"];
    $value13 = $_POST["projmgr"];
    $value14 = $_POST["teamlead"];

$sql = "DELETE FROM employee WHERE emp_number = '$value1' AND fname = '$value2' AND mname = '$value3' AND lname = '$value4' AND homeadd = '$value5' AND emailadd = '$value6' AND ofcnum = '$value7' AND mobilenum = '$value8' 
        AND homenum = '$value9' AND position = '$value10' AND practice = '$value11' AND projname = '$valu12' AND projmgr = '$value13' AND teamlead = '$value14'";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
    }
//echo '<p>One member added! <a href="demo-form.php">add another member</a></p>';
echo '<p>Back to <a href="main.php">Home page</a></p>';
mysql_close();

?>

but when i click my delete button, it says, undefined index. im using post method.

Thanks!

4
Contributors
4
Replies
23
Views
4 Years
Discussion Span
Last Post by mallows.yum
0

Will u share click button HTML code too? Are you using JS also? If means, share that tooo.. :)

Edited by mrvijayakumar

0

The query have projname = '$valu12'
it should be projname = '$value12'

You can use a unique id to delete a row

0

Yep, as code_rum has suggested the problem is likely to be caused by a mispelling of a variable.

In the future, a tip to debugging such errors is to either echo out the variables when you get an error (and see if it is null, or has the expected value), or to use the isset() function.

0

hi guys! yes i saw that one. but thats not the cause. my button was not inside the form. :)

THANKS! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.