html - How should I link a PHP login script to a mysql database for verification? -


i new php programming language , working on first site using language having trouble linking log in page mysql database in order carry out account verification , create cookies. how should go code below has trouble being executed.

<?php  $connection =  mysql_connect("localhost","root",) or die("couldn't connect server!"); mysql_select_db("irrigation",$connection)  or die("couldn't connect server!");  if ($_post['login']){     if ($_post['username'] && $_post['password']){         $username = mysql_real_escape_string($_post['username']);         $username = mysql_real_escape_string(hash("sha512",$_post['password']));         $user = mysql_fetch_array(mysql_query("select * 'users' 'username' = '$username'"));         if ($user == '0'){             die("that username doesnt exist! try making <i>$username</i>today!<a href='index.php'>&larr; home </a>");         }         if ($user['password'] != $password){             die("incorrect password!<a href='index.php'>&larr; home </a>");         }         $salt = hash ("sha512",rand().rand().rand());         setcookie("c_user",hash("sha512",$username),time()+ 24 * 60 *60,"/");         $userid = $user['user_id'];         mysql_query("update 'users' set 'salt'='$salt' 'user_id'='$userid'");         die("you logged in $username");             }         }  echo "      <body style='font-family:verdana,sans-serif;'>         <div style='width: 80%; padding; 10px; border:1px solid #e3e3e3;  background-color;#fff ; color #000;             <br/>             <form action=' ' method='post'>                 <table>                     <tr>                         <td>                             <b> username: </b>                         </td>                         <td>                             <input type='text' name='username' style='padding: 4px;'/>                         </td>                     </tr>                     <tr>                         <td>                             <b>password</b>                         </td>                         <td>                             <input type='password' name='password' style='padding: 4px;'/>                         </td>                     </tr>                     <tr>                         <td>                                 <input type='submit' value='login'>                         </td>                     </tr>                 </table>             </form>             <br />             <h6>                 no account? <a href='register.php'> register here!</a>             </h6>         </div>     </body>      "; ?> 

whenever press submit button, nothing happens.

using code pasted here nothing happening because have typo: <div style='width: 80%; padding; 10px; border:1px solid #e3e3e3; background-color;#fff ; color #000;

that div tag isn't being closed here. change line <div style='width: 80%; padding; 10px; border:1px solid #e3e3e3; background-color;#fff ; color #000;'> (note '> added end) , login button should work.

edit

to code working please fix these issues too:

  1. change $username = mysql_real_escape_string(hash("sha512",$_post['password'])); $password = mysql_real_escape_string(hash("sha512",$_post['password'])); (notice change $password in beginning)
  2. change <input type='submit' value='login'> <input type='submit' value='login' name='login'> (adding name='login'). needed line if ($_post['login']) working.

and others pointed out:

there no more support mysql_* functions, officially deprecated, no longer maintained , removed in future. should update code pdo or mysqli ensure functionality of project in future.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -