【问题标题】:Can someone help me find out the meaning behind these errors? [duplicate]有人可以帮我找出这些错误背后的含义吗? [复制]
【发布时间】:2023-03-06 17:57:01
【问题描述】:

可能重复:
Can anyone help me figure out the meaning of this php error message?

代码如下:

$con = mysql_connect("localhost", "root", '');

if (!$con)
{
    die('Cannot make a connection');
}


mysql_select_db('yumbox_table', $con) or die('Cannot make a connection');

$user_name = mysql_real_escape_string($_POST['user_name']);
$password = mysql_real_escape_string($_POST['password']);
$user_type = mysql_real_escape_string($_POST['user_type']);



$data = mysql_query("SELECT * from users where user_name == '$user_name' AND password == '$password' user_type == '$user_type'") or die(mysql_error());

$info = mysql_fetch_array($data);

$count = mysql_numrows($data);

if ($count==1)
{
    echo ("Success!!");
}
else 
{
    echo ("BIG FRIGGIN FAILURE!!");
}



mysql_close($con);

这些是从所述代码生成的错误消息:

Notice: Undefined index: user_name in C:\wamp\www\login.php on line 12
Call Stack
#   Time    Memory  Function    Location
1   0.0013  371904  {main}( )   ..\login.php:0

( ! ) Notice: Undefined index: password in C:\wamp\www\login.php on line 13
Call Stack
#   Time    Memory  Function    Location
1   0.0013  371904  {main}( )   ..\login.php:0

( ! ) Notice: Undefined index: user_type in C:\wamp\www\login.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0013  371904  {main}( )   ..\login.php:0

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== '' AND password == '' user_type == ''' at line 1

【问题讨论】:

  • @user717363 停止发送垃圾邮件问题。请更新您的原始问题并留下反馈。

标签: php mysql


【解决方案1】:
  • 您的某些变量未设置。他们是空的。因此Undefined index 消息
  • 您的查询也有问题。字符串的比较运算符是=,而不是==。应该是SELECT * from users where user_name = '$user_name' AND password = '$password' AND user_type == '$user_type'"
  • 您忘记了user_type 列之前的=

【讨论】:

    【解决方案2】:

    不确定这部分的错误。

    $data = mysql_query("SELECT * from users where user_name == '$user_name' AND password == '$password' user_type == '$user_type'") or die(mysql_error());
    

    试试这个

    $data = mysql_query("SELECT * from users where user_name == '".$user_name."' AND password == '".$password."' user_type == '".$user_type."'") or die(mysql_error());
    

    【讨论】:

    • 编辑了您的问题,添加了代码格式
    猜你喜欢
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    相关资源
    最近更新 更多