Now I know this is something stupid, but once again I just don't see it.
Trying to call several field from a table via a select form.
What tells me that's it's something silly is because when you go to the next page you get an entry, but it pulls the first entry not the One selected from first script.
Here's both scripts..... first is the select page, second is the result page.
<?
// create connection
$connection = mysql_connect("host","user","pass")
or die("Couldn't make connection.");
// select database
$db = mysql_select_db("mydb", $connection)
or die("Couldn't select database.");
// create SQL statement
$sql = "SELECT title FROM journal
ORDER BY title ASC";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$title = $row["title"];
$option_block .= "<OPTION value=\"$title\">$title</OPTION>";
}
?>
<FORM method="post" action="journal-search.php">
<P>Search Journal Entries by Title:<br>
<SELECT name="title-search">
<? echo "$option_block"; ?>
</SELECT>
<P><INPUT type="submit" value="submit"></p>
</FORM>
===============journal-select.php================================
<?php
if ((!$title)) {
header("select.php");
exit;
}
else {
//create connection
$connection = mysql_connect("host","user","pass") or die ("Couldn't connect to the database.");
//select database
$db = mysql_select_db("mydb",$connection) or die ("Couldn't select database.");
//prepare SQL statement
$sql = "SELECT day , title , rant FROM journal LIKE '$title' LIMIT 1 ";
//execute SQl queries and exit if failure at any query
$sql_result = mysql_query($sql,$connection) or die ("Sorry your search showed no results!");
echo "<ul>";
while ($row = mysql_fetch_array($sql_result)) {
$search_result_day = $row["day"];
$search_result_title = $row["title"];
$search_result_rant = $row["rant"];
echo "<table border=\"4\"><td align=\"left\">$search_result_day </td></tr><tr><td align=\"center\">$search_result_title </td></tr><tr><td align=\"center\">$search_result_rant</td></tr></table>\n";
}
}
?>
Here is the working example.
http://www.citystylecreations.com/forms/select.php
~Peace~
Gary
http://citystylecreations.com