0

Here is the html form:

<form action="process.php" method="post">  
 <label> Enter Email:</label><input type="text" name="email"/>
</form>  

Here is the php:

<? 
 $email=$_POST['email']; 

 mysql_connect("localhost", "root", "password" ) or die(mysql_error());
 mysql_select_db("data") or die(mysql_error());
 mysql_query("INSERT INTO `data` VALUES ('$email')");
?>

What am I doing wrong?

  • 2
    besides using root to connect to your database, and using the deprecated `mysql_*` syntax that is terribly insecure? hmm ... what does your error say? – PlantTheIdea Sep 04 '14 at 20:14
  • `mysql_query` is an obsolete interface and should not be used in new applications and will be removed in future versions of PHP. A modern replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/). If you're new to PHP, a guide like [PHP The Right Way](http://www.phptherightway.com/) can help explain best practices. If you're just getting started, a [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) like [Laravel](http://laravel.com/) gives you more support than coding from scratch. – tadman Sep 04 '14 at 20:14
  • I'm not getting any errors. It''s just not processing the form at all. – cookron009 Sep 04 '14 at 20:18
  • You're not getting errors because you're not checking for them. Add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Sep 04 '14 at 20:21

1 Answers1

5

There are a lot of things to comment on, but the specific cause of your error is case sensitivity. Your field name is Email but you are looking for email in the $_POST superglobal.

So

$email=$_POST['email']; 

should be

$email=$_POST['Email']; 

As for the other stuff, you are wide open to SQL injections and using an obsolete API. I strongly recommend fixing this before pushing your code to production.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496