Brad420 Posted July 25, 2008 Share Posted July 25, 2008 I created a script that updates a MySQL database and the text is then used as a scrolling text in a JavaScript. The problem is when I update the text a space becomes %A0, as well as any character. I have tried to use str_replace() to search for %AO and replace with   and so on, but doesn't seem practical. Is there anyway around this? Should I be looking for another way to update this database, and store the text in another format? Here is the locations of the 2 scripts one that displays the data and another that updates it. I will also post the code for the updating... Any help is appreciated... http://beta.auctioncms.com/dinardoframe.php Display http://beta.auctioncms.com/dinardoupdate.php Update Code************************** //----------------- Make the MySQL connection $_link = mysql_connect($_dbhost, $_dbuser, $_dbpass); if (!$_link) { die('Not connected : ' . mysql_error()); } // make foo the current db $_db_selected = mysql_select_db($_dbname, $_link); if (!$_db_selected) { die ('Can\'t use foo : ' . mysql_error()); } //Check to see that text was entered and update to database $value = $_POST['newtext']; if ($value == '') { mysql_close($_link); } else { $result = mysql_query("UPDATE scroll SET textjs = '$value' WHERE id = 1"); } //Get Value from Database to display to textbox $queryget = "SELECT textjs FROM scroll"; $resultget = mysql_query($queryget); $rowget = mysql_fetch_array($resultget); //Replace Strings $value2 = $rowget['textjs']; $newstring1 = str_replace("%A0"," ",$value2); $newstring2 = str_replace("%3Cb%3E","<b>",$newstring1); $newstring3 = str_replace("%3C/b%3E","</b>",$newstring2); $newstring4 = str_replace("%u2022","•",$newstring3); $newstring5 = str_replace("%0D%0A","<br>",$newstring4); $newstring6 = str_replace("%u201C","“",$newstring5); $newstring7 = str_replace("%u201D","”",$newstring6); $newstring8 = str_replace("%u2019","’",$newstring7); $newstring9 = str_replace("%20"," ",$newstring8); $finalvalue = $newstring9; ?> <script language="javascript" type="text/javascript"> function submitScrollBulletinInput(){ var escapedValue = escape(document.getElementById("prenewtext").value); document.getElementById("newtext").value = escapedValue; document.getElementById("formName").submit(); } </script> <form name="formName" id="formName" action="" method="post"> <textarea type="text" name="prenewtext" id="prenewtext" rows="10" cols="22" ><? echo $finalvalue; ?></textarea><br/><br/> <input type="button" onclick="submitScrollBulletinInput()" value="Submit"/> <input type="hidden" name="newtext" id="newtext" value=""/> </form> Link to comment https://forums.phpfreaks.com/topic/116611-php-javascript-and-mysql/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.