title: How to insert a URL into MySQL database using PHP?
body: <p>I have a form that submits information into a database.  The form includes 3 inputs - a name, a description, and a URL.  All three work fine and submit the data into the database, but the URL input only works if the text that is entered DOES NOT include <code>http://</code> which is not what I want. I NEED it to include the <code>http://</code></p>
  
  <p>Currently, if I submit the form without the <code>http://</code> it goes through fine, but if it does include the <code>http://</code> I get a 406 not acceptable error.</p>
  
  <p>I've read some articles about <code>mysqli_real_escape_string</code> but I haven't had any luck getting it to work.  Currently I have the following:</p>
  
  <pre><code>$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  $code_name = filter_var($_POST['code_name'], FILTER_SANITIZE_STRING);
  $code_desc = filter_var($_POST['code_desc'], FILTER_SANITIZE_STRING);
  $code_dest = filter_var($_POST['code_dest'], FILTER_SANITIZE_STRING);
  
  $stmt = $dbh-&gt;prepare("INSERT INTO qr_codes (code_name, code_desc, code_dest ) VALUES (:code_name, :code_desc, :code_dest )");
  
  $stmt-&gt;bindParam(':code_name', $code_name, PDO::PARAM_STR);
  $stmt-&gt;bindParam(':code_desc', $code_desc, PDO::PARAM_STR, 40);
  $stmt-&gt;bindParam(':code_dest', $code_dest, PDO::PARAM_STR, 40);
  
  $stmt-&gt;execute();
  </code></pre>
  
  <p>Here is the form:</p>
  
  <pre><code>&lt;form id="newQR" method="post" action="create-qr-code.php" onSubmit="return validateForm();"&gt;
      &lt;ul class="new-qr-form"&gt;
          &lt;li&gt;&lt;label&gt;Name&lt;/label&gt;&lt;br&gt;&lt;input id="code_name" name="code_name" type="text" class="form-control" &gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Description&lt;/label&gt;&lt;br&gt;&lt;input id="code_desc" name="code_desc" type="text" class="form-control" &gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Destination&lt;/label&gt;&lt;br&gt;&lt;input id="code_dest" name="code_dest" type="text" class="form-control" &gt;&lt;/li&gt;
          &lt;li class="img-src-preview"&gt;&lt;label&gt;Preview Source&lt;/label&gt;&lt;br&gt;&lt;input value="test" id="code_img_src" name="code_img_src" type="text" class="form-control" &gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Any ideas on why it won't allow a URL?</p>