Jump to content

Archived

This topic is now archived and is closed to further replies.

genista

Function change from newuser to updateuser

Recommended Posts

Hi all,

I have a function that helps to create a new user, the query looks like so:


[code=php:0]
$query="INSERT INTO users (username, password, etc, etc)
[/code]

Now I need a function that updates the user details, so when I call update user it updates the database with all of the vlaues. The problem I have is that when I run this updateuser function in any of my scripta I get:

"Died inserting login info into db. Error returned if any: 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 '(username, password"


Off the following change:


[code=php:0]
$query="UPDATE users (username, password, etc, etc where username=$username)
[/code]


$username is defined in the script as I have already run a query to select * from the user table.

ANy ideas? (I hope it is a simple one)


G

Share this post


Link to post
Share on other sites
Use this:
[code]$query="UPDATE users (`username`, `password`, `etc, etc`) where `username`='$username'";[/code]
As the SQL query. password is a SQL keyword so MySQL is getting confused and so result in the above error. You should add backticks around the column names in your query, like I have done. This is prevent SQL from getting confused and is good practice to add backticks around column/table names in your SQL queries

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.