mysql_result显示语法错误

时间:2016-10-13 06:13:57

标签: php

我正在使用登录系统并在使用

时出错

mysql_result()功能

错误是:

  

解析错误:语法错误,意外','

这是代码

function user_exists($username){
    $username = sanitize($username);
    $query = mysql_query("SELECT COUNT(`user_id`) FROM `p32_users` WHERE `user_name` = '$username'");
    return (mysql_result(($query , 0) == 1) ? true : false;
}

谢谢

2 个答案:

答案 0 :(得分:4)

你的括号搞砸了。它应该是

function SlideImages(){
    this.myphotos = new Array (
            "slide_image_1",
            "slide_image_2",
            "slide_image_3",
            "slide_image_4",
            "slide_image_5"
        );
    this.currentImage = 1;
    this.totalImageCount = this.myphotos.length;

}

//Object creation
var slideImages = new SlideImages(); 

//accessing object properties
console.log(slideImages.currentImage) //output:1

此外,不需要三元表达式,因为return (mysql_result($query, 0) == 1) ? true: false; 本身会返回==true。所以只是:

false

答案 1 :(得分:0)

以下查询应解决您的问题:

$query = mysql_query("SELECT
COUNT(user_id)
FROM p32_users
WHERE user_name='{$username}'
");

return (mysql_result($query, 0) == 1) ? true: false;