Forum Moderators: coopster

Message Too Old, No Replies

data not going into DB

         

ganderla

3:22 am on Jun 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am so new at this db stuff. I have a form on my site that just asks for email. here is my process code. The email address is not going into the DB. Can anyone just see wuickly if there is anything woring with it?

<?

$email=$_POST['email'];

include("include.php");

$link=mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase") or die( "Unable to select database");

$query="INSERT INTO mydb (

email,
)

VALUES(
'',
'$email',
)";

$result = mysql_query($query) or $errors[] = mysql_error();

header ("Location: http://www.example.com/thanks.shtml");

?>

ironik

5:29 am on Jun 28, 2005 (gmt 0)

10+ Year Member



I've changed your code so the SQL statement should work, I've also added some email validation in there as well.


<?php

function isValidEmail($email)
{
return preg_match('/^(([A-Za-z0-9]+_+)¦([A-Za-z0-9]+\-+)¦([A-Za-z0-9]+\.+)¦([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)¦(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/i', $email);
}

$email=$_POST['email'];

include("include.php");

if (isValidEmail($email))
{
$link=mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase") or die( "Unable to select database");

$query="INSERT INTO mydb (email) VALUES ('$email')";

$result = mysql_query($query) or $errors[] = mysql_error();

header ("Location: http://www.example.com/thanks.shtml");
} else {
echo 'Sorry, the email address given is not valid';
}

ganderla

5:34 am on Jun 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you so much.
30 seconds before I checked the post again, I closed everything out of frustration.

I appreciate it.