duanmao1975 2014-05-08 17:02
浏览 7

用html打印的PHP代码[关闭]

This is the PHP code for logging the user into the website which I am building but whenever I run this code I am getting the following output. Please help me.

I am using WAMP server, short open tag is enabled.

OUTPUT

wrong password'; } } else { echo 'invalid username'; } } ?> `

THIS IS THE PHP CODE

<?php
if(isset($_POST['name'])){

//connecting to data base 

$con=mysqli_connect("localhost:3306","root","","recommender");

// Check connection
if (mysqli_connect_errno())
{

echo "Failed to connect to MySQL: " . mysqli_connect_error();

}


  $q = "select * from user where name ='".mysql_real_escape_string($_POST['name'])."'";
  $res = mysql_query($q) or die("wrong query");
    $row = mysql_fetch_assoc($res);
  if(!empty($row))
{
    if($_POST['password']==$row['password'])
    {
        $_SESSION['name']=$_POST['name'];
        header('Localhost/home.html');
    }
    else
    {
        echo '<centre><font color="red">wrong password</font></centre>';

    }
}
else
{
    echo '<centre><font color="red">invalid username</font></centre>';

}

}
?>
  • 写回答

2条回答 默认 最新

  • dsvcqvp139098 2014-05-08 17:06
    关注

    you have a syntax error on

    $q = "select * from user where name ='.mysql_real_escape_string($_POST['name'])."'";<br>
                                         ^^ lost "
    

    solve this with

    $q = "select * from user where name = '". mysql_real_escape_string($_POST['name']) . "'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程