<?php # Script 16.5 - index.php
// This is the main page for the site.
// Include the configuration file:
require_once ('includes/config.inc.php');
// Set the page title and include the HTML header:
$page_title = 'Welcome to this Site!';
include ('includes/header.html');
// Welcome the user (by name if they are logged in):
echo '<h1>Welcome';
if (isset($_SESSION['first_name'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';
$words = "search";
// Show the search form:
echo '<form action="index.php" method="get" accept-charset="utf-8">
<p><em>' . $words . '</em>: <input name="terms" type="text" size="30" maxlength="60" ';
// Check for existing value:
if (isset($_GET['terms'])) {
echo 'value="' . htmlspecialchars($_GET['terms']) . '" ';
}
//echo ($_GET['terms']);
// Complete the form:
echo '/><input name="submit" type="submit" value="' . $words . '" /></p></form>';
require_once('mysqli_connect.php');
if (isset($_GET['terms'])) { // Handle the form.
// Clean the terms:
$terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms'])));
// Run the query...
$q = "SELECT * FROM `metadata` WHERE `keyword` LIKE '$terms'";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
echo '<h2>Search Results</h2>';
$row = mysqli_fetch_row($r);
echo ($row[0]);
}
$qq = "SELECT location From datalocation Where `keywordID` = $row[0]";
$rr = mysqli_query($dbc, $qq);
if(mysqli_num_rows($rr) > 0)
{
$results = mysqli_fetch_row($rr);
echo ($results[0]);
} else {
echo '<p>No results found.</p>';
}
//}
}
?>
<p>data results</p>
<?php // Include the HTML footer file:
include ('includes/footer.html');
?>
This is for a project I'm doing in my software engineering course and when I type in the terms I have in the MySQL database now, they do pop up. However, the keyword ID pops up right next to the image and only one of the images shows up on the 1st one when there should be two.
And when I typed in a term not in the datebase to make sure I get the error message to work, it gives me the undefined variable on line #45 and I'm stuck on how I should define it. Please help.

New Topic/Question
Reply




MultiQuote




|