depojones Posted September 30, 2010 Share Posted September 30, 2010 Thanks for reading my post, Can someone point me to the right direction here; Am trying to insert a record in a text area field into PHP/MYSQl. This time around, I am reading what the user entered into the textarea before inserting. Take a look at this: TEXTAREA -> row 1: BOY row 2: GIRL Can I make it two rows in my database as opposed to one? I don't have a problem inserting, just how to insert as multiple if there are two rows. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/214860-inserting-into-phpmysql/ Share on other sites More sharing options...
jcbones Posted September 30, 2010 Share Posted September 30, 2010 $data = $_POST['textarea']; $rows = explode("\n",$data); $row_1 = $rows[0]; $row_2 = $rows[1]; //etc... Quote Link to comment https://forums.phpfreaks.com/topic/214860-inserting-into-phpmysql/#findComment-1117748 Share on other sites More sharing options...
depojones Posted September 30, 2010 Author Share Posted September 30, 2010 Thanks for your reply, I got your logic here. I only specified 2 as an example. what if the row is 50 do i have to assign 50 rows in my script or what? eg, $row[0] $row[1] $row[2] $row[3] $row[n] ... Quote Link to comment https://forums.phpfreaks.com/topic/214860-inserting-into-phpmysql/#findComment-1117749 Share on other sites More sharing options...
Pawn Posted September 30, 2010 Share Posted September 30, 2010 $data = $_POST['textarea']; $rows = explode("\n",$data); foreach($rows as $val) { $sql = "INSERT INTO table (field) VALUES ('".$val."')"; if(!$query = mysql_query($sql)) { echo "Error!"; die; } } Quote Link to comment https://forums.phpfreaks.com/topic/214860-inserting-into-phpmysql/#findComment-1117770 Share on other sites More sharing options...
depojones Posted October 1, 2010 Author Share Posted October 1, 2010 Thank you it worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/214860-inserting-into-phpmysql/#findComment-1117870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.