confirm delete
Moderator: General Moderators
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
confirm delete
hi
I have admin page where user can delete a person from the databse. Im using email address as primary key. what I'm trying to do is when user hits 'Delete' button on the form he/she asked to confirm delete "Are you sure" if they hits 'Yes' then record is deleted from the databse.
here is the code
delete.php
<form action="confirm.php" method="post">
Email: <input type="text" name="email" size="40" maxlength="40" ><br>
<input type="submit" name="delete" value="Delete">
</form>
confirm.php
if ($delete == "Delete")
{
<h3>Are You Sure</h3>
<form action="edit.php" method="post" >
<input type="submit" name="delete" value="Yes">
<input type=hidden name=email value="$email">
</form>
}
edit.php
if ($delete == "Yes")
{
$query = "delete from Names "
."where Email='$email'";
print "<h2>$email has been deleted from the databese </h2>\n";
}
i get "$email has been deleted from the databese" but when look in the databse record is still there.
I think this is where the problem is but con't work it out. Please help
<input type="submit" name="delete" value="Yes">
<input type=hidden name=email value="$email">
Thanx
I have admin page where user can delete a person from the databse. Im using email address as primary key. what I'm trying to do is when user hits 'Delete' button on the form he/she asked to confirm delete "Are you sure" if they hits 'Yes' then record is deleted from the databse.
here is the code
delete.php
<form action="confirm.php" method="post">
Email: <input type="text" name="email" size="40" maxlength="40" ><br>
<input type="submit" name="delete" value="Delete">
</form>
confirm.php
if ($delete == "Delete")
{
<h3>Are You Sure</h3>
<form action="edit.php" method="post" >
<input type="submit" name="delete" value="Yes">
<input type=hidden name=email value="$email">
</form>
}
edit.php
if ($delete == "Yes")
{
$query = "delete from Names "
."where Email='$email'";
print "<h2>$email has been deleted from the databese </h2>\n";
}
i get "$email has been deleted from the databese" but when look in the databse record is still there.
I think this is where the problem is but con't work it out. Please help
<input type="submit" name="delete" value="Yes">
<input type=hidden name=email value="$email">
Thanx
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
It's because you have to actually run the query through your database. Assuming you use MySQL you would want to do something like:
Have a look at the manual information on mysql_connect(), mysql_select_db() and mysql_query().
Mac
Code: Select all
if ($delete == "Yes") {
// connect to database server
@mysql_connect($host, $user, $pass) or die(mysql_error());
// select database
@mysql_select_db($db) or die(mysql_error());
$sql = "DELETE FROM Names WHERE Email='$email'";
// query the database
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
echo '<h2>'.$email.' has been deleted from the database</h2>';
}Mac
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
Yes im using MySQL.
I should have pointed out that in edit.php im including header.php which connects to my database.
<?php
function dbconnect ($dbname="",$user="",$password="",$server="localhost")
{
if (!($mylink = mysql_connect($server,$user,$password)))
{
print "<h3>could not connect to database</h3>\n";
exit;
}
mysql_select_db($dbname);
}
dbconnect("");
?>
I should have pointed out that in edit.php im including header.php which connects to my database.
<?php
function dbconnect ($dbname="",$user="",$password="",$server="localhost")
{
if (!($mylink = mysql_connect($server,$user,$password)))
{
print "<h3>could not connect to database</h3>\n";
exit;
}
mysql_select_db($dbname);
}
dbconnect("");
?>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
I think JavaScript is perfectly suited for this. It's as simple as the javascript alert() function, which places a box in front of the user and tells them to confirm what they are about to do. Using PHP, you have to make a trip back to the server, process the info, then another trip back to the user, where she decides that the delete is OK, then the final trip back to the server to delete (or not) the info.I have admin page where user can delete a person from the databse. Im using email address as primary key. what I'm trying to do is when user hits 'Delete' button on the form he/ she asked to confirm delete "Are you sure" if they hits 'Yes' then record is deleted from the databse.
Check into it. Also, javascript isn't really difficult if you're allready programming in PHP as they are both using a C type syntax. Logic is logic. The DCOM stuff will be a little weird at first.
Cheers,
BDKR
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Does it give you any errors? What information do you get if you do:
after the query.
http://www.php.net/manual/en/function.m ... d-rows.php
Mac
Code: Select all
echo 'Affected rows: '.mysql_affected_rows();http://www.php.net/manual/en/function.m ... d-rows.php
Mac
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
According to the documentation on mysql_affected_rows():
if you use mysql_error() in the or die() statement you may get a reason for the query failing. If there is no error then make sure the query looks alright by doing:
just in case $email isn't getting passed properly.
Mac
so your query is failing - do you have an or die() statement at the end of the mysql_query() call? E.g.If the last query failed, this function will return -1
Code: Select all
@mysql_query($query) or die(mysql_error());Code: Select all
echo $query;Mac
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
new to php
- Forum Newbie
- Posts: 11
- Joined: Fri Nov 29, 2002 6:16 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You need to change this:
to this
Mac
Code: Select all
mysql_query($query) or die(mysql_error());
$query= mysql_query ("delete from Names"
."where Email='$email'");Code: Select all
$query = "DELETE FROM Names WHERE Email='$email'";
@mysql_query($query) or die(mysql_error());- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Does it give you the same error? Have you done:
to check the SQL query?
Mac
Code: Select all
echo $query;Mac