UpcomingPhpDev Posted August 2, 2008 Share Posted August 2, 2008 Hi again phpfreaks. I have a slight problem that I have been testing through trial and error but I cant seem to get it, Ive tried a few searches with google too but the results are differnt to what im trying to achieve. Basically I have a textarea field which ive stored in a certain variable and have passed it to the nl2br function. Then I have used a foreach loop to echo each single line out whilst adding a few characters before and after each line. The problem im having is when I pass the variable to MySQL to store it, it only saves the last line on the textarea variable. Here is my code.(I havnt included all such as the textarea,connection to db, selected db etc) $BrokenLines = $_POST['brokenlines']; $BrokenLines = nl2br($BrokenLines); if(!empty($BrokenLines)) { echo "<div id='array'>"; $Array = explode("<br />", $BrokenLines); foreach($Array as $Key => $Value) { $SQLBrokenLines = "[9s28d\"$Value\"]".$Value."[d82s9]<br />"; echo $SQLNormalLinks; } echo "</div>"; } $Sql = "INSERT INTO TextArea (BrokenLines) VALUES ('$BrokenLines')"; The problem im having is that it will only save the last line from the textarea into the mysql table. Thanks in advance guys. Il continue to test some stuff myself. Link to comment https://forums.phpfreaks.com/topic/117879-storeing-looped-array-data-frm-php-to-mysql/ Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 I don't see $brokenlines being what u need for the query. You need a comma separated list for the query as written. Link to comment https://forums.phpfreaks.com/topic/117879-storeing-looped-array-data-frm-php-to-mysql/#findComment-606340 Share on other sites More sharing options...
UpcomingPhpDev Posted August 2, 2008 Author Share Posted August 2, 2008 I don't see $brokenlines being what u need for the query. You need a comma separated list for the query as written. Sorry, I renamed 1 of the variables so you guys could read the script easier and forgot to change that part. It should be $BrokenLines = $_POST['brokenlines']; $BrokenLines = nl2br($BrokenLines); if(!empty($BrokenLines)) { echo "<div id='array'>"; $Array = explode("<br />", $BrokenLines); foreach($Array as $Key => $Value) { $SQLBrokenLines = "[9s28d\"$Value\"]".$Value."[d82s9]<br />"; echo $SQLBrokenLines; } echo "</div>"; } $Sql = "INSERT INTO TextArea (BrokenLines) VALUES ('$SQLBrokenLines')"; Link to comment https://forums.phpfreaks.com/topic/117879-storeing-looped-array-data-frm-php-to-mysql/#findComment-606344 Share on other sites More sharing options...
JasonLewis Posted August 3, 2008 Share Posted August 3, 2008 Change this line: $SQLBrokenLines = "[9s28d\"$Value\"]".$Value."[d82s9]<br />"; To this: $SQLBrokenLines .= "[9s28d\"$Value\"]".$Value."[d82s9]<br />"; That way it'll add the next line on and the next line and so on. Link to comment https://forums.phpfreaks.com/topic/117879-storeing-looped-array-data-frm-php-to-mysql/#findComment-606458 Share on other sites More sharing options...
UpcomingPhpDev Posted August 3, 2008 Author Share Posted August 3, 2008 Such a easy answer, Thanks for the help. It worked. Admin/Mod can put resolved here. Link to comment https://forums.phpfreaks.com/topic/117879-storeing-looped-array-data-frm-php-to-mysql/#findComment-606688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.