title: Connecting to MySQL(WAMP) database with PHP
body: <p>Here is what I am trying to do.  </p>
  
  <p>I have an index.php page which accepts user input and then transfers it to infosubmitted.php</p>
  
  <pre><code>    &lt;?php
  include('header.php');
  ?&gt;
  
  &lt;body&gt;
  &lt;form action="infosubmitted.php" method="post" id="infosubmitted"&gt;
  &lt;div id="header"&gt;
  &lt;h1&gt;&lt;strong&gt;Enter In The Data&lt;/h1&gt;&lt;/strong&gt;
  &lt;/div&gt;
  &lt;div id="main"&gt;
  &lt;table border="0" width="75%"&gt;
          &lt;tr&gt;
              &lt;td align="right" width="10%"&gt;First Name: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="fname" id="fname" size="20" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td align="right" width="10%"&gt;Last Name: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="lname" id="lname" size="20" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td align="right" width="10%"&gt;Age: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="age" id="age" size="3" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td align="right" width="10%"&gt;City: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="city" id="city" size="20" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" /&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;?php
  include('footer.php');
  ?&gt;
  </code></pre>
  
  <p>Now, I am trying to get the variables and store them in a database called test in a table called people</p>
  
  <p>Here is the dbconnect.php</p>
  
  <pre><code>&lt;?php
  // Set the database access information as constants 
  
  define('DB_USER', 'root');
  define('DB_PASSWORD', 'phpmyadmin');
  define('DB_HOST', 'localhost');
  define('DB_NAME', 'test');
  
  ?&gt;
  </code></pre>
  
  <p>And here is the model.php</p>
  
  <pre><code>&lt;?php
  // model for the totals of the wreath orders
  require_once("dbconnect.php");
  
  // connect to database and check errors
  @ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  
  $connection_error = $dbc-&gt;connect_error;
  if ($connection_error != null) {
    echo "&lt;p&gt;Error connectiong to database: $connection_error&lt;/p&gt;";
    exit();
  }
  ?&gt;
  </code></pre>
  
  <p>Here is infosubmitted.php</p>
  
  <pre><code>&lt;?php
  require_once("model.php");
  
  
  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $age = $_POST['age'];
  $city = $_POST['city'];
  
  insertIntoTable($fname, $lname, $age, $city);
  
  
  
  function insertIntoTable($fname, $lname, $age, $city){
  global $dbc;
  
  $insertRow = 'INSERT INTO people(fname, lname, age, city) VALUES('$fname', '$lname', '$age', '$city')';
  $result = $dbc-&gt;query($insertRow);
  header('location: getinformation.php');
  
  }
  ?&gt;
  </code></pre>
  
  <p>Then I want it redirected to getinformation.php to take the record back out of the database so I can store it back into variables.  </p>
  
  <pre><code>&lt;?php
  include('model.php');
  include('header.php');
  
  $fname = $people['fname'];
  $lname = $people['lname'];
  $age = $people['age'];
  $city = $people['city'];
  $dbc-&gt;close();
  ?&gt;
  &lt;div id="header"&gt;
  &lt;h1&gt;&lt;strong&gt;This is the information you submitted&lt;/h1&gt;&lt;/strong&gt;
  &lt;/div&gt;
  &lt;div id="main"&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;First Name:&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $fname; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Last Name:&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $lname; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Age:&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $age; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;City:&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $city; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;?php
  include('footer.php');
  ?&gt;
  </code></pre>
  
  <p>I get the error</p>
  
  <p>Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\wamp\www\testwebpage\Model\infosubmitted.php on line 17</p>
  
  <p>I know I could just keep passing the variables from the index to info submitted and then to getinformation but I am trying to get a grasp on connecting to the database.</p>
  
  <p>I want to have the user enter data, have the data sent to another page then that data is put into the table then redirect to a new page and have the information from the table dumped back into variables so I can put them on the screen. </p>