title: Understanding Prepared Statements - PHP
body: <p>I am working on a school project for the finacial aid office at a university. The project is in production and have most of it done apart from a few little tweaks here and there. My main concern over the winter break (now) is security and preventing any breaches to the best of my abilities. People have told me to steer into Prepared Statements. I understand them to a good extent except for inserting data. </p>
  
  <p>I have two forms : a login in form and student login form. The student login form enters why a student is coming to the office. that form is then submitted and that data is later retrieved by a table that shows counselors what students are waiting to be seen. </p>
  
  <p>My problem is though each student who walks into the financial aid office has his or her own unique problem (most of the time) so now what confuses me is : </p>
  
  <p>Do I need to think ahead and pre-make the insert queries or is there a way for there to be a "dynamic" query because there is a student comments box and for that it will be totally unique so how will I be able to create a query for that? </p>
  
  <pre><code>&lt;?php
  define('DB_Name', 'dbtest');
  define('DB_User', 'root');
  define('DB_Password', 'testdbpass');
  define('DB_Host', 'localhost');
  
  $link = mysql_connect(DB_Host, DB_User, DB_Password);
  
  if (!$link) {
    die ('Could Not Connect: ' . mysql_error ());
  }
  
  $db_selected = mysql_select_db(DB_Name, $link);
  
  if (!db_selected) {
    die('Can Not Use ' . DB_name . ': ' . mysql_error());
  }
  
  $value1 = $_POST ['anum'];
  $value2 = $_POST ['first'];
  $value3 = $_POST ['last'];
  $value4 = $_POST ['why'];
  $value5 = $_POST ['comments'];
  
  $sql = "INSERT INTO `dbfinaid` (anum, first, last, why, comments) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5')";
  
  if (!mysql_query($sql)) {
    die('Error : ' . mysql_error());
  }
  
  mysql_close();
  </code></pre>
  
  <p>and as I have been told doing it that way leaves me prone to SQL-Injections. </p>
  
  <p>Any help will be very much appreciated. Thank you. </p>