Post by iteration » Fri Dec 15, 2006 5:57 am

Updating a password in the administration panel causes the following SQL error:

Error: 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 'where user_id = '5'' at line 1
Error No: 1064
insert into user set password = 'ba352acae7a4b3532fb4f9ca26f79bbd' where user_id = '5'

This is caused by the following line in admin/plugin/user.php (50, 51, ...):

      if (@$_POST['password']) {
      $sql = "insert into user set password = '?' where user_id = '?'";
        $database->query($database->safe_query($sql, md5($_POST['password']), $_GET['user_id']));
      }

The generated SQL query should be:

$sql = "UPDATE user SET password = '?' WHERE user_id='?'";

And if you use prepared statements for the MySQL database, it is not necessary to use ' ' around the question marks.

I certainly do propose a clearer SQL syntax and a transparent seperation of SQL code and PHP code.

Best Regards,

Anders (iteration)
aj AT itersys DOT dk
Last edited by iteration on Fri Dec 15, 2006 5:59 am, edited 1 time in total.

Newbie

Posts

Joined
Fri Dec 15, 2006 2:39 am

Post by Daniel » Fri Dec 15, 2006 10:53 am

I have Just fixed this problem on the dev server.

Please explain more about:

I certainly do propose a clearer SQL syntax and a transparent seperation of SQL code and PHP code.

I thought I had done this with whats in the code already.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by chomp » Tue Feb 27, 2007 2:52 am

maybe he's suggesting SELECT something FROM rather than select something from. Also the code is all on one line, perhaps break it across multiple lines. And as for the seperation comment... who knows, maybe he means using a sql class which dynamically builds the statement, ie $database->query("*","table","WHERE id=null").

New member

Posts

Joined
Sat Feb 24, 2007 7:19 am

Post by Mark Dyer » Fri Jun 01, 2007 1:49 pm

The idea of using less code is better. For example with out queries I do the following

dbInsert(TABLE_NAME,$sql);
dbUpdate(TABLE_NAME,$sql,"field = '".$value."'");
dbDelete(TABLE_NAME,"field = '".$value."'");
dbSelect($sql_query,$optional); wjhere is $optional is not false it gets row rather then rows

The $sql is an arrary with the fields being the key and the values being the values. this allows the same array created for an insert as an update ie.

if($id){
dbUpdate(TABLE_NAME,$sql,"field = '".$id."'");
}else{
$id = dbInsert(TABLE_NAME,$sql);
}

Just my comments.. Saves so much time and I never have any sql errors as it's pretty much automated.

User avatar
New member

Posts

Joined
Thu May 31, 2007 10:07 pm
Who is online

Users browsing this forum: No registered users and 1 guest