Hello All!
I'm trying to write an SQL query string that updates a row in a table, but I can't find the right info on it.
The variables I have are:
$page_title, $content1 and $content2.
The table is called "pages" and It contains the fields, "id", "page_title", "content1" and "content2"
So the string I want is something like...
"Select all from pages where the page_title is equal to "$page_title" and update the values with "$content1" and "$content1""
- so "page_title" and the "id" are no updated.
Are you all mad at me because this isn't technically php? I hope not.
Many thanks for any help!
-- wibblywobbly.
Quick SQL query...
Moderator: General Moderators
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Quick SQL query...
wibblywobbly wrote:"Select all from pages where the page_title is equal to "$page_title" and update the values with "$content1" and "$content1""
Code: Select all
$page_title = mysqli_real_escape_string($page_title);
$content1 = mysqli_real_escape_string($content1);
$content2 = mysqli_real_escape_string($content2);
"UPDATE `pages` SET `content1`='$content1', `content2`='$content2' WHERE `page_title`='$page_title';"Re: Quick SQL query...
basically the sentence that you want is something like this (your variable should be "cleaned" first of course):wibblywobbly wrote:The variables I have are:
$page_title, $content1 and $content2.
The table is called "pages" and It contains the fields, "id", "page_title", "content1" and "content2"
So the string I want is something like...
"Select all from pages where the page_title is equal to "$page_title" and update the values with "$content1" and "$content1""
- so "page_title" and the "id" are no updated.
Code: Select all
UPDATE pages
SET content1 = $content1,
content2 = $content2
WHERE page_title = $page_title
Code: Select all
UPDATE pages
SET content1 = $content1,
content2 = $content2
WHERE id = $id
-
wibblywobbly
- Forum Newbie
- Posts: 17
- Joined: Mon Oct 19, 2009 10:11 am
Re: Quick SQL query...
That's so helpful.
Thank you so much. People on here are always quick and very thoughtful. Many thanks.
It was the latter option I was interested in. All the pages with the same title will be changed.
Thanks,
-- wibblywobbly.
Thank you so much. People on here are always quick and very thoughtful. Many thanks.
It was the latter option I was interested in. All the pages with the same title will be changed.
Thanks,
-- wibblywobbly.