Hi eveyone im trying to write some code but there is a problem i think ..if i type index.php into browser before loggin in ..i get this error
Notice: Undefined index: position _ in C:\wamp\www\MemberForms\index.php on line 4
Notice: Undefined index: user_ in C:\wamp\www\MemberForms\index.php on line 5
Please sign in
but after sign-in everythin is ok no eny error messages and says "welcome " , Im confused could you help plase
my code
signinform.php
<form action="signin.php" method="post">
<div align="center" class="style1 style1">SIGN IN PAGE</div>
<table width="200" border="0">
<tr>
<td> Username: </td>
<td>
<input type="text" name="txtname" />
</td>
<td> </td>
</tr>
<tr>
<td>Passsword: </td>
<td>
<input type="password" name="txtpass" />
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Sign In" />
</td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
signin.php
<?php
session_start();
include("cnn.php");
$name=$_POST['txtname'];
$pass=$_POST['txtpass'];
$fetch_array=mysql_fetch_array(mysql_query("select * from memberinfo where Username='$name' and Pass='$pass' "));
if(($name!="" || $pass!="" ) && ($name==$fetch_array['Username'] && $pass==$fetch_array['Pass']))
{
$_SESSION['position _']= "girildi";
$_SESSION['user_']=$name;
header("location:index.php");
}
?>
index.php
<?php
session_start();
$Ses_value=$_SESSION['position _'];
$user=$_SESSION['user_'];
if($Ses_value == ""){
echo "Please sign in";
}
else{
echo "Welcome " .$user;
}
?>
Login problem
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Login problem
Because $_SESSION['position _'] and $_SESSION['user_'] don't exist until you sign in. You need to check them with isset() before using them.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Login problem
hi and thanks for replying me i watched a training video about sesion and cookie and that guy didnt use that code .so i thouht mybe it could be php server settings what do you say my friend
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Login problem
The code you have is flawed, so I say that you need to check if a variable is set before you use it. If you turn off error reporting then you won't see those notices, but it is still flawed.
Last edited by AbraCadaver on Tue Jun 22, 2010 2:29 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Login problem
On a side note, you need to be passing $name and $pass through mysql_real_escape_string() or you are open to SQL Injection attacks.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Login problem
Thanks a lot i will try but mybe you want to check this video because isset doesn't exist there thanks again
http://www.seyretogren.com/video/web-ta ... stemi.html
http://www.seyretogren.com/video/web-ta ... stemi.html
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Login problem
Yes, there is a lot of useless stuff on the Internet. Just because you found it online does not mean that it is reliable.digrev wrote:Thanks a lot i will try but mybe you want to check this video because isset doesn't exist there thanks again
http://www.seyretogren.com/video/web-ta ... stemi.html
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.