title: Inserting data to database via web form
body: <p>I have looked for the answer to my question and seeing as all programming varies I can't seem to fix my problem. I have created a php file that does in fact connect to my database. However, when I try submitting data to my database via my php webpage it won't go through. The same happens when I try to display info from my database to a webpage. Seeing as it is in fact connecting to the database, I'm not sure what the issue is. Any help is appreciated, try to dumb it down for me as much as possible when you answer. Also, I have triple-checked my database name and table names to make sure they match up with my coding. Here's my code:</p>
  
  <p>Connection to database:</p>
  
  <pre><code>&lt;?php
  
  DEFINE ('DB_USER', 'root');
  DEFINE ('DB_PSWD', '');
  DEFINE ('DB_HOST', 'localhost');
  DEFINE ('DB_NAME', 'art database');
  
  $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);
  
  ?&gt;
  </code></pre>
  
  <p>My form to insert data to my database:</p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST['submitted'])) {
  
      include('connect-mysql.php');
  
      $fname = $_POST['fname'];
      $lname = $_POST['lname'];
      $sqlinsert = "INSERT INTO users (first name, last name) VALUES ('$fname','$lname')";
  
      if (!mysqli_query($dbcon, $sqlinsert)) {
          die('error inserting new record');
          } //end of nested if
  
          $newrecord = "1 record added to the database";
  
  
  } // end of the main if statement
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Insert Data into DB&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  
  &lt;hl&gt;Insert Data into DB&lt;/hl&gt;
  
  &lt;form method="post" action="insert-data.php"&gt;
  &lt;input type="hidden" name="submitted" value="true"/&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;New People&lt;/legend&gt;
      &lt;label&gt;First Name:&lt;input type="text" name="fname" /&gt;&lt;/label&gt;
      &lt;label&gt;Last Name:&lt;input type="text" name="lname" /&gt;&lt;/label&gt;
  &lt;/fieldset&gt;
  &lt;br /&gt;
  &lt;input type="submit" value="add new person" /&gt;
  &lt;/form&gt;
  &lt;?php
  echo $newrecord;
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>