Use of variables in a MySQL Update Query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Taxon
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2008 9:58 pm

Use of variables in a MySQL Update Query

Post by Taxon »

This works:

$sql = 'UPDATE Requests SET requested_date=\'2007-01-01\' WHERE request_number=\'0\'';

However, I am have not been able to come up with the proper syntax for replacing the constants in the query with variables.

The variables are $requested_date and $request_number.

What is the correct syntax for using those variables in the Update query?

Thanks,

Roger
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Use of variables in a MySQL Update Query

Post by jaoudestudios »

You need to read up on basic php! Otherwise you will not get very far.

However, the solution is...

$sql = "UPDATE Requests SET requested_date='".$requested_date."' WHERE request_number='".$request_number."'";

Eddie
Taxon
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2008 9:58 pm

Re: Use of variables in a MySQL Update Query

Post by Taxon »

Thanks, Eddie. :oops:
Post Reply