Forum Moderators: coopster

Message Too Old, No Replies

index.php?rate=45

mysql and php help please!

         

PokeTech

5:03 pm on Apr 10, 2008 (gmt 0)

10+ Year Member



Once again I'm in need of help... What I'm trying to figure out how to do this time is make like a form with a text box and a search button but then when the user enters a number it places that in the url so if they enter "45" it goes to index.php?rate=45. And then I was wondering how you get a page to grab information for something so lets say someone entered 50 and it took them to index.php?rate=50 then on that page I want to know how to display the data from a table where rate=50.

I was hoping something like this would work:

// get contact id
$rate = $_GET['rate'];
if (!empty($rate)) { $_SESSION['recordrate']=$rate; }
else { $rate = $_SESSION['recordrate']; }

$query = "SELECT * FROM table WHERE rate='$rate'";
$result = $database->query($query);
$dex = $result->fetchRow(DB_FETCHMODE_ASSOC,0);
$database->disconnect();

But I can't seem to find a way. Anybody have any ideas on how to do this? If it makes since.

eelixduppy

8:59 pm on Apr 15, 2008 (gmt 0)



First off, you have to start the session, I don't see where you did that anywhere. Use session_atart [php.net]() for that.

Also, you have not connected to a db from what I can see. You might want to take a look at the following thread to see how to do that: [webmasterworld.com...]

Other than that, though, you have the general idea. Just note, that you should be escaping the $rate variable before you use it within the query, and also checking to see if it is an integer, just so that your application doesn't fail because of incorrect input or a malicious attempt to hack your db. Look at mysql_real_escape_string [php.net]()