dongwuchu0314 2010-12-14 20:20
浏览 11

一个非常简单的查询不适用于PHP

i have a little problem with a very simple query , when i hard code the values in the query its working , but when i use a PHP variable nothing is retrieved , i over check a lot of things including the query , the database it worth saying that i'm getting the variable from a form by POST and also checked that i'm getting them but when i use them in a query they jst dont work :S

here's my code ..PLZ what am i doing wrong ?!!!!!!!!!!!

  <?php 

 $email = $_POST ['emailEnter'] ; 
$password = $_POST ['passwordEnter'];


$connection = mysql_connect('localhost','root','') ;

$db_selected = mysql_select_db("lab5" , $connection) ;

$query = 'select * From user where email="$email" and password="$password" ' ;
$result = mysql_query ($query , $connection);
    while($row=mysql_fetch_array($result))
    {
        echo $row['name'];
    }
mysql_close($connection);       
?>
  • 写回答

9条回答 默认 最新

  • douan2478 2010-12-14 20:23
    关注

    The basic debugging steps are 1. adding

    if (!$result) echo "Error: ".mysql_error();
    

    to see any errors from the SQL query and 2. outputting

    echo "Query: $query";
    

    to see what the variables contain. One of these will point you to the problem.

    Also, your query is vulnerable to SQL injection. You should add a

    $email = mysql_real_escape_string($email);
    $password = mysql_real_escape_string($password );
    

    after fetching the values from the POST array.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据