Jump to content

Function change from newuser to updateuser


genista

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.