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 01-13-2008, 04:28 PM   #1 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default Updating a database!?

Hi guys, I have a question for you :)

This has been really annoying me recently,

I am trying to update my database via a form which will be found in the ACP. I manage to display the original values in the forms and then when i click submit it says Forum CANNOT be updated.

I have a tried a few methods, my last attempt being here.

Can someone help me fix this or give me a version of an update form which will definitely work, please?

Gareth
SBB Alpha 2 (Powered by SBB)
Gareth is offline  
Reply With Quote
Old 01-13-2008, 05:16 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Hi Gareth,

Try changing your "Forum cannot be updated" error text to echo mysql_error() instead. That may give some clues as to why it isn't updating.

A handy trick when debugging these sorts of mysql problems is to do the following:

PHP Code:
$something mysql_query("your query here..") or die(mysql_error()); 
That will stop the script and show the mysql error message in the event that the query fails. Shouldn't be used in a live enviroment for it's handy for debugging :)

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-13-2008, 05:27 PM   #3 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

Aha!

It comes up with:

Quote:
ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( title, desc, cat, category ) VALUES ( Public, n/a, 1, 0 ) WHERE id='7'' at line 1
EDIT: It now says

Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='n/a' , cat='1' , category='0' ' at line 5
for

PHP Code:
 $update_forum mysql_query("
                                
                                                            UPDATE 
                                                                sbb_forums 
                                                            SET 
                                                                title='
$title' ,
                                                                desc='
$desc' ,
                                                                cat='
$cat' ,
                                                                category='
$category'                                                        
                                                            WHERE
                                                                id='
$id'"
                                                                
                                        or die(
mysql_error());            
                         
                            if (
$update_forum) {
                                echo 
'<div class="sub_cat_content">';
                                echo 
'Forum Updated';
                                echo 
'</div>';
                            } else {
                                echo 
'<div class="sub_cat_content">';
                                echo 
'Forum <b>CANNOT BE</b> Updated';
                                echo 
'</div>';
                                } 
Gareth is offline  
Reply With Quote
Old 01-13-2008, 05:30 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You'll need to format the SQL query correctly. At the moment you have:
... VALUES ( Public, n/a, 1, 0 ) but you need it to look like: ... VALUES ( 'Public', 'n/a', 1, 0 )
Salathe is offline  
Reply With Quote
Old 01-13-2008, 05:36 PM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Ahh, then the problem is with your update query syntax :)

Try changing it to:

PHP Code:
"UPDATE sbb_forums SET title = '$title', $desc = '$desc', cat = '$cat', category = '$category' WHERE id = '$id'" 
That should do the trick.

More info on the SQL Update syntax here: MySQL AB :: MySQL 5.0 Reference Manual :: 11.2.10 UPDATE Syntax

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-13-2008, 05:47 PM   #6 (permalink)
The Contributor
 
Join Date: Dec 2007
Location: Florida
Posts: 73
Thanks: 12
danielneri is on a distinguished road
Default

Also, be careful using "desc", it's a mysql keyword!!
Send a message via AIM to danielneri
danielneri is offline  
Reply With Quote
Old 01-13-2008, 05:52 PM   #7 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Quote:
Originally Posted by Gareth View Post
EDIT: It now says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='n/a' , cat='1' , category='0' ' at line 5"
What daniel said :) As "desc" is a reserved SQL word you'll run into problems using it. I would recommend changing it to something else but if you really want to use it, wrap it in backticks (` - next to the 1 key :)).

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-13-2008, 05:56 PM   #8 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

You guys are great! Thank you so much :)

I need to remember about desc, will change it sometime :P
Gareth is offline  
Reply With Quote
Old 01-13-2008, 05:57 PM   #9 (permalink)
The Contributor
 
Join Date: Dec 2007
Location: Florida
Posts: 73
Thanks: 12
danielneri is on a distinguished road
Default

Yeah I've run into that terrible desc error so many times and never knew what it was!

Annoying little thing isn't it... haha
Send a message via AIM to danielneri
danielneri is offline  
Reply With Quote
Old 01-13-2008, 06:22 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default


Offtopic

There are over 200 reserved words in MySQL (the link points to MySQL 6.0) which you'll want to avoid using as table names, column names, etc. Thankfully if you stick to the convention of using descriptive names then generally you won't hit too many problems. If in doubt, always `quote` the words.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
codefreek (01-13-2008)
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


All times are GMT. The time now is 06:58 AM.

 
     

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