Php and msqli are not inserting data

-1

I have a login and registration program. The problem is that when registering the user the data is not being stored in my database

This is the php code of the Registry

<body background="Imagenes/pluma.jpg">
<form action="recibe_registro.php" method="post" >
<br>
 <center><table width="25%" border="0" id="form_pers">
  <tbody>
    <tr>
      <td>	
	<p>	
<label for="textfield1">Usuario:<br></label>
<input type="text" name="usuario" id="usuario"  >
	</p>
	<p>	
<label for="textfield1">Contraseña:<br></label>
<input type="password" name="contrasena" id="contraseña"  >
	</p>
		
		<p>	
<label for="textfield1">Nombre(s):<br></label>
<input type="text" name="nombre" id="nombre"  >
	</p>
		<p>	
<label for="textfield1">Apellido(s):<br></label>
<input type="text" name="ap" id="ap"  >
	</p>
	<p>	
<label for="textfield1">RFC:<br></label>
<input type="text" name="rfc" id="rfc"  >
	</p>
	<p>	
<label for="textfield1">Teléfono:<br></label>
<input type="text" name="tel" id="tel"  >
	</p>
		<p>	
<label for="textfield1">Dirección:<br></label>
<input type="text" name="dir" id="dir"  >
	</p>
	
	<p>	
<label for="textfield1">Ciudad:<br></label>
<input type="text" name="ciudad" id="ciudad"  >
	</p>
	<p>	
<label for="textfield1">País:<br></label>
<input type="text" name="pais" id="pais"  >
	</p>
  
		
		
</td>      
    </tr>
  </tbody>
</table></center>

<center><input type="submit" name="submit" id="submit_pers" value="Enviar"></center>
</form>
</body>
</html>

And this is the php that you insert into the database

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
</head>

<body>
<?php 
include("conecta_pasarela.php");
	
	$id_prov="";
	$us=$_POST['usuario'];
	$contrasena=$_POST['contrasena'];
	$nombre=$_POST['nombre'];
	$ap=$_POST['ap'];
	$rfc=$_POST['rfc'];
	$tel=$_POST['tel'];
	$dire=$_POST['dir'];
	$ciudad=$_POST['ciudad'];
	$pais=$_POST['pais'];    	
	
	$sql=mysqli_query($conexion,"INSERT INTO registro values('".$id_prov."','".$us."','".$contrasena."','".$nombre."',,'".$ap."','".$rfc."','".$tel."','".$dire."','".$ciudad."','".$pais."')");    			
		
        echo"<script type=\"text/javascript\">function redireccionar(){window.location=\"compras.php\";} window.onload = redireccionar;</script>";  	
	
?>

</body>
</html>
    
asked by Stephanie B Bautista 25.07.2018 в 01:44
source

3 answers

0

You could check this to see if it's ok ...

$insert = mysqli_query($con, "INSERT INTO TABLA(Columna1, Columna2, etc)
VALUES('$VAR1','$VAR2',etc)") or die('Error: ' . mysqli_error($con));

Luck

    
answered by 25.07.2018 в 02:08
0

I mention some errors that I notice in your SQL statement:

1.- You include a variable that has an ID value but you mention in the comments that it is PK (Primary key) given which your manager will include it automatically; for which it is not necessary to include it

2.- You have between $nombre and $ap double comma, which will generate error remove the one left over

3.- Personally I would remove that concatenation that you did in VALUES() to put the variables to your query

Leaving your code as follows

<?php

$sql=mysqli_query($conexion,"INSERT INTO registro(us, contrasena, nombre, 
ap, rfc, tel, dire, ciudad, pais)
VALUES('$us','$contrasena','$nombre','$ap','$rfc','$tel','$dire','$ciudad','$pais')");
    
answered by 25.07.2018 в 02:21
0

Several factors can influence that you can not, insert data, One is that the data has not been captured in the Textbox and that causes that when inserting if in your table some field is NO null insertion is not done, other than in the query in the variable:

  

". $ name." ',

You have an extra comma, another situation that the data of your connection has an error, It is recommended that you check your code well.

Good luck, Greetings

    
answered by 25.07.2018 в 04:06