title: How to replace space with underscore in a typen text in a form using PHP or javascript in exesting script
body: <p>I need a little help. I have created the below script. A form that save its info to my database and a long with that it create some (2 on different paths) folders on the server.</p>
  
  <p>My issue is that in the form under ”folder” you can type the name of the folder you want to create along with the info that is saved in the database. At the moment everything works just as it should. My request/issue is how do a replace space “ “ from the folder name to an underscore “_”</p>
  
  <p>Means, if someone enters a folder name called “My Folder Photo” I need the script to change the name to: “my_folder_photo” so it will work in urls on the website.</p>
  
  <p>The is my codes so fare:</p>
  
  <pre><code>&lt;?php
  include "../config.php";
  if(isset($_POST['send']))
  {
  mysql_query("insert into profiles set name= '".$_POST["name"]."', age= '".$_POST["age"]."', country = '".$_POST["country"]."', folder = '".$_POST["folder"]."'");
  
  $folder = $_POST['folder'];
  $path1 = '../game1/photos/' . $folder;
  $path2 = '../game2/photos/' . $folder;
  mkdir($path1);
  mkdir($path2);
  header("Location: myprofile-new-step2.php");
  
  exit;
  }
  
  ?&gt;
  
  
  &lt;form method="post" action="&lt;?=$_SERVER["PHP_SELF"]?&gt;" name="myform" id="myform"&gt;
  &lt;table bgcolor="#FFFFFF"  border="0" align="center"&gt;&lt;tr&gt;&lt;td width="70"&gt;
  Name: 
  &lt;/td&gt;&lt;td width="270"&gt;
  &lt;input type="text" name="name" size="40"&gt;
  &lt;/td&gt;&lt;td&gt;
  
  &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
  Age: 
  &lt;/td&gt;&lt;td&gt;
  &lt;input type="text" name="age" size="40"&gt;
  &lt;/td&gt;&lt;td&gt;
  
  &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
  Country: 
  &lt;/td&gt;&lt;td&gt;
  &lt;select name="country"  data-placeholder="&lt;?=$country?&gt;" class="chosen-select" style="width:250px;" id="&lt;?=$country?&gt;" value="&lt;?=$country?&gt;"  &lt;?= (!empty($country) ? 'checked="checked"' : "")?&gt;&gt;
              &lt;option value="&lt;?=$country?&gt;"&gt;&lt;/option&gt;
              &lt;option value="United States"&gt;United States&lt;/option&gt;
              &lt;option value="United Kingdom"&gt;United Kingdom&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;&lt;td&gt;
  Enter the country you live in.
  &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
  Folder: 
  &lt;/td&gt;&lt;td&gt;
  &lt;input type="text" name="folder" size="40"  id="folder"&gt;
  &lt;/td&gt;&lt;td&gt;
  
  &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; 
  &lt;center&gt;&lt;br /&gt; 
  &lt;input type="submit" name="send" title="NEXT" value="NEXT"&gt;&lt;/center&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Im a new to php so need as much help as possible to figure this out :) THANKS</p>