Friday, November 20, 2009

How can you pass spaces in a php query string? (ie "Tony Smith" - there's a space bet

THIS STRING WORKS OK:



http://www.mysite.com/sendmail.php?realn...



WITH THIS CODE:



%26lt;form method="post" action="http://mysite.com/cgi-bin/sendma... %26lt;p%26gt;



To:%26lt;br%26gt;%26lt;input type="text" value=%26lt;?php echo $_GET['realname']; ?%26gt; name="realname" size="60" /%26gt;



To E-Mail Address: %26lt;br%26gt;%26lt;input type="text" value=%26lt;?php echo $_GET['username']; ?%26gt; name="username" size="60" /%26gt;



From E-Mail Address: %26lt;br%26gt;%26lt;input type="text" value=AskTony@mysite.com name="fromurl" size="60" /%26gt;



Subject: %26lt;br%26gt;%26lt;input type="text" value="Work Wanted" name="subjectline" size="60" /%26gt;



Salutation: %26lt;br%26gt;%26lt;input type="text" value=%26lt;?php echo $_GET['salutation']; ?%26gt; name="salutation" size="60" /%26gt;



%26lt;p%26gt;



Message:



%26lt;textarea name="comments" cols="48" rows="8"%26gt;



Insert Message Here



%26lt;/textarea%26gt;%26lt;/p%26gt;



%26lt;p%26gt;



%26lt;input type="submit" value="Send"/%26gt;???%26lt;input type="reset" value="Start Over" /%26gt;



%26lt;/p%26gt;%26lt;/form%26gt;



BUT NOT SPACES LIKE "realname=Tony Smith"



How can you pass spaces in a php query string? (ie "Tony Smith" - there's a space between Tony and Smith)microsoft live



Well if this is a copy+paste from your code, then the problem here is likely the lack of quotes (") around the value attribute of your realname input box.



You have it like this:



%26lt;input type="text" value=%26lt;?php echo $_GET['realname']; ?%26gt; name="realname" size="60" /%26gt;



but it SHOULD be like this:



%26lt;input type="text" value="%26lt;?php echo $_GET['realname']; ?%26gt;" name="realname" size="60" /%26gt;



Notice the double-quote (") glyph right before %26lt;? and right after ?%26gt;.



When HTML renders the form, it will encounter that space and freak out a little bit. The exact behavior may vary depending on your browser, but needless to say, it won't work like you're expecting. When you enclose the value in quotes, it will read the entire value without a problem.



You have the same issue with a few other boxes as well:



username



fromurl



salutation



It is good practice to always use quotes for the attribute values inside your HTML tags. A lot of lazy coders will decide not to use them, but then there are problems like this popping up.



Good luck my friend! I hope this helps you.

No comments:

Post a Comment

 
computer repair