TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-08-2008, 09:23 PM   #1 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default Updating MySQL Row

I have 5 fields in total that store information into my database. Here is one of them:

PHP Code:
if(!empty($_POST['title']))
{
    
$title mysql_real_escape_string(ucfirst($_POST['title']));
    
$db_title mysql_query("UPDATE mainsettings SET WebsiteTitle='$title' WHERE WebsiteTitle='WebsiteTitle'");    

As you can tell, when the field in my html is filled it is updated in my database.

The problem, if I use:
PHP Code:
"UPDATE mainsettings SET WebsiteTitle='$title' WHERE WebsiteTitle='WebsiteTitle'" 
My information is not updated. But, if I use:
PHP Code:
"UPDATE mainsettings SET WebsiteTitle='$title'" 
It works perfectly. The problem is that it updates all columns, although I only have one table and row to worry about in this part of my script so it doesn't really matter. I'm just trying to figure it out for future purposes.
9three is offline  
Reply With Quote
Old 12-09-2008, 12:28 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Are you sure that the field in the column you are looking for is the text 'Website Title'? Also, do not update rows like that, use the primary key to identify the row you wish to modify. What happens if two rows have the same title?

If your database only has (and will ever need) one row, you probably don't need to be using a database.
__________________

Village Idiot is offline  
Reply With Quote
Old 12-09-2008, 02:25 AM   #3 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default

Well the field column is called WebsiteTitle and in the WebsiteTitle it will contain the title of the page.

Are you saying that it should be something like this:

PHP Code:
"UPDATE mainsettings SET WebsiteTitle='$title' WHERE PrimaryKey='WebsiteTitle'" 
9three is offline  
Reply With Quote
Old 12-09-2008, 03:26 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

No, a primary key is a unique integer on each row that identifies the row from anything else.

I'd read some more on database design, that would probably make things make lot more sense.
__________________

Village Idiot is offline  
Reply With Quote
Old 12-09-2008, 10:26 AM   #5 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

yes, its greatly recommended that in updating the rows in mysql databases or any databases, you should be using a primary key.
Quote:
Originally Posted by Village Idiot View Post
No, a primary key is a unique integer on each row that identifies the row from anything else.
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 12-09-2008, 11:52 AM   #6 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default

oh yea I get you now.
9three is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a MySQL class Andrew General 12 07-14-2009 03:49 PM
having trouble updating with mysql sarmenhb Absolute Beginners 7 11-18-2008 07:49 AM
MySQL Sell Up Alan @ CIT The Lounge 12 01-17-2008 05:46 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM
Notepage like application to open large MySQL files Wildhoney General 6 12-07-2007 02:18 PM


All times are GMT. The time now is 12:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design