Jump to content
TNG Community

php/mysql


ebelew

Recommended Posts

I'm stumped. Why would I not get any results. I know they're in the database. I get no error just "You did not enter a name to search. Go back and type a string to search" which is the last line of the code.

click here

index.php

<body>

<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

</tr>

</table>

<p align="center">Enter a City to search the database!</p>

<p align="center"><form name="search" method="post" action="search.php">

<input type="text" name="search" size=30 maxlength=30>

<input type="submit" name="Submit" value="Search">

</form></p>

</body>

search.php

<?php

include("connect.php");

if ($search)

{

$search=$_POST["search"];

$result = mysql_query("SELECT * FROM zipcodes WHERE city LIKE '%$search%'");

if ($result)

{

echo "<h4>Here are the results:</h4>";

echo "<table width=90% align=center border=1><tr>

<td align=center bgcolor=#00FFFF>Zip Code</td>

<td align=center bgcolor=#00FFFF>City</td>

<td align=center bgcolor=#00FFFF>State</td>

</tr>";

while($r=mysql_fetch_array($result))

{

$zip=$r["zip"];

$city=$r["city"];

$state=$r["state"];

echo "<tr>

<td>$zip</td>

<td>$city</td>

<td>$state</td>

</tr>";

}

echo "</table>";

} else { echo "problems...."; }

} else {

echo "You did not enter a name to search. <br> Go back and type a string to search";

}

?>

Link to comment
Share on other sites

This is from a working model.


$query = "SELECT * FROM fms_zipcodes WHERE zipcode = '$cst_zip'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$cst_city = $row["city"];
$cst_state = $row["state"];
In your model be sure to limit the search LIMIT 1 or you may obtain the city "Harrisburg" from every state in the Union. I don't see any thing wrong on a quick examination, but it is obvious that you are not getting any results. Run a quick test for any value from the table to be sure you are connected to the table and the table has values. For example,

$query = "SELECT * FROM zipcodes LIMIT 1";

Another idea: Create a $query and echo it before the mysql_query. Also echo the error message if no results are found.

$result = mysql_query($query) or die(mysql_errno() . ":" . mysql_error());

I have a database of zipcodes, cities, and states in the United States. If you need them contact me.

Link to comment
Share on other sites

Thanks. As I am running this from one page (indexold.php) and searching from another page (search.php), I wonder if the search string is ever making it to the search page.

I can run sql statement within the data base and get results. Also, I'm not getting connection errors, so I assume I'm connecting.

Link to comment
Share on other sites

Check all request variables to be sure they are being passed.


foreach( $_REQUEST as $name => $value )
{
      ${$name} = @mysql_real_escape_string($value);
}
echo "$city, $state  $zip";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...