Jump to content

[SOLVED] Some help with code.


Klauwaart

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.