PHP Error "Undefined index" -


hello i'm trying login system working on site , error saying notice: undefined index: user_login in c:\wamp\www\justbetweenfriends\home.php on line 4.

the database works , everthing else works besides error i'm getting now.

home.php code

 <?php error_reporting(e_all ^ e_deprecated); ?>     <?php     include ( "./inc/header.inc.php" );     echo $_session["user_login"];     ?> 

full code index.php

<?php error_reporting(e_all ^ e_deprecated); ?> <?php include( "./inc/header.inc.php" ); ?> <?php  $reg = @$_post['reg']; //declaring variables prevent errors $fn = ""; //first name $ln = ""; //last name $un = ""; //username $em = ""; //email $em2 = ""; //email 2 $pswd = ""; //passoword $pswd2 = ""; // password 2 $d = ""; // sign data $u_check = ""; // check if username extsts //registration form $fn = strip_tags(@$_post['fname']); $ln = strip_tags(@$_post['lname']); $un = strip_tags(@$_post['username']); $em = strip_tags(@$_post['email']); $em2 = strip_tags(@$_post['email2']); $pswd = strip_tags(@$_post['password']); $pswd2 = strip_tags(@$_post['password2']); $d = date("y-m-d"); // year - month - day  if ($reg) { if ($em==$em2) { // check if user exists $u_check = mysql_query("select username users username='$un'"); // count amount of rows username = $un $check = mysql_num_rows($u_check); if ($check == 0) { //check of fields have been filed in if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) { // check passwords match if ($pswd==$pswd2) { // check maximum length of username/first name/last name not exceed 25 charcters if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) { echo "the maximum limit username/first name/last name 25 characters!"; } else { // check maximum length of password not exceed 25 characters , not less 5 characters if (strlen($pswd)>30||strlen($pswd2)<5) { echo "your password must between 5 , 30 characters long!"; } else { //encrypt password , password 2 using md5 before sending database $pswd = md5($pswd); $pswd2 = md5($pswd2); $query = mysql_query("insert users values ('','$un','$fn','$ln','$em','$pswd','$d','0')"); die("<h2>welcome justbetweenfriends</h2>login account started ..."); } } } else { echo "your passwords don't match!"; } } else { echo "please fill in fields"; } } else { echo "username taken ..."; } } else { echo "your e-mails don't match"; } }  // user login code  if (isset($_post["user_login"]) && isset($_post["password_login"])) { $user_login = preg_replace('#[^a-za-z0-9]#i', '', $_post["user_login"]); $password_login = preg_replace('#[^a-za-z0-9]#i', '', $_post["password_login"]); $password_login_md5 = md5($password_login); $sql = mysql_query("select id users username='$user_login' , password='$password_login_md5' limit 1"); //check thir existance $usercount = mysql_num_rows($sql); //count number of rows returned if ($usercount == 1) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; } $_session["user_login"] = $user_login; header("location: index.php"); exit(); }else{     echo " information incorrect, try again"; exit(); } } ?> <div style="width: 800px; margin: 0px auto 0px auto;"> <table> <tr> <td width="60%" valign="top"> <h2>already member? sign in below!</h2> <form action="index.php" method="post"> <input type="text" name="user_login" size="25" placeholder="username"><br /><br /> <input type="text" name="password_login" size="25" placeholder="password"><br /><br /> <input type="submit" name="login" value="login"> </form> </td> <td width="40%" valign="top"> <h2>sign below!</h2> <form action="index.php" method="post"> <input type="text" name="fname" size="25" placeholder="first name"><br /><br /> <input type="text" name="lname" size="25" placeholder="last name"><br /><br /> <input type="text" name="username" size="25" placeholder="username"><br /><br /> <input type="text" name="email" size="25" placeholder="email address"><br /><br /> <input type="text" name="email2" size="25" placeholder="email address (again)"><br /><br /> <input type="text" name="password" size="25" placeholder="password"><br /><br /> <input type="text" name="password2" size="25" placeholder="password (again)"><br /><br /> <input type="submit" name="reg" value="sign up!"> </form> </td> </tr> </table> <?php include( "./inc/footer.inc.php" ); ?> 

it's not error persay, more of warning php. php allows call variable if hasn't been set, warn if it, security reasons. more detailed explanation can found here.


Comments

Popular posts from this blog

How to logout from a login page in asp.net -