genista Posted September 4, 2006 Share Posted September 4, 2006 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 https://forums.phpfreaks.com/topic/19667-function-change-from-newuser-to-updateuser/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 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 https://forums.phpfreaks.com/topic/19667-function-change-from-newuser-to-updateuser/#findComment-85707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.