Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT with WHERE condition using html search and php post. Returns blank table

The task is pretty straight forward. Using an html form, a last name is posted into a php code which connects to myAdmin database and returns the first and last name associated with the form posted last name from the html search. I've double checked my database, as well as the connection php I am using. The information is in the db and my connection.php file has worked fine for other files accessing and manipulating this same db. Anyway here is my html code:

<html>
<body>
<form action="where.php" method="post">
Lastname: <input type="text" name="lastname" />
<input type="submit" name="search" />
</form>
</body>
</html>

and my post php code:

<?php
include('connection.php');

$sql = "SECLECT * FROM PERSONS WHERE LastName ='$_POST[lastname]'";
$result = mysql_query($sql);
?>

<table border='1'>
<tr>
    <td>Firstname</td>
    <td>Lastname</td>
</tr>

<?php
while($row = mysql_fetch_array($result))
{
?>
  <tr>
  <td><?php echo $row['FirstName'] ?></td>
  <td><?php echo $row['LastName'] ?></td>
  </tr>

<?php
}
?>
</table>

<?php
mysql_close($con);
?>

Anyone see why when I search for a valid last name I get back a table that only has the headings but no values?

like image 402
James Wilkerson Avatar asked Jan 27 '26 19:01

James Wilkerson


2 Answers

You put "SECLECT" on the query. It's SELECT.

like image 131
Pablo Anaya Avatar answered Jan 30 '26 11:01

Pablo Anaya


Try changing your query to -

$sql = "SELECT * FROM PERSONS WHERE LastName like '%$_POST[lastname]%'";

If it shows some results then you may have problem in exact match scenario

like image 42
kewlashu Avatar answered Jan 30 '26 09:01

kewlashu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!