Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/73797-solved-some-help-with-code/
Share on other sites

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 :)

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.