DruX Posted May 23, 2009 Share Posted May 23, 2009 I have setup a form that adds data to a MySQL database, however I need spaces in textarea form inputs to be filled with instead of just a regular space when the data is added to the MySQL table. For example, if someone enter "Ice Cream" in the text box and clicks submit, "Ice Cream" is what actually needs to be added in the database table. I am wonder if this is possible and how to set this up. Not sure if it can be accomplished with HTML, PHP, or in MySQL. -DruX Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 23, 2009 Share Posted May 23, 2009 Clicky Quote Link to comment Share on other sites More sharing options...
TylerDiaz Posted May 23, 2009 Share Posted May 23, 2009 I took a look at the link providd above, and its not of too much help for a begginer. The method you want can be done in tons of ways but here I provide a simple way using php: $test = "Ice cream"; echo preg_replace ("/ /", " ", $test); Should output to the source of: Ice Cream Quote Link to comment Share on other sites More sharing options...
DruX Posted May 24, 2009 Author Share Posted May 24, 2009 Thanks TylerDiaz, that code worked. $food0 = $_POST['food']; $category0 = $_POST['category']; $brand0 = $_POST['brand']; $addname = $_SESSION['username']; $food = preg_replace ("/ /", " ", $food0); $category = preg_replace ("/ /", " ", $category0); $brand = preg_replace ("/ /", " ", $brand0); mysql_query("INSERT INTO foods (food, category, brand, username) VALUES ('$food', '$category', '$brand', '$addname')"); -DruX Quote Link to comment Share on other sites More sharing options...
TylerDiaz Posted May 24, 2009 Share Posted May 24, 2009 Thanks TylerDiaz, that code worked. $food0 = $_POST['food']; $category0 = $_POST['category']; $brand0 = $_POST['brand']; $addname = $_SESSION['username']; $food = preg_replace ("/ /", " ", $food0); $category = preg_replace ("/ /", " ", $category0); $brand = preg_replace ("/ /", " ", $brand0); mysql_query("INSERT INTO foods (food, category, brand, username) VALUES ('$food', '$category', '$brand', '$addname')"); -DruX P.S. Not sure how to mark as solved. Something even more effective you can try is: $test = "Ice cream"; function spaceclean($data){ preg_replace ("/ /", " ", $data); } $food = spaceclean($food0); $category = spaceclean($category0); $brand = spaceclean($brand0); Cleans up your code a bit. And provides same effect. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 24, 2009 Share Posted May 24, 2009 TylerDiaz: That doesn't work. Your function doesn't return anything. I posted a MySQL function being in the MySQL mood since this topic was here. But PHP would have been better. My mistake. Sorry DruX. Quote Link to comment 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.