title: mysql database with HTML form?
body: <p>I'm trying to make it to where the user can input a name that is already in the database. Once they select "Go", I need it to show all of the results from the <code>contact</code> table that matches the inputted data by the user. Am I missing something? When I run the HTML, the PHP runs, but comes up with "0 results". I think it might be something in my SELECT statement, but could not find an answer. Code below...</p>
  
  <h2>HTML File</h2>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Module 3 | Course Project&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h4&gt;Ancestry Data Query&lt;/h4&gt;
    &lt;form action="queryMyDatabase.php" method="post"&gt;
      First Name: &lt;input name="dataItem1" type="text" size="30" maxlength="30"&gt;&lt;br&gt;&lt;br&gt;
      Last Name: &lt;input name="dataItem2" type="text" size="30" maxlength="30"&gt;&lt;br&gt;&lt;br&gt;
      &lt;input value="Go"  type="submit"&gt;
    &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>PHP File</h2>
  
  <pre><code>&lt;?php
  // Make a MySQL Connection
  $servername = "localhost";
  $username = "root";
  $password = "bitnami admin password";
  $dbname = "adventureworks";
  
  
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $item1=$_POST["dataItem1"];
  $item2=$_POST["dataItem2"];
  
  $sql="SELECT * FROM `contact` WHERE FirstName = `$item1` AND LastName = `$item2`";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          echo "First Name " . $row["FirstName"] . "&lt;br&gt;" . "Last Name " . $row["LastName"] . "&lt;br&gt;";
      }
  } else {
      echo "0 results";
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Jewa7.jpg" rel="nofollow noreferrer">table structure</a></p>
  
  <p>The shell code I had was this....</p>
  
  <pre><code>&lt;?php
  // Make a MySQL Connection
  $servername = "localhost";
  $username = "root";
  $password = "yourApplicationPassword";
  $dbname = "desiredDatabase";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  $stmt = $conn-&gt;prepare("SELECT * FROM desiredTable WHERE desiredColumn1 = ? AND desiredColumn2 = ?");
  $stmt-&gt;bind_param('ss', $_POST["dataItem1"] , $_POST["dataItem2"]);
  $stmt-&gt;execute();
  $result = $stmt-&gt;get_result();
  $row_count= $result-&gt;num_rows;
  
  echo "Query Results&lt;/br&gt;-----------------------------&lt;br&gt;&lt;br&gt;";
  if($row_count&gt;0){
  while($row = mysqli_fetch_array($result))
  {
      echo $row['desiredColumn1']." ".$row['desiredColumn2']." ".$row['desiredColumn3']."-".$row['desiredColumn4']."-".$row['desiredColumn5']."&lt;/br&gt;";
  }
  } else {
      echo "0 results";
  }
  echo "&lt;br&gt;-----------------------------&lt;br&gt;";
  $stmt-&gt;close();
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>But I still needed the variables for the "dataItem".</p>
  
  <pre><code>$item1=$_POST["dataItem1"];
  $item2=$_POST["dataItem2"];
  </code></pre>