mysql - How can I make a simple login system with PHP? -


my university left task create login system php (obviously, connected database ). problem registration page not save data sent database. don't know why is.

here code:

<html> <head> <link type="css/text" rel="stylesheet" href="unixyz.css"/> <meta charset="utf-8"/> <title>registro</title> </head> <body> <?php session_start(); $host="****"; $username="****";  $password="****";  $db_name="****";  $tbl_name="****";  mysqli_connect($host,$username,$password,$db_name)or die("cannot connect"); $email=$_post['email']; $password=$_post['password']; if (filter_var($email, filter_validate_email)){ $sql="select 'email' 'user' 'email'='$email'"; $result=mysqli_query($sql); $count=mysqli_num_rows($result); if($count>0){ echo ("<center><h1><font color='red'>el usuario<br><font color='blue'>".$email."<br><font color='red'>ya existe!<br><a href='index.php'>inicio</a>"); }else{ $sql="insert $tbl_name ('email','pass')values('$email','$password')"; $result=mysqli_query($sql); if($result){ header("location:inicioxyz.php"); }else{ echo "error mysql"; }  mysqli_close(); } }else{ echo"<center><h1><font color='red'>error el mail ingresado no es v&aacute;lido<br><a href='index.php'>inicio</a>"; } ?> <img width="1300px" src="http://i.imgur.com/iofmylk.png"/> <hr width="80%"/> <div class="login"> <h3 class="h3">datos procesados</h3> <div class="imglog"><img src="http://i.imgur.com/ycuazhh.png"/></div><br><br><br><br> <h4><a href="inicioxyz.php" class="registrate">pulsa aquĆ­ para regresar la pagina de inicio.</a></h3> </div> </body> </html> 

errors

  1. mysqli_connect() should assign variable

    $connect = mysqli_connect($host,$username,$db_password,$db_name)or die("cannot connect");

  2. as @sean suggest change query

     $sql="select email user email='$email'";  $sql="insert $tbl_name (email, pass) values ('$email','$password')"; 
  3. $result=mysqli_query($sql); should link database connection($connect)

     $result=mysqli_query($connect,$sql); 
  4. $password assign twice in code

    $password="****";//change $sql="insert $tbl_name (email,pass) values ('$email','$password')"; 

read this

  1. mysqli_query
  2. mysql_connect

so final form code is

<?php     session_start();     $host="****";     $username="****";     $db_password="****";     $db_name="****";     $tbl_name="****";     $connect = mysqli_connect($host,$username,$db_password,$db_name)or die("cannot connect");      $email=$_post['email'];     $password=$_post['password'];     if (filter_var($email, filter_validate_email)){         $sql="select email user email='$email'";         $result = mysqli_query($connect,$sql);         $count=mysqli_num_rows($result);         if($count>0)         {             echo ("<center><h1><font color='red'>el usuario<br><font color='blue'>".$email."<br><font color='red'>ya existe!<br><a href='index.php'>inicio</a>");         }else         {             $sql="insert $tbl_name (email,pass) values ('$email','$password')";             $result=mysqli_query($connect,$sql);             if($result){                 header("location:inicioxyz.php");             }else{                 echo "error mysql";             }             mysqli_close($connect);         }     }else     {         echo"<center><h1><font color='red'>error el mail ingresado no es v&aacute;lido<br><a href='index.php'>inicio</a>";     } ?> 

and aware of sql injection


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -