使用php的Mysql更新代码出错 [英] Error in Mysql update code using php

查看:71
本文介绍了使用php的Mysql更新代码出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行脚本时,我在php中的MySql更新代码中出现以下错误。



数据库查询失败,因为你有一个SQL语法错误;检查与MySQL服务器版本对应的手册,以便在'= 

附近使用正确的语法



这是导致错误的代码:< br $>


公共功能更新(){
全球 $数据库;

$ sql = 更新用户SET;
$ sql 。= FullName =' 。$ database-> mysqlPrep($ this-> fullName)。 ',< /跨度>;
$ sql 。= RoleID =' 。 $ database-> mysqlPrep($ this-> roleID)。 ',;
$ sql 。= UserName =' 。 $ database-> mysqlPrep($ this-> userName)。 ',;
$ sql 。= Email =' 。 $ database-> mysqlPrep($ this-> email)。 ',;
$ sql 。= Password =' 。 $ database-> mysqlPrep($ this-> password)。 ';
$ sql 。= WHERE ID = 。 $数据库 - > mysqlPrep($这 - > ID);
$ database-> query($ sql);
return ($ database-> affectedRows()== 1)?真假;
}







此更新函数中的sql脚本在我调用时发出错误在HTML中的功能。调试时我觉得奇怪的一件事是,如果我把脚本放在它工作的函数之外。所以我无法完全理解这里发生的事情。



Php版本= 5.4.3

MySql版本= 5.5.24



我将不胜感激任何帮助。谢谢你们

解决方案

数据库;


sql = UPDATE用户SET;


sql 。= 全名='

I am having the following error in MySql update code in php when I run the script.

Database query failed because 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 '=



This is code causing the error:

public function update(){
     global $database;
  
     $sql = "UPDATE users SET ";
     $sql .= "FullName='".$database->mysqlPrep($this->fullName)."',";
     $sql .= "RoleID='". $database->mysqlPrep($this->roleID) ."', ";
     $sql .= "UserName='". $database->mysqlPrep($this->userName) ."',";
     $sql .= "Email='". $database->mysqlPrep($this->email) ."', ";
             $sql .="Password='". $database->mysqlPrep($this->password)."' ";
     $sql .= "WHERE ID=". $database->mysqlPrep($this->id);
     $database->query($sql);
     return ($database->affectedRows() == 1) ? true:false;
 }




The sql script in this update function gives the error when I invoke the function in html. One thing i find strange when debugging is if i take the script outside the function it works. So i can't quite wrap my head round what's going on here.

Php version = 5.4.3
MySql version = 5.5.24

I would appreciate any help. Thanks guys

解决方案

database;


sql = "UPDATE users SET ";


sql .= "FullName='".


这篇关于使用php的Mysql更新代码出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆