Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

need fix error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

need fix error

Postby nguyenanhtuanhvan » Thu Feb 28, 2013 7:41 pm

hi i wrote a code to create login page but it show this error
"Notice: Use of undefined constant id - assumed 'id' in C:\xampp\htdocs\login.php on line 41

Notice: Use of undefined constant level - assumed 'level' in C:\xampp\htdocs\login.php on line 42
chao ban ". CAN SOME ONE FIX THIS FOR ME? this is my code
1.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action='login.php' method='post'>
Username: <input type='text' name='username' size='25' /><br />
Password: <input type='password' name='password' size='25' /><br />
<input type='submit' name='ok' value='Dang Nhap' />
</form>

</body>
</html>
2.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
if(isset($_POST['ok']))
{
$u=$p="";
if($_POST['username'] == NULL)
{
echo "Please enter your username<br />";
}
else
{
$u=$_POST['username'];
}
if($_POST['password'] == NULL)
{
echo "Please enter your password<br />";
}
else
{
$p=$_POST['password'];
}
if($u && $p)
{
$conn=mysql_connect("localhost","root","123456") or die("can't connect this database");
mysql_select_db("tuan",$conn);
$sql="select * from users where username='".$u."' and password='".$p."'";
$query=mysql_query($sql);
if(mysql_num_rows($query) == 0)
{
echo "Username or password is not correct, please try again";
}
else
{
$row=mysql_fetch_array($query);
session_start();
$_SESSION['userid'] = $row[id];
$_SESSION['level'] = $row[level];
echo "chao ban";
}
}
}
?>


<body>
</body>
</html>
nguyenanhtuanhvan
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Feb 28, 2013 7:20 pm

Re: need fix error

Postby seandisanti » Fri Mar 01, 2013 8:42 am

this line:
Code: Select all
$_SESSION['userid'] = $row[id];

should read
Code: Select all
$_SESSION['userid'] = $row['id'];

'UNEXPECTED CONSTANT' means "You've forgotten to quote something"
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: need fix error

Postby nguyenanhtuanhvan » Sat Mar 02, 2013 7:42 pm

thank you. it worked
nguyenanhtuanhvan
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Feb 28, 2013 7:20 pm

Re: need fix error

Postby seandisanti » Mon Mar 04, 2013 10:03 am

No problem, I'm glad i could help.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.