PHP string variable in WHERE clause MySQL. Ask Question. Up vote 9 down vote favorite. Browse other questions tagged php mysql sql select or ask your own question. HTML CSS JAVASCRIPT SQL PHP BOOTSTRAP HOW TO JQUERY W3.CSS PYTHON XML MORE. The SQL UPDATE Statement. The UPDATE statement is used to modify the existing records in a table. The following SQL statement will update the contactname to 'Juan' for all records where country is 'Mexico'.
Active4 years, 10 months ago
I'm working on a website that is supposed to pass data from a form on the page and use PHP to update a students table on the server. The condition I'm trying to work on now is Modifying data, so it should be able to update data on the server, but it does not..
Any help or advice you guys can offer will be greatly appreciated. Thanks in advance.
The SQL WHERE clause is used to restrict the number of rows affected by a SELECT, UPDATE or DELETE query. The WHERE clause can be used in conjunction with logical operators such as AND and OR, comparison operators such as,= etc.
Here is my code:
Php Mysql Update Where
I keep getting this error:
Database Found! Problem updating record. MySQL 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 ' lastName = , WHERE Stud' at line 2
P.S: I already have the students table created with some data. I can access the table and modify it using the terminal and an identical mysql query like the one above but still no luck. Also, I have changed the host address, database name, and password in my code on purpose (just in case someone asks).
Ouput of
echo $query
A fix for incorrect clipping of bitmaps in some PS files resulting in a 'white patch' on the background. Hp 2250 printer drivers. Improved slow printing in draft mode for PS jobs. Improved differentiation between PS & PCL5 jobs.
sqluser
4,55277 gold badges2626 silver badges4242 bronze badges
BizzyBeeBizzyBee
3 Answers
Obvious, you have a syntax error (an extra
, before WHERE ) in your UPDATE statement as pointed below
EDIT:
Check whether your form element really named as Rahul
firstName and lastName ? check the spelling. I doubt the names are different than what you are referring in code.
65.1k1212 gold badges4848 silver badges8787 bronze badges
You wrote it yourself:MySQL 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 ' lastName = , WHERE Stud' at line 2
Print the query string, it's not what you expect it to be.
P.s.You should probably escape your inputs in order to avoid sql-injectiion.
Also, please note you should not use mysql_ functions anymore.read the warning in the following page:http://php.net/manual/en/function.mysql-query.php
iLotiLot
Once try this..
$query = 'UPDATE students SET
firstName ='.$_POST['firstName'].',lastName ='.$_POST['lastName'].' WHERE StudentID = '.$_POST['StudentID'].'';
Php Mysql Where ClauseVivek SinghPhp Mysql Update Where Clause Sql ServerVivek SinghPhp Mysql Update Record
2,36411 gold badge99 silver badges2121 bronze badges
Php Mysql Update Where Clause Sql UpdateNot the answer you're looking for? Browse other questions tagged phpmysqlsql-updateupdate-statement or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |