Jump to content
xisto Community
Sign in to follow this  
tariqrf

Php New Line Problem how do i get the linebreak to work???

Recommended Posts

well, i have been running head over heels with this problem... i have been working on an online ordering system in flash which submits files to php, and which inturn puts it in the database.. the problem is that i dont have the newline break thing working.... i mean in flash, the "newline" in the actionscript solves it.. but when it is in the database... all of the linebreaks are gone and a continous string of code is created.... hmm... something like this.:1 x Sweet lime1 x Lime-mint cooler45 x Grape juicewhen it was supposed to be:1 x Sweet lime1 x Lime-mint cooler45 x Grape juice... i triend nl2br... but it does not work,,, or i have the code wrong or something..pls check if this code is right or not:PHP Coding:<?include ('Include.inc');mysql_connect($DBhost,$DBuser,$DBpass);@mysql_select_db("$DBName");$cart = nl2br($cartsend);$query = "INSERT INTO orders (orderid, date, name, tel, address, comments, cart) VALUES ('$orderid', DATE_SUB(now(), INTERVAL 2 HOUR) , '$name', '$tel', '$address', '$comments', '$cart')";$result = mysql_query($query);print "&status=DONE.";?>and i have used the following code for the retreival:<?$res = mysql_query("select * from orders");while($row = mysql_fetch_array($res)){ print "<tr><td valign=top>" . $row['orderid'] . "</td><td>" . $row['name'] . "</td><td>" . $row['tel'] . "</td><td>" . $row['address'] . "</td><td>" . $row['cart'] . "</td><td>" . $row['comments'] . "</td><td><a href=\"delete.php?id=" . $row['id'] . "\">delete</a></td></tr>";}?>if i can somehow get those linebreaks to turn into a "<br>" in the mysql databse, then my problem could be fixed,Please help,Tariq

Share this post


Link to post
Share on other sites

i tried this too:<?include ('Include.inc');mysql_connect($DBhost,$DBuser,$DBpass);@mysql_select_db("$DBName");$cartsend = str_replace("\r", "<br>", "$cartsend");$query = "INSERT INTO orders (orderid, date, name, tel, address, comments, cart) VALUES ('$orderid', DATE_SUB(now(), INTERVAL 2 HOUR) , '$name', '$tel', '$address', '$comments', '$cartsend')";$result = mysql_query($query);print "&status=DONE.";?>but no avail.. damn.. is this buggin me to death

Share this post


Link to post
Share on other sites

there is a problem here, i tried everything, from line breaks to page breaks, i am using flash to process the variables and then send it here, this is for an online shopping cart, the data is sent from a flash movie into a php script(above posted).. so am i supposed to do some php code so that mysql detects the linebreaks given by flash????i use the following code for sending variables from flash to mySQL, pls let me know if there is somthing wrong with that:status = "LOADING";loadVariablesNum("http://forums.xisto.com/no_longer_exists/, 0);gotoAndPlay("loop3");

Share this post


Link to post
Share on other sites

ok, i fixed the problem, i used the split and join to change the \n to (br) and then another small change in the retreival script to change the (br) to <br> and voila it works!!!these are what i did to the script:The submit code:<?include ('Include.inc');mysql_connect($DBhost,$DBuser,$DBpass);@mysql_select_db("$DBName");$cartsend = str_replace("\r", "\n", "$cartsend");$query = "INSERT INTO orders (orderid, date, name, tel, address, comments, cart) VALUES ('$orderid', DATE_SUB(now(), INTERVAL 2 HOUR) , '$name', '$tel', '$address', '$comments', '$cartsend')";$result = mysql_query($query);print "&status=DONE.";?>the retreival code: (HTML and PHP)<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title><style type="text/css"><!--.style1 { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #999999;}.style5 { font-size: 10px; color: #999999;}body { background-color: #FFFFFF; margin-top: 0px;}--></style></head><body><?include ('Include.inc');mysql_connect($DBhost,$DBuser,$DBpass);@mysql_select_db("$DBName");?><table width="980" border="1" cellspacing="0" bordercolor="#999999"><tr><th width="71" bgcolor="#FFFFFF"><span class="style1">orderid</span></th><th width="113" bgcolor="#f8f8f8"><span class="style1">name</span></th><th width="94" bgcolor="#FFFFFF"><span class="style1">tel</span></th><th width="177" bgcolor="#F8f8f8"><span class="style1">address</span></th><th width="230" bgcolor="#FFFFFF"><span class="style1">cart</span></th><th width="133" bgcolor="#f8f8f8"><span class="style1">comments</span></th><th width="65" bgcolor="#FFFFFF"><span class="style1">bill value*</span></th><th width="63" bgcolor="#f8f8f8"></th></tr><?$res = mysql_query("select * from orders");while($row = mysql_fetch_array($res)){ $cart = str_replace("(br)", "<br>", $row['cart'] );$address = str_replace("(br)", "<br>", $row['address'] );print "<tr><td valign=top>" . $row['orderid'] . "</td><td valign=top>" . $row['name'] . "</td><td valign=top>" . $row['tel'] . "</td><td valign=top>" . $address . "</td><td valign=top>" . $cart . "</td><td valign=top>" . $row['comments'] . "</td><td valign=top>" . $row['bill'] . "</td><td><a href=\"delete.php?id=" . $row['id'] . "\">delete</a></td></tr>";}?></table></body></html>now hopefully, no one else would stumble accross such a problem!cheers,Tariq

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.