squiblo Posted January 22, 2010 Share Posted January 22, 2010 The code below is supposed to put the variable $about_me in a textarea by using javascript but i have to change "<br />" to "\n" when it goes into the textarea tags i am getting my logic all wrong trying to do this, and i think i have things in the wrong places. www.squiblo.com/test.php <html> <body> <?php $about_me = "liam<br /><br />!!!!<br />woooo"; ?> <?php $about_me = str_replace('<br />', '\n', $about_me); ?> <script type="text/javascript"> function toggle_visibility(id) { var div = document.getElementById(id); var text = document.getElementById("about_me_text"); if(div.style.display == 'block' ) { div.style.display = 'none'; text.innerHTML = "<?php $about_me = str_replace('\n', '<br />', $about_me); ?><?php $about_me = str_replace('<br>', '<br />', $about_me); ?><?php echo $about_me; ?>"; } else { div.style.display = 'block'; text.innerHTML = "<?php $about_me = str_replace('<br />', '\n', $about_me); ?><?php $about_me = str_replace('<br />', '\n', $about_me); ?><form action='' method='POST'><textarea cols='23' rows='6' name='textarea_about' id='textarea_about' style='font-family:arial;font-size:13px;overflow:hidden'><?php echo $about_me;?></textarea><br><input type='submit' name='submit_about' value='Save'> <input type='button' name='cancel_about' value='Cancel' onClick=\"window.location.href='#'\"></form>"; } } </script> <a href='#' onclick="toggle_visibility('bob');"><font color='CornflowerBlue'>Edit</font></a> <div id='about_me_test'> <?php echo $about_me; ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/ Share on other sites More sharing options...
squiblo Posted January 22, 2010 Author Share Posted January 22, 2010 ok this is the strangest thing ive ever seen.... this following code works.... <?php $about me = "text<br />text"; ?> <?php $about_me = str_replace('<br />', '<br>', $about_me); ?> <script type="text/javascript"> function toggle_visibility(id) { var div = document.getElementById(id); var text = document.getElementById("about_me_text"); if(div.style.display == 'none' ) { div.style.display = 'block'; text.innerHTML = "<?php $about_me = str_replace('<br>', '\n', $about_me); ?><?php echo $about_error; ?><form action='' method='POST'><textarea cols='23' rows='6' name='textarea_about' id='textarea_about' style='font-family:arial;font-size:13px;overflow:hidden'><?php echo "$about_me";?></textarea><br><input type='submit' name='submit_about' value='Save'> <input type='button' name='cancel_about' value='Cancel' onClick=\"window.location.href='content.php?content=myhub&myhub=mypage&mypage=mypage&cont=<?php echo $cont;?>'\"></form>"; } else { div.style.display = 'none'; text.innerHTML = "<?php $about_me = str_replace('\n', '<br />', $about_me); ?><?php echo $nothing.$about_me; ?>"; } } </script> but this does not work.... <?php $about_me_query = mysql_query("SELECT * FROM page_set_data WHERE username='$username'"); while ($row = mysql_fetch_assoc($about_me_query)) { $about_me = $row['about_me']; } if (!$about_me) { $about_me = ""; $nothing = "Write about yourself"; } ?> <?php $about_me = str_replace('<br />', '<br>', $about_me); ?> <script type="text/javascript"> function toggle_visibility(id) { var div = document.getElementById(id); var text = document.getElementById("about_me_text"); if(div.style.display == 'none' ) { div.style.display = 'block'; text.innerHTML = "<?php $about_me = str_replace('<br>', '\n', $about_me); ?><?php echo $about_error; ?><form action='' method='POST'><textarea cols='23' rows='6' name='textarea_about' id='textarea_about' style='font-family:arial;font-size:13px;overflow:hidden'><?php echo "$about_me";?></textarea><br><input type='submit' name='submit_about' value='Save'> <input type='button' name='cancel_about' value='Cancel' onClick=\"window.location.href='content.php?content=myhub&myhub=mypage&mypage=mypage&cont=<?php echo $cont;?>'\"></form>"; } else { div.style.display = 'none'; text.innerHTML = "<?php $about_me = str_replace('\n', '<br />', $about_me); ?><?php echo $nothing.$about_me; ?>"; } } </script> and the data in the database is exactly the same, i have also connected to the db further up in the page.. Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000131 Share on other sites More sharing options...
squiblo Posted January 22, 2010 Author Share Posted January 22, 2010 so basically, this script does not work when $about_me is data from mysql!! WHYY??? ive never seen anything like this before Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000169 Share on other sites More sharing options...
squiblo Posted January 23, 2010 Author Share Posted January 23, 2010 help anybody please? Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000279 Share on other sites More sharing options...
oni-kun Posted January 23, 2010 Share Posted January 23, 2010 help anybody please? ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); Why not var_dump your SQL query results and tell us what is wrong? As well as sql_error() Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000283 Share on other sites More sharing options...
greatstar00 Posted January 23, 2010 Share Posted January 23, 2010 sometime u might have <br /> with line break, or with css style, and this wont get u work <br style="line-height:100px;" /> << this wont work so, sometime, people just save the raw textarea content into database without converting them into html format so, when u retrieve it out, they convert it to html format because convert raw content to html is much easier than the reverse way because html, u might have css, or html tag's property, like width=100% u need to consider this, although ur sever might runs faster this way, cause users view posts more than modify, insert them but u need to spend more time to program the reg expression, this spends time, and money ok, i got what u did wrong u have this '\n' << the line break escape character should be "\n" << with double quote because single quote wont fetch the escape characters Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000308 Share on other sites More sharing options...
squiblo Posted January 24, 2010 Author Share Posted January 24, 2010 greatstar00 i changed the quotes to double quotes but then they both didnt work. What do you mean about the css and uploading raw textarea because i dont quite understand? could anyone try and describe it differently please? if this is needed, this is how i uploaded the data to the db... if (isset($_POST['submit_about'])) { if (isset($_POST['textarea_about'])) { $textarea_about = nl2br(strip_tags($_POST['textarea_about'])); if (strlen($textarea_about) < 301) { mysql_query("UPDATE page_set_data SET about_me='$textarea_about' WHERE username='$username'"); header("location:http://www.squiblo.com/content.php?content=myhub&myhub=mypage&mypage=mypage&cont=$cont"); } else $about_error = "<ul><li>Maximum of 300 characters.</li></ul>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/189474-simple-phpjava-script-logic/#findComment-1000917 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.