i always get blank result when i echo post content or insert it into my database$ here is my code
PHP
<?php
$host = "mysql.1freehosting.com";
$user = "u249494946_user";
$pass = "aqwaqwaqw";
$db = "u249494946_first";
mysql_connect($host,$user,$pass);
mysql_select_db($db);
/*if(isset($_post["ajout"])) {
echo("error submitting");
}
else {
*/
var_dump(isset($_post['submit']));
$nom = $_post["nom"];
$prenom = $_post["prenom"];
echo $_post[nom];
echo $nom;
$result1=mysql_query("INSERT INTO eleve (id,nom,prenom) VALUES (NULL,'$nom','$prenom')");var_dump($result1);
/*$result2=mysql_query("INSERT INTO eleve(id, nom, prenom) VALUES (null,'y','y')");
if(!$result1){
die('errreur result1 :' . mysql_error());
}
*/
var_dump($_POST);
?>
HTML
<html>
<head>
<title>disaster</title>
</head>
<body>
<div align="center">
<form id="form" method="post" action="ajout.php">
nom : <input type="text" id="nom" />
prenom : <input type="text" id="prenom" />
<input type="submit" value="ajouter" id="submit" />
</form>
</div>
</body>
</html>
this is the result that i get
bool(false)
bool(true)
array(3) {
["nom"]=>
string(7) "example"
["prenom"]=>
string(7) "example"
["submit"]=>
string(7) "ajouter"
}
$_POST
is a superglobal
and MUST be in uppercase.
Change all your $_post
to $_POST
Plus, as already stated by Alon
, you need to name your input element:
<input type="text" id="nom" name="nom" />
credit goes to Alon for this.
I also recommend that you switch to mysqli_*
functions with prepared statements or PDO as mysql_*
functions are deprecated and will be removed from future PHP releases.
Some of your input elements are not named:
Change to:
nom : <input type="text" id="nom" name="name" />
prenom : <input type="text" id="prenom" name="prenom" />
<input type="submit" value="ajouter" name="submit" id="submit" />
It should be echo $_POST["nom"];
instead of echo $_post[nom];
EDIT: you need to add name attributes to the form inputs like <input type="text" id="nom" name="nom" />