simonjk Posted September 19, 2012 Share Posted September 19, 2012 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> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
simonjk Posted September 19, 2012 Author Share Posted September 19, 2012 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: ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.