Andre Debuisne Andre Debuisne - 2 years ago 83
PHP Question

PHP form in HTML, won't connect

So I am very new to PHP,and databases in general, so please be indulgent! :)

I created a simple form in an HTML file:

<h1> Créez votre compte ici</h1>
<form action="form.php" method="post">
<p id="textdone"> </p>
<input type= "text" name="Surname" autocomplete="on" placeholder="Votre nom" required/> <br> <br>
<input type= "text" name="Name" autocomplete="on" placeholder ="Votre prenom" required/> <br> <br>
<input type= "email" name="Email" autocomplete="on" placeholder ="Adresse mail" required/> <br><br>
<input type= "text" name="Pseudo" autocomplete="off" placeholder ="Votre pseudo" maxlength="20" required/> <br>
<p>Ajoutez une photo de profil: <input type= "file" /> <br><br></p>
<p> Entrez un mot de passe: <input type="Password" name="Passwird" autocomplete="off" maxlength="20" required placeholder="Mot de passe"/> <br><br>
Validez votre mot de passe: <input type="password1" autocomplete="off" maxlength="20" required placeholder="Mot de passe"/> <br><br>
<input type="submit" value="Soumettre"/>

And so my action file, the form.php file, saved in the same folder (I made sure) is as follows:

define('DB_NAME', 'Matchy');
define('DB_USER', 'root@localhost');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link){
die('Could not connect: ' .mysql_error());
$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected){
die('Can\'t use' . DB_NAME. ':'. mysql_error());
echo 'Successful connection';

$surname = $_POST['Surname'];
$name = $_POST['Name'];
$email = $_POST['Email'];
$pseudo = $_POST['Pseudo'];
$password = $_POST['Password'];

$sql = "INPUT INTO users (Name) VALUES ('$name')";
$sql1 = "INPUT INTO users (Surname) VALUES ('$surname')";
$sql2 = "INPUT INTO users (Pseudo) VALUES ('$pseudo')";
$sql3 = "INPUT INTO users (Email) VALUES ('$email')";
$sql4 = "INPUT INTO users (Password) VALUES ('$password')";

if (!mysql_query($sql)) {
die ('Error: ' .mysql_error());
if (!mysql_query($sql1)) {
die ('Error: ' .mysql_error());
if (!mysql_query($sql2)) {
die ('Error: ' .mysql_error());
if (!mysql_query($sql3)) {
die ('Error: ' .mysql_error());
if (!mysql_query($sql4)) {
die ('Error: ' .mysql_error());


But every time I fill out my form and hit submit, I get this message:
Cannot Post /form.php.

I get this code from this following video (, which was very useful. But I really can't connect. I created my table on my database, with all the right columns.
I use phpMyAdmin.

Thank you so much to anyone who can help!! :)

Answer Source

Let's outline the errors here.

INPUT INTO isn't a valid MySQL expression, the syntax is INSERT INTO.

Then you have name="Passwird" and $_POST['Password'] which do not match and error reporting would have told you about it.

Then as outlined in comments by another member:

<input type="password1" autocomplete="off" maxlength="20" required placeholder="Mot de passe"/> this one is providing no love too. No inputtype password1 – Hendra Nucleo

which should have been password and not password1.

Best to use the right and official references and switch to PDO with prepared statements or mysqli_* with prepared statements, as the mysql_* functions are deprecated. The official manuals are the best references.

  • They won't steer you wrong ;-)

That tutorial probably didn't mention anything about SQL injection, so that's a good read in its own right.

Nor did it mention anything about passwords.

I noticed that you may be storing passwords in plain text. This is not recommended.

Use one of the following:

Other links:

Important sidenote about column length:

If and when you do decide to use password_hash() or the compatibility pack (if PHP < 5.5), it is important to note that if your present password column's length is anything lower than 60, it will need to be changed to that (or higher). The manual suggests a length of 255.

You will need to ALTER your column's length and start over with a new hash in order for it to take effect. Otherwise, MySQL will fail silently.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download