Click here to Skip to main content
15,902,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't seem to get my php echo to display more than one word from my form. It seems to simply stop echoing once it encounters a space. I can't seem to find an answer via google, so I'm hoping my good friends here can help.

Here is my form:
HTML
<pre lang="xml"><form <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td width="170px" rowspan="6"></td>
<td width="100px">Comic Book Name:
</td>
</tr>
<td height="25px"><input type="text" id="title" name="title" value="<?php echo $title; ?>">
</td>
</tr>
<tr>
<td>Comic Book Issue:
</td>
</tr>
<td><input type="text" id="issue" name="issue">
</td>
</tr>
<tr>
<td height="15px">
</td>
</tr>
<tr>
<td><input type="submit" name="search" id="search" value="Find My Comic!">
</td>
</tr>
</form>
</pre>

Then once the form is submitted it will populate some links based on the form below:
<pre lang="PHP">
</pre>
<?php
if($_POST['title'] || $_POST['issue'] != NULL) {
//Row 1
echo "<tr>";
// My Comic Shop
echo "<td width=170px><a target=blank href=http://www.mycomicshop.com/search?q=".htmlspecialchars($_POST['title'])."+".htmlspecialchars($_POST['issue'])."&pubid=&PubRng=>My Comic Shop</a></td>";
// Ebay
echo "<td width=170px><a target=blank href=http://www.ebay.com/sch/".htmlspecialchars($_POST['title'])."%20".htmlspecialchars($_POST['issue']).">Ebay</a></td>";
// Comic Connect
echo "<td width=170px><a target=blank href=http://www.comicconnect.com/bookSearch.php?title=".htmlspecialchars($_POST['title'])."&issue=".htmlspecialchars($_POST['issue']).">Comic Connect</a></td>";
//End Of Row 1
echo "</tr>";
}
else {
// For Page Centering Consistency
echo "<tr><td width=170px></td><td width=170px></td><td width=170px></td></tr>";
}
?>


As it is now, if I input 'doctor strange' into the Comic Book Name field, the My Comic Shop echo, returns:

'http://www.mycomicshop.com/search?q=doctor'


Any help would be appreciated! Thank you!



Jerome
Posted

I figured it out. I just did a simple str_replace to change the ' ' to '%20'.

Here's the ehco string that works:

echo "<td width="170px"><a target="blank" href="http://www.mycomicshop.com/search?q=".str_replace('" title="]))."+".htmlspecialchars($_POST[" issue="])."&pubid=&PubRng=>My Comic Shop</a></td>";<br mode="hold" /></pre><br mode="hold" /><br mode="hold" /><br mode="hold" />Jerome</xml>"></a></td>
 
Share this answer
 
You need quotes for the href, either single or double.

Like this:
PHP
$title = urlencode($_POST['title']);
$issue = urlencode($_POST['issue']);
echo "<a href=\"http://www.mycomicshop.com/search?q={$title}+{$issue}&pubid=&PubRng=\">My Comic Shop</a>";

Also use urlencode() instead of htmlspecialchars().

Cheers.

Edited: Removed quotes added by CodeProject automatically.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900