Problem in php + Mysqli

0

Good morning, I tell you a little about how things are going. I'm doing a page in php along with Mysqli for queries and insertions in database. We are working on localhost. My problem is the following. -Once I register a user, he does not take the fields of the form, and only registers the field of the PK, which seems strange to me, since they are made in the same way. I have tried different ways and can not find any solution: /.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
 	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>Registro de Usuario</title>
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/estilo.css">
</head>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<body>
	<header>
		<div class="container">
			<h1>Registrate en Guppy!</h1>
		</div>
	</header>
	<section id="fondo">
	<div class="container">
		<section class="main row">
			<article class="col-md-6">
				<br>
				<br>
				<br>
				<br>
				<br>
				Unete a la nueva red social que revolucionara el mundo! <br>
				Es totalmente gratis!
			</article>
			<aside class="col-xs-9 col-sm-6 col-md-4">
				<h1>REGISTRO</h1> <br>
				<form action="validarUsu.php" method="post">
					<table class="table">
						<tr>
							<td>Correo: </td>
							<td><input type="text" name="txtCorreo"></td>
						</tr>
						<tr>
							<td>Nombre: </td>
							<td><input type="text" name="txtNombre"></td>
						</tr>
						<tr>
							<td>Apellido: </td>
							<td><input type="text" name="txtApellido"></td>
						</tr>
						<tr>
							<td>Clave: </td>
							<td><input type="text" name="txtClave"></td>
						</tr>
						<tr>
							<td></td>
							<td><button class="btn btn-primary">REGISTRARME</button></td>
						</tr>
					</table>
				</form>
			</aside>
		</section>
	</div>
	<br>
	</section>
	<footer>
		<div class="container">
			<h3><a href="index.html">Guppy</a></h3>
		</div>
	</footer>
</body>
</html>

PHP:

<script>
	function exito(){
		alert("Usuario Registrado Exitosamente");
		window.location = "index.html";
	}

	function camposVacios(){
		alert("Campos Vacíos!");
		window.location = "registrar.html";
	}
</script>

<?php  
	
	$correo   = trim($_POST["txtCorreo"]);
	$nombre   = trim($_POST["txtNombre"]);
	$apellido = trim($_POST["txtApellido"]);
	$clave 	  = trim($_POST["txtClave"]);

// Create connection
$conn = mysqli_connect("localhost","root","", "guppy");
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

if ($correo == "" || $nombre = "" || $apellido = "" || $clave = "") {
	echo"<script>camposVacios()</script>";
}

else{

	$query = "INSERT INTO usuario (correo, nombre, apellido, clave) VALUES ('".$correo."', '".$nombre."','".$apellido."','".$clave."')";

	if (mysqli_query($conn, $query)) {
	    echo "<script>exito()</script>";
	    
	} else {
	    echo "Ocurrio un error inesperado: " . $sql . "<br>" . mysqli_error($conn);
	}
}

mysqli_close($conn);

?> 
    
asked by Ignacio Espinoza 01.12.2017 в 00:09
source

1 answer

0

In your INSERT INTO statement you only indicate the php variables that you are going to put into the database, but you do not indicate to which part of the database you will put it.

E.g.

$sql = "INSERT INTO Contacto (correo, nombre, apellido, clave) VALUES ('$correo', '$nombre', '$apellido', '$clave')";
    
answered by 01.12.2017 в 01:37