Please help! I am trying to insert data into a database table using php and sql, but it is inserting blanks into the fields that I am trying to populate. Here is the sql insert command that I am using
$sql = "INSERT INTO tropicustomers.tropimembers (member, emailaddr) VALUES (\"$name\", \"$email\");";
Why is it inserting blanks instead of the data that I passed to the variables $name and $email? I was successfully passing the variables before through a form. I am not sure what has changed.
If it helps here is my code:
<?php
$name = $HTTPPOSTVARS['name'];
$email = $HTTPPOSTVARS['email'];
$from = "Tropiconnect <example@example.com>";
$subject = 'Free Caribbean Travel Offer from Example.com';
$message = 'http://www.example.com/FreeOffer.doc';
$con = mysqlconnect("tropicustomers.db","tropicustomers","mypassword");
if ($con) { mysqlselectdb("tropicustomers", $con); $sql = "INSERT INTO tropicustomers.tropimembers (member, emailaddr) VALUES (\"$name\", \"$email\");"; mysqlquery("$sql");
}else{ die('Could not connect: ' . mysql_error()); }
mysql_close($con);
if (!pregmatch("/\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*/", $email)){ echo "<h4>Invalid email address:</h4>"."$email"; echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif ($name == "") { echo "<h4>Please fill in your full name before clicking the send button</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>"; }
elseif (mail($email,$subject,$message)) { echo "<h4>Thank you! Your request has been sent to example. You should receive an email shortly.</h4>"; echo "<a href='http://www.example.com'>Click here to go back to the example web site</a>"; } else { echo "<h4>Can't send email to $email</h4>"; } ?>