NZ7C
asked on
PHP delete contact form problem
This script properly selects and displays a user name to be deleted. However, it does not delete the user from the database on submission. I don't see the problem. Can someone help me work through what I'm missing? Thank you in advance.
<?php
require_once('functions.ph p');
require_once('includes/con n.php');
session_start();
if (!$_POST['uid']) {
$msg_no_input = "NO SEARCH TERM WAS HIGH LIGHTED!";
header("Location:http://www.zzzzzzzzzzzzzzz.org/user_search.php?msg_no_input=" . urlencode($msg_no_input));
exit;
} else {
$uid = $_POST['uid'];
if (isset($_POST['lastname']) )
{
$email = strtolower(trim($_POST['em ail']));
$firstname = ucfirst (trim($_POST['firstname']) );
$lastname = ucfirst (trim($_POST['lastname'])) ;
//build and issue query
$sql = "DELETE t_user FROM t_user
WHERE t_user.lastname = '$lastname'";
$result = @mysql_query($sql,$connect ion) or die(mysql_error());
$msg_success = "$_POST[firstname] $_POST[lastname] has been deleted";
header("Location:http:/www.zzzzzzzzzzzzzz.org/user_add_result.php?msg_success=" . urlencode($msg_success));
exit;
} else {
//build and issue query
$sql ="SELECT uid, firstname, lastname FROM t_user WHERE uid ='$_POST[uid]'";
$result =@mysql_query($sql,$connec tion)or die(mysql_error());
//get results for display
while ($row =mysql_fetch_array($result ))
{
$firstname =$row['firstname'];
$lastname =$row['lastname'];
}//end while
}//end else
}//end if
?>
<form name="user_form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"/>
<input type="hidden" name="uid" value="<? echo "$_POST[uid]"; ?>">
<input type="text" name="name" value="<? echo "$firstname $lastname"; ?>" size="42" maxlength="42" class="input_area" />
<input type="submit" name="submit"value="Delete " class="button"
onclick="this.form.action= '<?php $_SERVER['PHP_SELF']; ?>'"/>
<input type="submit" class="button" value="Cancel"
onclick="this.form.action= 'user_sear ch.php'" />
</form>
<?php
require_once('functions.ph
require_once('includes/con
session_start();
if (!$_POST['uid']) {
$msg_no_input = "NO SEARCH TERM WAS HIGH LIGHTED!";
header("Location:http://www.zzzzzzzzzzzzzzz.org/user_search.php?msg_no_input=" . urlencode($msg_no_input));
exit;
} else {
$uid = $_POST['uid'];
if (isset($_POST['lastname'])
{
$email = strtolower(trim($_POST['em
$firstname = ucfirst (trim($_POST['firstname'])
$lastname = ucfirst (trim($_POST['lastname']))
//build and issue query
$sql = "DELETE t_user FROM t_user
WHERE t_user.lastname = '$lastname'";
$result = @mysql_query($sql,$connect
$msg_success = "$_POST[firstname] $_POST[lastname] has been deleted";
header("Location:http:/www.zzzzzzzzzzzzzz.org/user_add_result.php?msg_success=" . urlencode($msg_success));
exit;
} else {
//build and issue query
$sql ="SELECT uid, firstname, lastname FROM t_user WHERE uid ='$_POST[uid]'";
$result =@mysql_query($sql,$connec
//get results for display
while ($row =mysql_fetch_array($result
{
$firstname =$row['firstname'];
$lastname =$row['lastname'];
}//end while
}//end else
}//end if
?>
<form name="user_form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"/>
<input type="hidden" name="uid" value="<? echo "$_POST[uid]"; ?>">
<input type="text" name="name" value="<? echo "$firstname $lastname"; ?>" size="42" maxlength="42" class="input_area" />
<input type="submit" name="submit"value="Delete
onclick="this.form.action=
<input type="submit" class="button" value="Cancel"
onclick="this.form.action=
</form>
I agree with steelseth12 about what the problem is, but wonder if your query might delete more than one user by mistake sometimes (if they have the same surname)?
ASKER
steelseth12 - Yes, you are right on that - don't know why I did not see it. However, I still cannot get the entry to delete after making the change.
TerryAtOpus - You are right as well - I am just setting this up for the moment. Deletions should really be done by the uid.
Thanks to both of you for offering help. Still scratching my head on it.
TerryAtOpus - You are right as well - I am just setting this up for the moment. Deletions should really be done by the uid.
Thanks to both of you for offering help. Still scratching my head on it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
steelseth12:
You're right! Changed the textfield name and now it deletes. Case change does not seem to be an issue though. Thanks so much for the help.
You're right! Changed the textfield name and now it deletes. Case change does not seem to be an issue though. Thanks so much for the help.
WHERE t_user.lastname = '$lastname'";
should be
$sql = "DELETE FROM t_user
WHERE t_user.lastname = '$lastname'";