Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have done a little bit of coding and withdrawed this problem:
Java
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 `Username` = ?' at line 1


I don't understand whats wrong with this prepare:
SQL
require 'mysqli_data/mysqli_connection.php';
        $qString = $gConnection->prepare("UPDATE `accounts` SET ? = ? WHERE `Username` = ?");
        printf($gConnection->error);
        $qString->bind_param('sss', $key, $data, $gConnection->real_escape_string($user));
        $qString->execute();
        $qString->close();
        return true;


Thanks for any help!
Posted
Comments
Mohibur Rashid 8-May-13 1:16am    
what is ? = ?
NextGenDeveloper 8-May-13 3:58am    
Read up on the prepare statment
http://php.net/manual/en/mysqli.prepare.php
Bernhard Hiller 8-May-13 4:21am    
what do you want to achieve? Change a username? Then you must also provide the previous username or userid. And of course, you need some more basics for SQL:
UPDATE `MYTABLE`
SET `MYCOLUMN`=`NEWVALUE`
WHERE `OTHERCOLUMN`=`OTHERVALUE`
NextGenDeveloper 8-May-13 5:58am    
Its a general function called UpdateUserInfo($user, $key, $data) at my side.
I'm doing it regulery so I can't find the problem.
'UPDATE `accounts` SET ? = ? WHERE `Username` = ?' is like 'UPDATE `accounts` SET Username = RANDOM_RANDOM WHERE `Username` = NON_RANDOM'

Its the same thing, but with a statement, and I can't figure out why it dosen't work.

1 solution

Fixed, just implemented some PHP into it:
$qString = $gConnection->prepare("UPDATE `accounts` SET ".$key." = ? WHERE `Username` = ?");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900