[Solved] Inserting into a database an email address

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

[Solved] Inserting into a database an email address

Post by Dale »

Ok so i'm using a basic bog standard form:

Code: Select all

<form action="mail.php" method="POST">
Email: <input type="text" name="email" size="60"><br>
<input type="submit" value="Add Email">
</form>
Simple yeah?

Now this is what i'm using to insert the code to the database on mail.php:

Code: Select all

<?php
$conn = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE", $conn) or die(mysql_error());

$sql1 = "INSERT INTO mailing VALUES('',$_POST[email])";
$result1 = mysql_query($sql1, $conn) or die(mysql_error());
?>
Now whenever I I enter something in the email address form and click the "Add Email" button I always get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com)' at line 1
Any reason why??
Last edited by Dale on Mon Jun 26, 2006 2:57 pm, edited 1 time in total.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

That shud be

Code: Select all

$sql1 = "INSERT INTO mailing VALUES('','".$_POST['email']."')";
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Ahh thank you :)
Post Reply