Hi Folks,
I looked through the manual for a while today concerning a problem I encountered while working on my first real PHP project. I want to pass a value from the file "drinks.php" back to "drinks.php" for processing depending on what the user clicks. The problem that I am incurring is that when I send the value "Long Island Iced Tea" with an "a href" command, the string turns into "Long%20Island%20Iced%20Tea". Now this is presenting a problem when I query my database for this value. Is there a way to strip the %20's from the string and replace them with normal spaces? Any help is appreciated.
The PHP code for my problem is listed below.
<?php
if($_GET['query'])
{
echo "This Page has a database query attached to it";
$link = mysql_connect("localhost", "xxxx", "xxxxxx") or die("Could not Connect!");
mysql_select_db("xxxxx") or die("Could not select database!");
$category = $_GET['query'];
$query = "SELECT name FROM drinks WHERE category='$category'";
$result = mysql_query($query) or die("Could not perform the query");
/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td><a href = \"drinks.php?drinkname='$col_value'\">$col_value</a></td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
}
else
if($_GET['drinkname'])
{
$drink = $_GET['drinkname'];
$link = mysql_connect("localhost", "xxxx", "xxxxxx");
mysql_select_db("xxxxx") or die("Could not select database!");
$query = "SELECT * FROM drinks WHERE name='$drink'";
$result = mysql_query($query) or die("Could not perform the query");
/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
}
?>