-7

how can i update the record from database?

$query = "UPDATE studentinfo SET firstname= '".$student['fname']."' and lastname='".$student['faname']."' and gender = 'Male' WHERE id = '".$student['id']."'"; 
8
  • 1
    An UPDATE statement seems like a reasonable way to start. Is something not working? Can you maybe provide some information about the problem? (Also, be aware that this code is wide open to SQL injection attacks.) Commented May 23, 2014 at 12:58
  • i want to update a student record in db but my query is not working properly. Commented May 23, 2014 at 12:59
  • 5
    Oh hi, my name is bob'; DROP TABLE studentinfo; --. Commented May 23, 2014 at 13:00
  • 3
    @phpisuber01 is trying to demonstrate that this code makes it very easy to delete the complete table, or do other evil things, using SQL injection. See How can I prevent SQL-injection in PHP? for more information. Commented May 23, 2014 at 13:02
  • 1
    Are you paying by the keystroke for your internet? You need to put more effort into your question. Commented May 23, 2014 at 13:19

3 Answers 3

2
UPDATE table SET column1 = 'value1', column2 = 'value2' 

Do not use AND to separate terms in the SET clause.

Sign up to request clarification or add additional context in comments.

Comments

1
$query = "UPDATE studentinfo SET firstname= '".$student['fname']."', lastname='".$student['faname']."', gender = 'Male' WHERE id = '".$student['id']."'"; 

2 Comments

i want to get id from auto increament.but not geting through $_get method
That's a matter for another question, feel free to make it and link to it, but ONLY if you make the question become better than this one. Read about how to post questions on stackoverflow, please.
1

AND is used in SQL for multiple-conditions.

To update multiple fields just separate them with a comma:

$query ="UPDATE studentinfo SET firstname = '$student['fname']', lastname = '$student['faname']', gender = 'Male' WHERE id = '$student['id']'"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.