Reputation: 93
What is the best way to insert a PHP 5 form into a MySQL database?
<form action="script.php" method="post">
<fieldset>
<input id="name" type="text" placeholder="name" />
<input type="submit" value="Opslaan" />
</fieldset>
</form>
Do I still have you use all of these?
$name= $_POST['name'];
$name = stripslashes($name);
$name = mysql_real_escape_string($name);
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO names VALUES ('','$name')";
mysql_query($query);
mysql_close();
Because when I do this, the script only enters the ID, the name field remains empty..
EDIT: How to use PDO or mysqli in PHP 5 (by the latest standards)?
Upvotes: 0
Views: 544
Reputation: 640
You need your name input to have the name attribute="name" ie.
<input type="text" id="name" name="name" placeholder="Enter your name" />
To fully address your answer.
Upvotes: 2
Reputation: 82
The placeholder attribut allows in html 5 to put a default value in an element of a form. This default value is remove when the element has focus. But in your case you have forget the attribut name. Try this:
<form action="script.php" method="post">
<fieldset>
<input id="name" name="name" type="text" placeholder="Enter your name" />
<input type="submit" value="Opslaan" />
</fieldset>
</form>
Upvotes: 0