Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert & update

Status
Not open for further replies.

Dreamboy2k3

Technical User
Apr 12, 2003
3
0
0
GB
Can anyone tell me why this won't work please!

I have an insert command that goes like this:

$sql="INSERT INTO news(Title, Body,) VALUES ( \"$title\", \"$body\" )";

Therefore I thought that the update command would be like this:

$sql="UPDATE news SET Title = $title WHERE News_ID = 1"

but it doesn't seem to work?

Could someone show me where I'm going wrong please!! Thanks!
 
It would be
[tt]$sql="UPDATE news SET Title = '$title' WHERE News_ID = 1";[/tt]
You need to surround all strings with quotes in SQL.

//Daniel
 
i also surround all field names with ` thats the key that also has a ~ on it, i noticed phpMyAdmin does this so i copied...

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
... which is only needed when you use a reserved word (such as use) for column/table names.

//Daniel
 
so why does the very much used phpMyAdmin do this?

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
ah :) ok that makes sense

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top