I have created the following form and I want the data entered to be saved in the database. But when I send the form, it goes blank and does nothing.
I created the database, the user and the table. All the data is correct:
index.php
<!DOCTYPE html>
<html>
<head>
<title>Formulario De Contacto</title>
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<div class="form">
<form action="guardar.php" method="POST">
<p>Nombre</p>
<label for="nombre">Su nombre</label>
<br>
<input type="text" name="user" required>
<p>Correo</p>
<label for="correo">Direccion De Correo</label>
<br>
<input type="password" name="pass" required>
<br>
<br>
<input type="submit" value="Enviar">
</form>
</div>
</body>
</html>
save.php
<?php
//conectamos Con el servidor
$conectar=@mysql_connect('localhost','Usuario','Contraseña');
//verificamos la conexion
if(!$conectar){
echo"No Se Pudo Conectar Con El Servidor";
}else{
$base=mysql_select_db('NombreBaseDeDatos');
if(!$base){
echo"No Se Encontro La Base De Datos";
}
}
//recuperar las variables
$user=$_POST['user'];
$pass=$_POST['pass'];
//hacemos la sentencia de sql
$sql="INSERT INTO datos VALUES('$user',
'$pass')";
//ejecutamos la sentencia de sql
$ejecutar=mysql_query($sql);
//verificamos la ejecucion
if(!$ejecutar){
echo"Hubo Algun Error";
}else{
echo"Datos Guardados Correctamente<br><a href='index.html'>Volver</a>";
}
?>
- Where I put "User" I have placed the created user, "Password" is the password of that user and "NombreDeBaseDatos" is the database itself.
- The user is added to the database with all the privileges.