0

I've been working at this for hours, and can't seem to get these few lines of code to work. This is the first time I've worked with MySQL, so bear with me.

<?php

$con = mysql_connect("localhost","usernamewitheld","passwordwithheld");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("splashpage");
mysql_query("INSERT INTO 'email' ('emailaddress') VALUES ('$_POST[email]');", $con);
mysql_close($con);

?>

The code executes without any errors from apache, but the database remains unaffected. Any ideas?

EDIT: Table structure is as follows:

Field   Type    Null    Key Default Extra
emailaddress    text    NO  MUL NULL     
timesubmitted   timestamp   NO      CURRENT_TIMESTAMP    
2
  • could you please post table structure as well ? Commented May 4, 2013 at 6:06
  • 2
    Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use pdo or mysqli. Commented May 4, 2013 at 6:08

4 Answers 4

2

Remove semi colon, use bacticks instead of single quotes in query.

mysql_query("INSERT INTO `email` (`emailaddress`) VALUES ('$_POST[email]')", $con)
or     
die(mysql_error());

Note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Sign up to request clarification or add additional context in comments.

Comments

0

use backtick ` here around column name not '

mysql_query("INSERT INTO 'email' ('emailaddress') VALUES ('$_POST[email]');", $con);

should be

mysql_query("INSERT INTO `email` (`emailaddress`) VALUES ('$_POST[email]')", $con);

Comments

0

Use this.

<?php
mysql_query("INSERT INTO email (emailaddress) VALUES ('".$_POST[email]."')", $con);
mysql_close($con);
?>

Comments

0

try

<?php

$con = mysql_connect("localhost","usernamewitheld","passwordwithheld");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("splashpage",$con);
mysql_query("INSERT INTO 'email' ('emailaddress') VALUES ('$_POST[email]');", $con);
 echo mysql_errno($con) . ": " . mysql_error($con) . "\n";
mysql_close($con);

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.