Jump to content

Displaying user information and deleting a row in table


simonjk

Recommended Posts

Hi,

 

I now want to show visitors there account information and also want to show them when email weather forecasts will be delivered to them. I have done this without a problem.

 

However, I am having difficulty when users want to delete their email request. I want to show them a 'delete' button next to their information, and then to delete the particular row in the table which includes this information.

 

I have written some code (below) but it does not work. can you help please?

 

Thanks,

Simon

 

<code>

 

<?php

$con = mysql_connect SECURITY DETAILS DELETED;

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("SECURITY DETAILS DELETED", $con);

echo "<table width=800 Border=1>";

$userinfo = mysql_query("SELECT * FROM `awisemails` WHERE `userEmail`='$email'");

while($user = mysql_fetch_array($userinfo))

{

echo "<td><br><FONT FACE=Arial,Helvetica SIZE=2 COLOR=BLACK>Forecast for <b>".$user['userfcstarea']."</b> is delivered at <b>" .$user['usersendtime']."</b></td><td><FONT FACE=Arial,Helvetica SIZE=2 COLOR=BLACK>";

echo "<form action=$_SERVER[php_SELF] method=post>

<form action=$_SERVER[php_SELF] method=post>

<input id=submit type=submit value=Delete /><br />

</p>

</form></td></tr> ";

 

// Connect to the MySQL

$con = mysql_connect("SECURITY DETAILS DELETED");

 

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

$useremail = mysql_real_escape_string($_POST[$email]);

$name = mysql_real_escape_string($_POST[$username]);

$usertime = mysql_real_escape_string($_POST[$user['usersendtime']);

 

mysql_query("DELETE FROM awisemails WHERE userEmail='".$useremail."' AND usersendtime='".$usertime."' AND username='".$name."'");

mysql_close($con);

}

echo "</table>";

end:

?>

</CODE>

Link to comment
Share on other sites

This is the third time I've seen you've post code using <code>. That is NOT how this forum works. Post using our code tags, you've been shown how, and now you're just being rude about it. No one wants to read your unformatted un-highlighted code!

 

In addition to that you've also been told "it doesn't work" is not a good post. What doesn't work? What does it do? What doesn't it do? etc.

Link to comment
Share on other sites

Thanks for your reply.

 

My statement 'doesn't work' refers to the fact that when I press the delete button, the row does not delete, i.e.e nothing happens.

 

As for the code tags, you might note that there is not a clear button to enclose code. Unless you know what '#' means, you can't press the button to enclose the code!

 

Perhaps replacing '#' with the word 'code' might just help?  ;)

 

Thanks again though,

Simon

 

 

 

 

 

<?php
$con = mysql_connect SECURITY DETAILS DELETED;
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("SECURITY DETAILS DELETED", $con);
echo "<table width=800 Border=1>";
$userinfo = mysql_query("SELECT * FROM `awisemails` WHERE `userEmail`='$email'");
while($user = mysql_fetch_array($userinfo))
{
echo "<td><br><FONT FACE=Arial,Helvetica SIZE=2 COLOR=BLACK>Forecast for <b>".$user['userfcstarea']."</b> is delivered at <b>" .$user['usersendtime']."</b></td><td><FONT FACE=Arial,Helvetica SIZE=2 COLOR=BLACK>";
echo "<form action=$_SERVER[php_SELF] method=post> 
<form action=$_SERVER[php_SELF] method=post> 
<input id=submit type=submit value=Delete /><br /> 
</p> 
</form></td></tr> ";

// Connect to the MySQL 
$con = mysql_connect("SECURITY DETAILS DELETED");

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

$useremail = mysql_real_escape_string($_POST[$email]);
$name = mysql_real_escape_string($_POST[$username]);
$usertime = mysql_real_escape_string($_POST[$user['usersendtime']);

mysql_query("DELETE FROM awisemails WHERE userEmail='".$useremail."' AND usersendtime='".$usertime."' AND username='".$name."'"); 
mysql_close($con); 
}
echo "</table>";
end:
?>

Link to comment
Share on other sites

There's also the PHP button, the buttons both have hover text, and it's explained in the rules. Not to mention YOU WERE TOLD THRICE.

 

Rather than deleting on all those conditions, you should use a primary unique key. Does your table have a PK?

See the link in my sig for debugging SQL statements, you're not capturing or displaying any errors or attempting to do any testing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.