The data is not recorded in my database

1

<?php
  
$X = mysqli_connect("localhost","root","");//or die("<h2>NO se encuentra el servidor </h2>"); 
//mysqli_select_db("abogados",$X) or die("<h2>error conexion </h2>"); 
if(!$X){
   die("<h2>NO se encuentra el servidor </h2>");
}
else {
    $nombre=$_POST['first_name'];
	$password=$_POST['passwd'];
	$repass=$_POST['repass'];
	$appaterno=$_POST['last_name'];
	$apmaterno=$_POST['last_name2'];
	$email=$_POST['email'];
	$direccion=$_POST['addres'];
	$fec_nac=$_POST['date'];
	$nickname=$_POST['nick'];
	$celular=$_POST['movil'];
	
}
	
	
if($password!=$repass){ 
	die("<h2>contraseñas diferentes </h2>");
	}	
//$r= "INSERT INTO persona values ('$nombre','$appaterno','$apmaterno','$email','$fec_nac','$direccion','$celular','$nickname')";
// echo $r;

	mysqli_query($X,"INSERT INTO persona (nombre,appaterno,apmaterno,email,fec_nac,direccion,celular,nickname) VALUES('$nombre','$appaterno','$apmaterno','$email','$fec_nac','$direccion','$celular','$nickname')"); // or die("<h2>error de envio</h2");
	
	mysqli_query($X,"INSERT INTO usuario (nicknaname,email,password) VALUES ('$nickname','$$email','$password')"); // or die("<h2>error de envio</h2");
   
	mysqli_close($X);
				  echo'se a registrado';

</style>
<body>
    <div id="wrapper">
	    <fieldset>
        <form action="file:///C|/xampp/htdocs/alta.php" method="POST">
                <legend>Registro</legend>
                <div>
                    <input type="text" name="first_name" placeholder="Nombres(s)" required/>
                </div>
                <div>
                    <input type="text" name="last_name" placeholder="Apellido Paterno" required/>
                </div>
				<div>
                    <input type="text" name="last_name2" placeholder="Apellido Materno" required/>
                </div>
                <div>
                    <input type="password" name="passwd" placeholder="Contrasenia" required/>
                </div>
                <div>
                    <input type="password" name="repass" placeholder="Confirma contrasenia" required/>
                </div>
				<div>
                    <input type="text" name="email" placeholder="Email" required/>
                </div>
				<div>
                    <input type="text" name="addres" placeholder="Direccion" required/>
                </div>
				<div>
                    <input type="date" name="date" placeholder="Fecha de  nacimiento" required/>
                </div>
				<div>
                    <input type="text" name="nick" placeholder="Nombre de usuario" required/>
                </div>
				<div>
                    <input type="varchar" name="movil" placeholder="Celular" required/>
                </div>
				<div>
                
                <input type="submit" name="submit" value="Enviar"/>    
        </form>
		</fieldset>
    </div>
</body>
</html>
    
asked by Hugo Castillo 04.12.2018 в 15:59
source

1 answer

0

Three things. The first one in the form, as the partner pointed you in the comments. In the action you are called to a php script. You should call it by http (if you use the absolute path), or by relative path. Something like this:

<form action="http://localhost.com/alta.php" method="post">

or

<form action="alta.php" method="post">

This last option only if the form and the script are on the same route. If not, you must put the relative path from the form to the script. In any case, a PHP can not be called by file:// .

Fixed this, we go to the following, that tb you have put in the comment: in the script put a var_dump($_POST); , just to make sure that the variables are happening. I know it sounds silly, but it's okay to make sure.

Finally, the classic witness when a query should work, and it does not. Below the line where you use mysqli_query(...) put the following:

echo mysqli_errno($X)." **** ".mysqli_error($X)."<br>";

You can not imagine the hundreds of times that line has told me exactly where I was making an error (a misplaced field name, a plus or minus point in the query, ...). That line will help you in many scripts.

As a final tip, if you can, leave mysqli aside and leave for PDO.

I hope I have helped you.

    
answered by 27.12.2018 в 21:56