The most bizarre problem I've ever encountered: text box and mysql_close()
| From: | Daniel H | Date: | Wed, 27 Dec 2000 05:01:48 +0000 |
| Subject: | The most bizarre problem I've ever encountered: text box and mysql_close() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-31918@lists.php.net to get a copy of this message | ||
I have a script with a form that includes a drop-down
menu, a text box, and a submit button. When I add
mysql_close() later in the file, the submit button's
variable won't be passed unless the text box is
removed. The code is:
<form action="book_search.php" method="get">
<select name="search_option">
<option>Title
<option>Author
</select>
<!--this is the text box-->
<input type="text" name="search_field">
<input type="submit" name="submit" value="Search">
</form>
<?
if($submit){
include "incs/dbvars.inc";
$search_field=ereg_replace("'", "\'",
trim($search_field));
if($search_option=="Title"){
$query="SELECT user.alias, user.email, book.title,
book.author, book.genre, book.book_id as bid
FROM user, book
WHERE book.keeper_email IS NULL
AND book.title LIKE '%$search_field%'
AND user.user_id = book.user_id
ORDER BY author, title";
$links="search=1&search_option=title&search_field=$search_field";
}
elseif($search_option=="Author"){
$query="SELECT user.alias, user.email, book.title,
book.author, book.genre, book.book_id as bid
FROM user, book
WHERE book.keeper_email IS NULL
AND book.author LIKE '%$search_field%'
AND user.user_id = book.user_id
ORDER BY author, title";
$links="search=1&search_option=title&search_field=$search_field";
}
elseif($genre){
$query="SELECT user.alias, user.email, book.title,
book.author, book.genre, book.book_id as bid
FROM user, book
WHERE book.keeper_email IS NULL
And book.genre = '$genre'
AND user.user_id = book.user_id
ORDER BY author, title";
$links="search=1&genre=$genre";
}
else{
$query="SELECT user.alias, user.email, book.title,
book.author, book.genre, book.book_id as bid
FROM user, book
WHERE book.keeper_email IS NULL
AND user.user_id = book.user_id
ORDER BY author, title";
$links="search=1";
}
$display_number=10;
if(!$page) $page=1;
$display_base=($page-1)*$display_number;
if(!$result=mysql_query($query,$connID)) echo
"shit.";
$num_rows=mysql_num_rows($result);
if($num_rows == 0) echo "No matches were found.\n";
else{
if($display_base > $num_rows || $display_base < 0)
$display_base=0;
mysql_data_seek($result, $display_base);
echo "<table>\n";
for($i=0; $i<$display_number &&
$i<$num_rows-$display_base; $i++){
$book=mysql_fetch_array($result);
echo " <tr>\n";
echo " <td>$book[title]</td>\n";
echo " <td>$book[author]</td>\n";
echo " <td>$book[genre]</td>\n";
echo " <td><a
href=\"mailto:$book[address]\">$book[alias]</a></td>\n";
echo " <td><a
href=\"checkout.php?bid=$book[bid]&book_title=$book[title]&author=$book[author]&user_email=$book[email]&alias=$book[alias]\">check
out</a></td>\n";
echo " </tr>\n";
}
echo " <tr><td align=\"center\">\n";
//"back" link
if($page > 1){
/*this is something else i had a problem with- i
couldn't put $page-1 where $back is in the echo
statement*/
$back=$page-1;
echo " <a
href=\"book_search.php?".$links."&page=".$back."\">Back</a>\n";
}
//To test for "next" link
if($num_rows - $display_base > $display_number){
$next=$page+1;
echo " <a
href=\"book_search.php?".$links."&page=".$next."\">Next</a>\n";
}
echo " </td></tr>\n";
echo " </table>\n";
//this is where mysql_close() would go.
}
}
Also, if any tips could be offered on optimizing this
code, I'd appreciate it... I'm relatively new to PHP
and programming in general, so I don't yet know all
the nifty shortcuts.
Thanks,
Daniel H
?>
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/