你好,请帮我在登录过程中使用我的代码,这是一条错误信息
解析错误:语法错误,意外'' (T_ENCAPSED_AND_WHITESPACE), 期待标识符(T_STRING)或变量(T_VARIABLE)或数字 (T_NUM_STRING)
在$_SESSION['userid'] = $row['userid'];
行
这是我的完整登录过程代码:
session_start();
$message = "";
if(count($_POST) > 0){
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("etransmittal", $conn);
$result = mysql_query("SELECT * FROM tbl_userlist WHERE username = '" . $_POST["username"] . "' AND user_password = '" . $_POST["password"] . "');
$row = mysql_fetch_array($result);
if(is_array($row)){
$_SESSION['userid'] = $row['userid'];
$_SESSION['username'] = $row['username'];
}
else{
$message = "Invalid username or password";
}
}
if(isset($_SESSION['userid'])){
header("location: userhomepage.php");
}
答案 0 :(得分:1)
你丢失了一个双引号,我修复了它:
$result = mysql_query("SELECT * FROM tbl_userlist WHERE username = '" . $_POST["username"] . "' AND user_password = '" . $_POST["password"] . "'");
答案 1 :(得分:0)
<?php
if( $_POST['submit_button']=='Login' ) {
$userdata = "select * from usertbl WHERE username = '".$_POST['username']."' ";
$res = mysql_query($userdata);
$userdata = mysql_fetch_array($res);
$userDetail = $userdata[0];
if( ( $userDetail['username'] == $_POST['username'] ) && ( $userDetail['password'] == md5($_POST['password']) ) ){
$_SESSION['userid'] = $userDetail['id'];
$_SESSION['username'] = $userDetail['username'];
$_SESSION['useremail'] = $userDetail['email'];
header("Location:Dashboard.php");
} else {
header("Location:index.php");
}
}
?>
<form action="" method="POST">
<input type="text" name="username" >
<input type="text" name="password" >
<input type="submit" name="submit_button" value="login">
</form>