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 08-19-2009, 03:51 PM   #1 (permalink)
The Visitor
 
Hempsworth's Avatar
 
Join Date: Jul 2008
Location: Hereford, UK
Posts: 4
Thanks: 0
Hempsworth is on a distinguished road
Default Save inputs (text, textarea) into database, with same names?

This is my first PHP script, so please bear with me! :)

I have a table, with each row representing a row from a database table. Each of the fields in the table are editable, so when the user edits a couple of them and hits 'Save', the appropriate ones need to be saved.

As you can see from this pastebin snippet, users can create new rows and save them.

http://wordpress.pastebin.com/d1fd7e116

I need to be able to save the appropriate items into the database; I have commented in where the problem lies!

At the moment, it's just saving the last outputted row.
Send a message via MSN to Hempsworth Send a message via Skype™ to Hempsworth
Hempsworth is offline  
Reply With Quote
Old 08-19-2009, 09:15 PM   #2 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Where are the comments ?
I think in line 14 the id could be AUTO_INCREMENT and unique/primary.
hello-world is offline  
Reply With Quote
Old 08-19-2009, 11:48 PM   #3 (permalink)
The Visitor
 
Hempsworth's Avatar
 
Join Date: Jul 2008
Location: Hereford, UK
Posts: 4
Thanks: 0
Hempsworth is on a distinguished road
Default

Sorry, I've updated the pastebin: http://wordpress.pastebin.com/m4e5721ac

My problem is with updating the existing rows which are outputted using the 'foreach' on line 25 onwards.
Send a message via MSN to Hempsworth Send a message via Skype™ to Hempsworth
Hempsworth is offline  
Reply With Quote
Old 08-20-2009, 05:48 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Line 10: $field2 = $_POST[row_field2'];

You forgot to put row_field2 between ''. You only put 1 ' in the end.
$field2 = $_POST['row_field2'];

Edit: 1000 posts!!
__________________
Tanax is offline  
Reply With Quote
Old 08-20-2009, 02:29 PM   #5 (permalink)
The Visitor
 
Hempsworth's Avatar
 
Join Date: Jul 2008
Location: Hereford, UK
Posts: 4
Thanks: 0
Hempsworth is on a distinguished road
Default

I've fixed the typo, but its not really the problem :P
Send a message via MSN to Hempsworth Send a message via Skype™ to Hempsworth
Hempsworth is offline  
Reply With Quote
Old 08-21-2009, 09:26 PM   #6 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
rguy84 is on a distinguished road
Default

Not sure but try changing:
PHP Code:
 $wpdb->query("INSERT INTO wp_example (id, field1, field2) VALUES (0, '$field1', '$field2')"); 
to
PHP Code:
 $wpdb->query("INSERT INTO wp_example (field1, field2) VALUES ('$field1', '$field2')"); 
Your original sets ID = 0 every time...
__________________
Ryan | Blog | Twitter
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 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
How to use the Singleton design pattern Karl Advanced PHP Programming 27 10-22-2012 08:16 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Adding Images to a database from a folder Rendair Advanced PHP Programming 3 01-13-2008 07:40 PM
Database export to text file... d4v1d Absolute Beginners 5 01-09-2008 04:30 PM
PDF Creation - Help! Sam Granger General 7 10-31-2007 11:32 AM


All times are GMT. The time now is 12:13 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