title: Using PHP to add to a database created in WAMP server?
body: <p>Ok, so after installing wamp server, I have gone to the phpMyAdmin page and created a database called db2. After that, I have created a table inside of that database called cnt2. It has 5 columns, ID, Name, Mark1, Mark2 and Mark3. So, I have one html php file that allows you to view the information in the database, and this works just fine. However, my second html php document is supposed to allow you to add new information into the database. I have followed 2 different tutorials on this as I have never done php or any html script before, but it just isn't working. I'll post both codes/scripts below. </p>
  
  <p><a href="http://gyazo.com/467f8e3a066992c0753eec2d5912bdba" rel="nofollow">http://gyazo.com/467f8e3a066992c0753eec2d5912bdba</a>   &lt;&lt; Database page</p>
  
  <p><a href="http://gyazo.com/82a1c2107fb75c4c2941583449b4504a" rel="nofollow">http://gyazo.com/82a1c2107fb75c4c2941583449b4504a</a>  &lt;&lt; Input page with error</p>
  
  <p>Database code</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
  
  $username = "root";
  $password = "";
  $hostname = "localhost";
  
  $dbhandle = mysql_connect($hostname, $username, $password)
      or die("Unable to connect to MySQL");
  echo "Connected to MySQL&lt;br&gt;";
  
  $selected = mysql_select_db("db2",$dbhandle)
      or die("Could not selected db2");
  echo "Coneted to db2&lt;br&gt;", "&lt;br&gt;";
  
  $result = mysql_query("SELECT ID, Name, Mark1, Mark2, Mark3 FROM cnt2");
  
  while($row = mysql_fetch_array($result)){
      echo "&lt;b&gt;Name: &lt;/b&gt;".$row{'Name'}." &lt;b&gt;ID: &lt;/b&gt;".$row{'ID'}." &lt;b&gt;First Mark: &lt;/b&gt;".$row{'Mark1'}." &lt;b&gt;Second Mark: &lt;/b&gt;".$row{'Mark2'}." &lt;b&gt;Third Mark: &lt;/b&gt;".$row{'Mark3'}."&lt;br&gt;";
  }
  
  mysql_close($dbhandle);
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Input code</p>
  
  <pre><code>&lt;HTML&gt;
  &lt;?php
  
  if($submit){
      $db = mysql_connect("localhost", "root","");
      mysql_select_db("db",$db);
      $sql = "INSERT INTO cnt2 (ID, Name, Mark1, Mark2, Mark3) VALUES ('$id','$name','$markone','$marktwo','$markthree','$result = mysql_query($sql))";
      echo "Thanks! Data received and entered.\n";
  }
  
  else{
      ?&gt;
      &lt;form method="post" action="datain.php"&gt;
      id:&lt;input type="Int" name="ID"&gt;&lt;br&gt;
      name:&lt;input type="Text" name="Name"&gt;&lt;br&gt;
      markone:&lt;input type="Int" name="Mark1"&gt;&lt;br&gt;
      marktwo:&lt;input type="Int" name="Mark2"&gt;&lt;br&gt;
      markthree:&lt;input type="Int" name="Mark3"&gt;&lt;br&gt;
      &lt;input type="Submit" name="submit" value="Enter information"&gt;
      &lt;/form&gt;
  &lt;?  
  }
  
  ?&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>Thanks for any help :)</p>