I'm trying to make a very simple php form that inserts values in a database. First I have created a form :
<html>
<head>
<title>insertion de données en PHP :: partie 1</title>
</head>
<body>
<form name="insertion" action="insertion2.php" method="POST">
<table border="0" align="center" cellspacing="2" cellpadding="2">
<tr align="center">
<td>nom</td>
<td><input type="text" name="nom"></td>
</tr>
<tr align="center">
<td>prenom</td>
<td><input type="text" name="prenom"></td>
</tr>
<tr align="center">
<td>adresse</td>
<td><input type="text" name="adresse"></td>
</tr>
<tr align="center">
<td>code postal</td>
<td><input type="text" name="codePostal"></td>
</tr>
<tr align="center">
<td>numéro de téléphone</td>
<td><input type="text" name="telephone"></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="insérer"></td>
</tr>
</table>
</form>
</body>
</html>
Then I created a second php file with the mysqli database connection and a SQL query to insert the values in the database :
<?php
$mysqli = new mysqli("localhost", "root", "", "info");
if ($mysqli->connect_errno) {
echo "Echec lors de la connexion à MySQL : (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$nom = $_POST["nom"] ;
$prenom = $_POST["prenom"] ;
$adresse = $_POST["adresse"] ;
$cp = $_POST["codePostal"] ;
$tel = $_POST["telephone"] ;
$sql = "INSERT INTO personnes (nom, prenom, adresse, cp, telephone)
VALUES ( '$nom', '$prenom', '$adresse', '$cp', '$tel') " ;
$requete = mysql_query($sql, $base) or die( mysql_error() ) ;
if($requete)
{
echo("L'insertion a été correctement effectuée") ;
}
else
{
echo("L'insertion à échouée") ;
}
?>
But now I have errors :
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\wamp\www\Inform\insertion2.php on line 20 Notice: Undefined variable: base in C:\wamp\www\Inform\insertion2.php on line 20
and I don't know what to do. Can you help me?