sql query

A

Anonymous

Guest
Hi there. I am new to SQL and i eed to find out how to update a record. I have record ID's so i want to update the record according to the id

ie the record currently

record_id: 1
first_name: Digitalbloke
last_name: Smith

change to
record_id: 1
first_name: John
last_name: Smith

But sometimes i may change the last name so it needs to read in both values first and last name.

also why do i get the query failed error for
Code:
$dbuser = "yyy";
$dbpass = "xxx";
$dbserver = "ppp.com";
$dbdb = "db";

$chandle = mysql_connect($dbserver, $dbuser, $dbpass) 
    or die("Connection Failure to Database");
mysql_select_db($dbdb, $chandle) or die ($dbdb . " Database not found. " . $dbdb);
$sql = "DELETE FROM 'page_data' WHERE 'id' = '" . $id . "'";
mysql_db_query($dbdb, $sql) or die("Failed Query of " . $sql);

Thanks in advance for your help!
 
digitalbloke said:
Hi there. I am new to SQL and i eed to find out how to update a record. I have record ID's so i want to update the record according to the id

ie the record currently

record_id: 1
first_name: Digitalbloke
last_name: Smith

change to
record_id: 1
first_name: John
last_name: Smith

But sometimes i may change the last name so it needs to read in both values first and last name.

To change a record, use UPDATE, e.g.:

Code:
UPDATE table_name SET first_name = 'John' WHERE record_id = 1;

If you want to change more than one field, just separated SET statements with commas:

Code:
UPDATE table_name SET first_name = 'John', SET last_name = 'Smith' WHERE record_id = 1;

digitalbloke said:
also why do i get the query failed error for
Code:
$sql = "DELETE FROM 'page_data' WHERE 'id' = '" . $id . "'";

Table and column names shouldn't have quotation marks around them -- only string values need quotation marks:

Code:
$sql = "DELETE FROM page_datea WHERE id = '" . $id . "'";

(Assuming your id values are just integers, you can skip the single-quotes around those, too.)
 
I would also recommed to get REALLY familiar with SQL since it is one of those things that you will use on a daily basis, and it is used so widely ->MySQL, Access, MS SQL, Oracle........

http://www.baycongroup.com/tocsql.htm

:wink:
 
Back
Top