Thanks to the help of many on this forum I've been able to put together a script that allows me to do some basic CMS functions, like pulling data from the MYSQL database, displaying it in rows/tables, etc.
Now I have tried to extend the functionality of my search by adding some javascript on an ajax framework, but I don't know how to pull the data from the database using this code. I keep getting an error, and I don't know the solution. I have no trouble pulling the data without the javascript, but with it, I'm running into an error.
Here's the code for the search page:
<div id="search-wrap">
<h1>Search with Auto Suggest</h1>
<input name="search-q" id="search-q" type="text" onkeyup="javascript:autosuggest()"/>
<div id="results"></div>
</div>
Here's the code for the search.php
<?php
include('config.php');
$SQL_FROM = 'runners';
$SQL_WHERE = 'last_name';
?>
<?php
$searchq = strip_tags($_GET['q']);
$getRecord_sql = 'SELECT * FROM '.$SQL_FROM.' WHERE '.$SQL_WHERE.' LIKE "'.$searchq.'%"';
$getRecord = mysql_query($getRecord_sql);
if(strlen($searchq)>0){
echo '<ul>';
while ($row = mysql_fetch_array($getRecord)) {?>
<li><a href="runners2.php"><?php echo $row['last_name']; ?> <small><?php echo $row['first_name']; ?></small></a></li>
<?php }
echo '</ul>';
?>
<?php } ?>
With the above code, I connect to my database, and when I type in a last name, all the similar last names in my database appear below the search form. But when I go to click the particular name, I get an error. The code for the page I'm trying to pull (runners2.php) looks like this:
<?php
// Include connection to your database
$con = mysql_connect("localhost","root","rilke123");
mysql_select_db("RUNNERS", $con) or die(mysql_error());
$name = $_POST['last_name'];
$query = "SELECT * FROM runners WHERE last_name ='".$name."'";
$result = mysql_query($query) or die(mysql_error());
echo "<table class='sortable'>";
while ($list = mysql_fetch_assoc($result)) {
echo "<thead>";
echo "<tr>";
echo "<th>ID #</th>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>1 Mile</th>";
echo "<th>2 Mile</th>";
echo "<th>5k</th>";
echo "<th>10k</th>";
echo "<th>15k</th>";
echo "<th>20k</th>";
echo "<th>13.1</th>";
echo "<th>26.2</th>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
echo "<th>" . $list['id'] . "</th>";
echo "<th>" . $list['first_name'] . "</th>";
echo "<th>" . $list['last_name'] . "</th>";
echo "<th>" . $list['one'] . "</th>";
echo "<th>" . $list['two'] . "</th>";
echo "<th>" . $list['five'] . "</th>";
echo "<th>" . $list['ten'] . "</th>";
echo "<th>" . $list['fifteen'] . "</th>";
echo "<th>" . $list['twenty'] . "</th>";
echo "<th>" . $list['half'] . "</th>";
echo "<th>" . $list['full'] . "</th>";
echo "</tr>";
echo "</tbody>";
}
?>
The error I'm getting is on line 31 of this page, which is: $name = $_POST['last_name'];
and the error says: Notice: Undefined index: last_name in /Users/laurenyoung/Sites/adr/runners2.php on line 31
I don't understand. As always, thanks for any suggestions.