please help with urlencode
Posted: Sun Nov 02, 2008 11:04 pm
I am having trouble passing a variable in a URL (the row 'id' is actually a phone number XXX-XXX-XXXX). I am under the impression that I need to use the urlencode feature. I cannot figure out how to include it in this url. I do not know the syntax to use. I have verified that the query works in mySQL and the query works if there are no hyphens. Your assistance is greatly appreciated!
Code: Select all
<?php
$search = $_GET['searchFor'];
$words = explode(" ", $search);
$phrase = implode("%' AND account LIKE '%", $words);
$query = "SELECT id,account,address1,city,state,zip from customers where account like '%$phrase%'";
$result = mysql_query($query) or die('Could not query database at this time');
echo "<h1>Search Results</h1><br><br>\n";
if (mysql_num_rows($result) == 0)
{
echo "<h2>Sorry, no accounts were found with '$search' in them.</h2>";
} else
{
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$id = $row['id'];
$account = $row['account'];
$address1 = $row['address1'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
echo "<a href='index.php?content=showaccount&id=$id'>$account</a><br>\n";
echo "$address1<br>\n";
echo "$city $state $zip<br><br>\n";
}
}
?>