gpt4 book ai didi

php - 在 PHP 中使用时 MySQL 查询语法错误

转载 作者:行者123 更新时间:2023-11-29 03:54:49 29 4
gpt4 key购买 nike

iPhone 密码

当我使用此代码时,它总是显示错误密码,但我输入了正确的凭据。

    NSString *post =[NSString stringWithFormat:@"UserName=%@&UserPas   sword=%@",userNameTextField.text, userPasswordTextFiled.text];

NSString *hostStr = @"http://www.celeritas-solutions.com/emrapp/connect.php";
= [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized "
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];


} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];

}

我正在从数据库中获取验证用户名和密码,但它给出了 sql 语法错误

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

mysql_select_db("emriphone", $con);


$u=$_GET['UserName'];
$pw=$_GET['UserPassword'];

$check ="SELECT UserName,UserPassword from appUsers WHERE UserName=$u AND UserPassword=$pw";

$login=mysql_query($check,$con) or die(mysql_error());

if(mysql_num_rows($login)==1){

$row =mysql_fetch_assoc($login);
echo 'YES'; exit;
}

else{
echo'NO';exit;
}

mysql_connect($con);

最佳答案

您需要在查询中放置单引号 -

$check ="SELECT UserName, UserPassword 
FROM appUsers
WHERE UserName='$u'
AND UserPassword='$pw'"; // These are probably varchar data columns
// in your db. In that case, you should
// put single quotes like this.

当您在数据库中搜索文本字段时,您应该在它们周围加上单引号。否则 MySQL 会报错。

关于php - 在 PHP 中使用时 MySQL 查询语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9765459/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com