在登录php中解析错误

时间:2014-08-04 08:41:56

标签: php html

我正在构建一个拥有用户数据库的站点,用户可以在其中登录并注册。当我测试用于登录的PHP代码时,它会说“解析错误”一次并且invalid { in line 16。我的代码中有什么问题?

<?php

$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];
$con = mysql_connect("localhost","root","xxxxxxxxxx") or die('Could not connect:'.mysql_error());
$test = mysql_select_db("users",$con)or die("unable to connect");

$result = "SELECT  * FROM users where username='$user' AND password='$pass'";
$alpha = @mysql_query($result,$con);

if($alpha==1)
{
     $expire=time()+60*60*24*30;
     setcookie("id",$row['id'],$expire);
     echo "Logged in. as <b>".$row['username']."</b>";
     $userID = $row['id'];
     header("index map.html")
 }
 else
 {
     echo "<b>Username or password  is wrong</b><br><br>";
     header("index.html")
 }

 mysql_close($con);

 ?>

4 个答案:

答案 0 :(得分:1)

这里的PHP存在一些问题。

  1. header需要用分号关闭它
  2. header需要位置设置..即header('location: index.html');
  3. 你应该替换

    header("index map.html")
    

    header("location: map.html");
    

    您还需要替换

    header("index.html")
    

    header("Location: index.html");
    

答案 1 :(得分:0)

到底是什么?排是从哪里来的? 你没有调用任何mysql_fecth_array或者某些与遍历行结果相关的东西 ..至少你的代码使用了

  

$ row = mysql_fetch_result / array($ result,$ conn);

然后使用行作为我的建议......

if($alpha==1)
{
     $expire=time()+60*60*24*30;
     setcookie("id",$row['id'],$expire);
     echo "Logged in. as <b>".$row['username']."</b>";
     $userID = $row['id'];
     header("index map.html")
 }

答案 2 :(得分:-1)

首先你的代码非常不安全!我们可以轻松地做一些SQL注入。 尝试至少使用:mysql_real_escape。 (How to use mysql_real_escape_string function in PHP)。使用PDO也会更好(在我看来)。

你忘记了

中的点

$result = "SELECT * FROM users WHERE username='.$user.' AND password='.$pass.'";(第7行)

你忘了把分号和字段键名(第21行)放在一起 header("location: index.html");

最好的问候。

答案 3 :(得分:-2)

你的header()函数调用

错误地纠正了它
header("location:index-map.html");
相关问题