TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Save inputs (text, textarea) into database, with same names? (http://www.talkphp.com/absolute-beginners/4877-save-inputs-text-textarea-into-database-same-names.html)

Hempsworth 08-19-2009 03:51 PM

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.

hello-world 08-19-2009 09:15 PM

Where are the comments ?
I think in line 14 the id could be AUTO_INCREMENT and unique/primary.

Hempsworth 08-19-2009 11:48 PM

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.

Tanax 08-20-2009 05:48 AM

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!! :-D :-D

Hempsworth 08-20-2009 02:29 PM

I've fixed the typo, but its not really the problem :P

rguy84 08-21-2009 09:26 PM

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...


All times are GMT. The time now is 03:59 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0