<?php Session_start(); ?>
<html>
</head>
<body>
<form action='auth.php?login=yes'method=POST>
Username: <input type=text, name='user'><br/>
Password: <input type=password name='pass'><br/>
<input type=submit name='login'value='go!'>
</form>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$login=$_GET['login'];
if ($login=='yes'){
$con = mysql_connect ("localhost","root","") or die ("error");
mysql_select_db ("login") or die ("eroor connecting Database");
$get=mysql_query("SELECT count(id)FROM login WHERE user= '$user' AND pass='$pass'");
$result=mysql_result($get,0);
mysql_close($con);
if($result!=1)echo "Login failiure";
else{
echo "Login Sucessfull";
$_SESSION['user']=$user;
}
}
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
?>
</body>
</html>
hi all:
this is a script for web page login. I have taken this for a you tube viedo. I have created three parameters in my database table.
Database name: login
tablename:login
filename : auth.php
three fields are exactley (id,user,pass).
when i compile it, the webpage will be dispalyed with three notices and they are:
Notice: Undefined index: user in C:\wamp\www\guestbook\auth.php on line 12
Notice: Undefined index: pass in C:\wamp\www\guestbook\auth.php on line 13
Notice: Undefined index: login in C:\wamp\www\guestbook\auth.php on line 14
but when i enter a user name and a password, it will work as expected with dissapered notices.
i want to stop these notices appearing when i compile it.
can any one help?
Thank you
Shehan
undifined indx
Moderator: General Moderators
Re: undifined indx
Ask your host to turn off error_reporting on your server (or more accurately only display parse/fatal errors).
-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: undifined indx
I absolutely disagree with this statement. If you are getting warnings that means you are doing something wrong, you should not turn off error reporting to make them go away; you should fix it. After the site is completely built and ready to go live then ALL error reporting should be turned off.oscardog wrote:Ask your host to turn off error_reporting on your server (or more accurately only display parse/fatal errors).
Here is you're problem,
Code: Select all
<form action='auth.php?login=yes'method=POST>
Username: <input type=text, name='user'><br/>
Password: <input type=password name='pass'><br/>
<input type=submit name='login'value='go!'>
</form>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$login=$_GET['login'];
if ($login=='yes'){
Change that code to this:
Code: Select all
<form action='auth.php' method=POST>
Username: <input type=text, name='user'><br/>
Password: <input type=password name='pass'><br/>
<input type=submit name='login' value='go!'>
</form>
<?php
if (isset($_POST['login']){
$user=$_POST['user'];
$pass=$_POST['pass'];
Since we are not using $_GET['login'] the condition of the if has to change. So I changed it so that it just checks if $_POST['login'] is set because that is the name of the submit button and it will confirm that the form has been submitted.
Then to fix the problem that you came here for, I moved the $user and $pass declarations inside the if statement since they will only exist if the form has been submitted.
Shawn
Re: undifined indx
the problem remains same.shawngoldw wrote:I absolutely disagree with this statement. If you are getting warnings that means you are doing something wrong, you should not turn off error reporting to make them go away; you should fix it. After the site is completely built and ready to go live then ALL error reporting should be turned off.oscardog wrote:Ask your host to turn off error_reporting on your server (or more accurately only display parse/fatal errors).
Here is you're problem,The problem is that you are trying to access $_POST['user'], $_POST['pass'], and $_GET['login'] when those indexes of the arrays have never been set.Code: Select all
<form action='auth.php?login=yes'method=POST> Username: <input type=text, name='user'><br/> Password: <input type=password name='pass'><br/> <input type=submit name='login'value='go!'> </form> <?php $user=$_POST['user']; $pass=$_POST['pass']; $login=$_GET['login']; if ($login=='yes'){
Change that code to this:First, I removed "?login=yes from the action, it is just unnecessary.Code: Select all
<form action='auth.php' method=POST> Username: <input type=text, name='user'><br/> Password: <input type=password name='pass'><br/> <input type=submit name='login' value='go!'> </form> <?php if (isset($_POST['login']){ $user=$_POST['user']; $pass=$_POST['pass'];
Since we are not using $_GET['login'] the condition of the if has to change. So I changed it so that it just checks if $_POST['login'] is set because that is the name of the submit button and it will confirm that the form has been submitted.
Then to fix the problem that you came here for, I moved the $user and $pass declarations inside the if statement since they will only exist if the form has been submitted.
Shawn