PHP $POST to database

Hi there.

I need help with my PHP code.

After entering an email address on a previous $POST form this code should add it to the database, it does but the email address does not appear, instead its just a blank value, the column is blank. Here is my code:

the column’s settings are: 2 emailad varchar(40) utf8_general_mysql500_ci

(2 because there is also a auto increment id)

[php]$email= “$POST”;
$con=mysqli_connect(“","","", "*”);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,“INSERT INTO emails (emailad)
VALUES (’$email’)”);
mysqli_close($con);
[/php]

Thank you.

$POST is a user created variable so unless you’ve set it somewhere to have a value, you will get exactly what you are now - a blank line.

I assume you are checking the $_POST variable, or better yet, $_POST[‘email’] or something along those lines.
As a side note, you should never EVER enter data into your database without cleaning it up first using the built in functions or create your own.
mysqli_real_escape_string()
or
addslashes (for entering data)
stripslashes (when retrieving data)

I’d use the first option and do it always - to the point where you don’t think about it anymore, you just do it on autopilot.

Better be safe than sorry.
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service