homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Searching MySQL DB using Drop Menu in PHP
Need a little help getting it to call the information.
OneSlickMerc

5+ Year Member



 
Msg#: 3558852 posted 9:05 pm on Jan 26, 2008 (gmt 0)

I am having trouble getting the DB to call the information back to the page. I am calling information from an abbreviation such as a state to get all the information back to display. Here is part of the code as follows:

<form name=\"state_search\" action=\"search/state_search.php\" method=\"post\">

<p>Please choose your state: </p>

<SELECT name=\"state_search\" size=\"1\" HEIGHT = \"22\" WIDTH = \"50\">
<OPTION value=\"-1\">-</option>

<OPTION value=\"FL\">FL</option>

</SELECT>

<input type=\"submit\" />

------------------------------------------

Here is the state_search.php

as follows:

<?
if ($search)
{
mysql_connect() or die ("Problem connecting to Database");

$query = "select * from search WHERE state_abbreviation='$search'";

$result = mysql_db_query("state_search", $query);

if ($result)
{
echo "Here are the results:<br><br>";

while ($r = mysql_fetch_array($result)) { // Begin while
$ts = $r["TimeStamp"];
$state_abbreviation = $r["state_abbreviation"];
$name = $r["name"];
$city = $r["city"];
$zip = $r["zip_code"];
echo "<tr>
<td>$ts</td>
<td>$name</td>
<td>state_abbreviation</td>
<td>$city</td></tr>
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$zip</td>
</tr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
?>

 

maxximus

5+ Year Member



 
Msg#: 3558852 posted 9:36 pm on Jan 26, 2008 (gmt 0)

First unless theres part of your script missing you need
$search = $_POST['state_search'] at top of search.php

Mysql_connect contains no arguments so it will only be able to attempt a default connection.

Also mysql_db_query is deprecated - use mysql_select_db .

Basic connect script here [uk.php.net...]

OneSlickMerc

5+ Year Member



 
Msg#: 3558852 posted 3:11 am on Jan 27, 2008 (gmt 0)

that didn't help. i have the database connected with a connect.php

Mohamed

5+ Year Member



 
Msg#: 3558852 posted 7:41 am on Jan 27, 2008 (gmt 0)

<form name=\"state_search\" action=\"search/state_search.php\" method=\"post\">
<SELECT name=\"state_search\" size=\"1\" HEIGHT = \"22\" WIDTH = \"50\">

your form and select have same name which is bad practice though it has nothing to do with your problem.

if ($search){

$search is not defined and has a null value, you should assign $search to whatever you got from the form.
try this it may help.

$search = $_post['state_search'];
if(!empty($search)){
//connect to database
mysql_connect("host", "user", "password");
mysql_select_db("database");
$sql = "SELECT * FROM table WHERE state_abbreviation='$search'";
$result = mysql_query($sql);
if($result){
while($r = mysql_fetch_array($result){
//do some stuff here
}
}
}

infinitylimit

5+ Year Member



 
Msg#: 3558852 posted 11:42 am on Jan 27, 2008 (gmt 0)

A thing to try is in your sql where statement I would try adding a WHERE state LIKE '*".$state."*';

[edited by: jatar_k at 12:53 pm (utc) on Jan. 27, 2008]
[edit reason] no urls thanks [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved