I can not insert data using the php form

0

In my next form within a php page I try to insert an email and a password inside the database. But he does not specify me why I can not perform that operation and I get the error message "I do not turn out"

<div class="panel-login">
   <div class="header"><div class="user"><img src="IMG/icon.png" width=90 alt=""></div><span class="text">Iniciar sesión</span></div>
      <form method="POST" action="#">
         <input type="email" name="email" class="email" placeholder="email" />
         <input type="password" name="contraseña" class="contraseña" placeholder="contraseña" />
         <input type="submit" name="submit" class="valider" value="Crear" />
         <center><u><a href="Index.php">Si ya tiene una cuenta, ingrese aqui</a><u/><center/>
      </form>
<?php
   if(isset($_POST["submit"]))
   {     
      if(!empty($_POST['email']) && !empty($_POST['contraseña'])) 
      {
         $email=$_POST['email'];
         $contraseña=$_POST['contraseña'];

         $con=mysql_connect('localhost','root','') or die(mysql_error());
         mysql_select_db('usuario') or die("no se puede seleccionar base de datos");
         $query=mysql_query("SELECT * FROM login WHERE email='".$email."'");
         $numrows=mysql_num_rows($query);

         if($numrows==0)
         {
            $sql="INSERT INTO login(email,contraseña) VALUES('$email','$contraseña')";
            $result=mysql_query($sql);

            if($result)
            {
               echo "email ingresado correctamente";
            } 
            else 
            {
               echo "no resulto";
            }
        } 
        else 
        {
            echo "Email ya registrado";
        }
      } 
      else 
      {
         echo "Llene todos los campos";
      }
   }?>
</div>

Is there something I need to add or delete?

    
asked by Beta 14.08.2017 в 00:41
source

1 answer

0

Hello good night, I found where your error is, it seems that a conflict is generated using the ñ: PHP Parse error: syntax error, unexpected '$ contrase \ xc3 \ xb1a' The solution is to change the word password by password or another word like pass, usually in the use of variables and name of fields in the database, the use of the letter ñ is not recommended, only to show the data.

On the other hand you use the mysql_connect function to connect and make your queries, the problem is that it is a function that is already deprecated in PHP 7 link

I recommend you use this link

And finally using the latest library and changing the names would be your file so

 <div class="panel-login">
 <div class="header"><div class="user"><img src="IMG/icon.png" width=90 alt=""></div><span class="text">Iniciar sesión</span></div>
  <form method="POST" action="#">
     <input type="email" name="email" class="email" placeholder="email" />
     <input type="password" name="contrasena" class="contraseña" placeholder="contraseña" />
     <input type="submit" name="submit" class="valider" value="Crear" />
     <center><u><a href="Index.php">Si ya tiene una cuenta, ingrese aqui</a><u/><center/>
  </form>

         if (! empty ($ _ POST ['email']) &! empty ($ _ POST ['password']))         {

     $email=$_POST['email'];
     $contrasena=$_POST['contrasena'];

     $con=mysqli_connect('localhost','root','','usuario') or die(mysql_error());

     $query= $con->query("SELECT * FROM login WHERE email='".$email."'");

     $numrows= $query->num_rows;

     if($numrows==0)
     {

         $sql="INSERT INTO login(email,contrasena) VALUES('$email','$contrasena')";

        $result = $con->query($sql);

        if($result)
        {
           echo "email ingresado correctamente";
        } 
        else 
        {
           echo "no resulto";
        }
    } 
    else 
    {
        echo "Email ya registrado";
    }
  } 
  else 
  {
     echo "Llene todos los campos";
  }
 }?>

As you can see the code is almost the same without many changes

Greetings!

    
answered by 14.08.2017 / 04:22
source