为什么我的代码在重定向时给出了解析错误

时间:2015-10-07 21:31:26

标签: php

注册所在的地方我得到一个解析错误。假设用户输入正确的用户名和密码,通过查看每个用户名和密码进行比较,重新定向到输入页面,但它不会工作!任何想法?

<?php
$conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)};
DBQ= e:\user\kyle.kinsey\database\Final.accdb','','');



// username and password sent from form, 'Username' is from name below in the html part
$myusername = '';
$mypassword = '';

$myusername = $_POST["Username"];
$mypassword = $_POST["Password"];

$db_name="Final"; // Database name
$tbl_name="Accounts"; // Table name 



$sql = "SELECT * FROM $tbl_name WHERE Username = '$myusername' AND Password = '$mypassword'";

// not this, because it is not access, which is what we are using, $result = mysql_query($sql);

//*** we are using access and not mysql ($result = mysql_query($sql);)
// $rs = odbc_exec($conn,$sql); is what is used to connect to a access database i think.
$rs = odbc_exec($conn,$sql);


///****** loop through recordset and count the number of returned records

$count = 0;
while ($row = odbc_fetch_array($rs))

{

$count++;

}

if ($count >0)
{
//**** redirect user
Register $myusername, $mypassword and redirect to file ("Input.php");  // dose it redirect?
session_register("myusername");
session_register("mypassword");
header("location:Input.php");
}

else

{

//***** display error
echo "Sorry, no matches found";

}




odbc_close($conn);




?>



<!DOCTYPE htm1
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>KLK: Final </title>
<script ></script>

<style type="text/css">
body {font-family:Times New Roman; font-size:14pt; color:Silver, background:blue}
h2 {text-align:center}
h2, h3 {color:#2E8B57}


.fnote {font-size:7pt}
div#Offset  {text-align:center}
</style>


</head>

<body>
<form name="Login" method="post" action="Login.php">
<div  id="Offset">

Login: <input type="text" name="Username" id="Username"><br>
Password: <input type="text" name="Password"><br>

<input type="submit" name="Search" value="Search" id ="Search">



</div>



</form>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

根据PHP文档,不推荐使用session_register()。相反,您可以使用session_start()初始化会话:

<?php
session_start();
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
header('Location: input.php');
?>

答案 1 :(得分:0)

检查PHP's documentation on comment syntax

要解决您的解析错误,请将//添加到引发错误的行前面。 所以它会变成:

//Register $myusername, $mypassword and redirect to file ("Input.php");

如果您尝试了但仍然收到错误,请告诉我们您尝试过的内容。

会有评论,但我没有代表。