Klauwaart Posted October 18, 2007 Share Posted October 18, 2007 Hello everyone (since this is my first post here). Forgive my ignorance, but I have just began an attempt to learn PHP/MySQL and I am, at this time, what I would call totally incompetent. I wanted to make a simple script where someone enters their email in a form, and the record containing that email is then deleted from the MySQL database. Everything seems to work OK, I get no errors, but when I check my database, the data in question are still there. Here is the code I tried: First a simple HTML form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <!-- Created with the CoffeeCup HTML Editor 2007 --> <!-- http://www.coffeecup.com/ --> <!-- Brewed on 18/10/2007 13:02:30 --> <head> <title>Vlaanderen-Flanders</title> </head> <body> <form action="remove.php" method=post> <table border="1" width="100%"> <tr> <td><div align="center">Enter your email please.<br><br><input type="text" name="Epost" value="" size=30 maxlength=60><br> <input type="submit"></div></td> </tr> </table> </form> </body> </html> Note: the field in the DB containing the email address is called 'Epost' Then the PHP data remove script: <HTML> <HEAD> <TITLE>New Document</TITLE> </HEAD> <BODY> <?php $con = mysql_connect("localhost","mrdee_mrdee","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mrdee_reloader", $con); mysql_query("DELETE FROM newsletter WHERE Epost='$Epost'"); mysql_close($con); ?> </BODY> </HTML> My DB connections seem to be OK, as I get no errors, but I don't know whether it actually connects to the DB. The table name in the DB is newsletter. Obviously, I have uploaded these files to my server. Has anyone got any idea where I am going wrong please? Any help will be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/73797-solved-some-help-with-code/ Share on other sites More sharing options...
MadTechie Posted October 18, 2007 Share Posted October 18, 2007 try this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <!-- Created with the CoffeeCup HTML Editor 2007 --> <!-- http://www.coffeecup.com/ --> <!-- Brewed on 18/10/2007 13:02:30 --> <head> <title>Vlaanderen-Flanders</title> </head> <body> <form action="remove.php" method="post"> <table border="1" width="100%"> <tr> <td><div align="center">Enter your email please. <input type="text" name="Epost" value="" size=30 maxlength=60> <input type="submit"></div></td> </tr> </table> </form> </body> </html> thats changing <form action="remove.php" method=post> to <form action="remove.php" method="post"> PHPs (see comments) <HTML> <HEAD> <TITLE>New Document</TITLE> </HEAD> <BODY> <?php $con = mysql_connect("localhost","mrdee_mrdee","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } $Epost = $_POST['Epost']; //ADD mysql_select_db("mrdee_reloader", $con); mysql_query("DELETE FROM newsletter WHERE Epost='$Epost'") or die(mysql_error()); //append mysql_close($con); ?> </BODY> </HTML> setting the value of $Epost (from the post) and adding error handling.. your probably want to add some filtering for the Epost to stop SQL injection Ahh and welcome to the board Quote Link to comment https://forums.phpfreaks.com/topic/73797-solved-some-help-with-code/#findComment-372298 Share on other sites More sharing options...
Klauwaart Posted October 18, 2007 Author Share Posted October 18, 2007 Thank you ever so much, MadTechie. That did the job. Sorry to say this, but expect more idiotic posts from me in the future. As i said, I am just beginning to learn PHP and I am, at the moment, completely incompetent. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/73797-solved-some-help-with-code/#findComment-372339 Share on other sites More sharing options...
MadTechie Posted October 18, 2007 Share Posted October 18, 2007 No worries, we all start somewhere, but can you click the topic solved button (bottem left) Quote Link to comment https://forums.phpfreaks.com/topic/73797-solved-some-help-with-code/#findComment-372346 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.