title: How doesnt my php code connect to the database..using Xampp
body: <p>First forgive me if the code is not in an organized manner, I have tried to insert code in a neat manner but by the time I fix it, the system times out, so I cant post and have to do it all over again..so this time I am not going to adjust the code.. just copy past it into forum</p>
  
  <p>I created a from called product_insert.html.. and a php script called product_insert.php. They are both located in a sub folder called Final exam, in the htdoc folder of xampp. </p>
  
  <p>After entering data into form, the next screen basically shows me the script of the product_insert.php. I cannot figure out why it does not make the connection. Also the database is called final_exam.  </p>
  
  <p>i have edited my code to the following and i am still getting errors</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
   &lt;body&gt;
  
  &lt;?php
   mysql_connect("localhost", "root", "Final exam") 
   or die(mysql_error());
  
  //echo "We have successfully connect to our DB.&lt;br/&gt;";
  
    mysql_select_db( "final_exam") or die(mysql_error());
  
  //echo "Successfully opened DB.&lt;br/&gt;";
  
  //pull values from the URL and put them each in a variable
  
      $Description = addslashes($_GET["Description"]);
      $Quantity = addslashes($_GET["Quantity"]);
      $Price = addslashes($_GET["Price"]);
      $Vend_id = addslashes($_GET["Vend_id"]);
  
      if($Description &amp;&amp; $Quantity &amp;&amp; $Price &amp;&amp; $Vend_id)
      {
              echo "test1";
  
      }
          else
      {
          echo "test2";
      }
  
      if(isset($Description) &amp;&amp; !empty($Description) 
      &amp;&amp; isset($Quantity) &amp;&amp; !empty($Quantity)
      &amp;&amp; isset($Price) &amp;&amp; !empty($Price)
      &amp;&amp; isset($Vend_id) &amp;&amp; !empty($Vend_id))
      {           
        $SQLstring = "INSERT INTO student (id, first_name,last_name,address, e_mail,             
  gpa)
  VALUES (NULL, '$first', '$last', '$address', '$email', 0.0)";
  
  $QueryResult = @mysqli_query($DBConnect, $SQLstring)
   Or die("Insert Broke!!!");
  
  echo "insert complete";
      }   
      else
      {
      echo "You are missing some values...Please press the back button and retry!";
      }
  //redirect back to our list page since the insert worked
   header("location: db_connect.php");        
      ?&gt;{/PHP]
  
  &lt;!--Insert Complete: click &lt;a href="product_list.html"&gt;here&lt;/a&gt; to go back to the     
  list!--&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>i have edited my code to the following and i am still getting errors</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;?php
  
          $host = "localhost"; // change this as required
          $username = "root"; // change this as required
          $password = "password"; // change this as required
          $db = "final_exam"; // your DB  
  
              $DBConnect=mysql_connect("localhost", "root", "password") 
                  or die("Could Not Connect");
              //echo "We have successfully connect to our DB.&lt;br/&gt;";
  
              mysql_select_db( "final_exam")
                  or die(mysql_error());
              //echo "Successfully opened DB.&lt;br/&gt;";
  
              //pull values from the URL and put them each in a variable
              $Description = addslashes($_GET["Description"]);
              $Quantity = addslashes($_GET["Quantity"]);
              $Price = addslashes($_GET["Price"]);
              $Vend_id = addslashes($_GET["Vend_id"]);
  
              if($Description &amp;&amp; $Quantity &amp;&amp; $Price &amp;&amp; $Vend_id)
              {
                  echo "test1";
  
              }
              else
              {
                  echo "test2";
              }
  
              if(isset($Description) &amp;&amp; !empty($Description) 
                  &amp;&amp; isset($Quantity) &amp;&amp; !empty($Quantity)
                  &amp;&amp; isset($Price) &amp;&amp; !empty($Price)
                  &amp;&amp; isset($Vend_id) &amp;&amp; !empty($Vend_id))
              {           
                  $SQLstring = "INSERT INTO student (id,                          
  VALUES ('$Description', '$Quantity', '$Price', '$Vend_id')";
  
                  $QueryResult = @mysql_query($DBConnect, $SQLstring)
                      Or die("Insert Broke!!!");
  
                  echo "insert complete";
          }   
              else
              {
                  echo "You are missing some values...Please press the back 
  button and retry!";
              }
              //redirect back to our list page since the insert worked
              header("location: product_list.php");       
  
          ?&gt;
  
          &lt;a a href="product_insert.html"&gt;Click here&lt;/a&gt; to go back to the list!--&gt;
      &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>