h8me Posted April 19, 2010 Share Posted April 19, 2010 Hi, I want to add some text into a databasefield, but the text is from 6 different textboxes. I tried to make a script for this but it only adds the last textbox value. Example: <INPUT TYPE="text" value="textbox1text" NAME="text1"> <INPUT TYPE="text" value="textbox2text" NAME="text2"> <INPUT TYPE="text" value="textbox3text" NAME="text3"> <INPUT TYPE="text" value="textbox4text" NAME="text4"> <INPUT TYPE="text" value="textbox5text" NAME="text5"> <INPUT TYPE="text" value="textbox6text" NAME="text6"> $text1 = $_POST['text1']; $text2 = $_POST['text2']; $text3 = $_POST['text3']; $text4 = $_POST['text4']; $text5 = $_POST['text5']; $text6 = $_POST['text6']; $combined = array($text1,$text2,$text3,$text4,$text5,$text6); (I know this is the problem, I don't know the right code for doing this) $query = "UPDATE user_info SET stats1='$combined' WHERE id='$char_id_sub' AND owner='$session_user'"; Is this even possible to do? and/or is it a better way to do it? Just to clear things up, ALL information from the textboxes is going in to the same databasefield. Link to comment https://forums.phpfreaks.com/topic/198985-phpmysql-help/ Share on other sites More sharing options...
Sergey Popov Posted April 19, 2010 Share Posted April 19, 2010 Use serialize/unserialize functions to combine array into a string. Here is how you save value to database: $combined = serialize(array($text1,$text2,$text3,$text4,$text5,$text6)); And when you need to read 6 fields from the database, you need to apply unserialize() function: $arr = unserialize($combined); Link to comment https://forums.phpfreaks.com/topic/198985-phpmysql-help/#findComment-1044479 Share on other sites More sharing options...
h8me Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks for reply! Adding information to the database works fine now, but not so fine when I pull the info out of the database, then I only get the word "Array" Output using echo : a:6:{i:0;s:5:"test1";i:1;s:5:"test2";i:2;s:5:"test3";i:3;s:5:"test4";i:4;s:5:"test5";i:5;s:5:"test6";} Output with unserialize : Array Any ideas on how to fix this? Link to comment https://forums.phpfreaks.com/topic/198985-phpmysql-help/#findComment-1044495 Share on other sites More sharing options...
Sergey Popov Posted April 19, 2010 Share Posted April 19, 2010 Sure The serialize() function take array and turn it into string... while unserialize() take string and create an array from it. So once you unserialized your string, you have an array. To access your 6 values use array index: $arr = unserialize($combined); echo $arr[0]; // your 1st string echo $arr[1]; echo $arr[2]; echo $arr[3]; echo $arr[4]; echo $arr[5]; // your 6th string Link to comment https://forums.phpfreaks.com/topic/198985-phpmysql-help/#findComment-1044496 Share on other sites More sharing options...
h8me Posted April 19, 2010 Author Share Posted April 19, 2010 ahh, of course, I didn't think of that. But thank you very much!! Been working on this for a long time now! :) Link to comment https://forums.phpfreaks.com/topic/198985-phpmysql-help/#findComment-1044497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.