Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Question, Should be REALLY easy

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
0
0
US
I have the following code,

$test=$userContact['firstName']."|".$userContact['lastName']."|".$userContact['universityEmail']."|".$userContact['address1']."|".$userContact['city']."|".$userContact['state']."|".$userContact['zip']."|".$userContact['phonea']."|".$userContact['address2']."|".$userContact['phoneb']."|".$userContact['phonec']."|".$userContact['org_code1'];

print(&quot;<input type='hidden' name='oldUserInfo' value='$test'>&quot;);

My problem comes when a user inputs a ' in any of the userContact fields, it automatically cuts off the rest of the fields from being included. Is there a easy way around this?? I tried using double quotes around value= but that did not work, THANKS!
 
Did you try...
print '<input type=&quot;hidden&quot; name=&quot;oldUserInfo&quot; value=&quot;$test&quot;>';

Or is that what you meant by double quotes?

That said... where's it cutting off the values? When you later try to read oldUserInfo from a form submission or javascript check, or when you view source and look at your hidden tag?

-Rob
 
sorry for not being clear enough. Yes that is what i meant by double quotes. The string is cutting off where the ' (single quote) is located. I am using the form variable on the action page.

this is my &quot;View Code&quot; from when i use single quotes:

<input type='hidden' name='oldUserInfo' value='Kirk's|kirk@hotmail.com|221 20th Avenue|Cedar Falls|IA|50613|'>

As you can see the ' in Kirk's is screwing the code up.

this is my &quot;View Code&quot; from when i use double quotes:

<input type='hidden' name='oldUserInfo' value=

with this error on the page:

Parse error: parse error in C:\InetPub\ on line 241
<input type='hidden' name='oldUserInfo' value=
 
Try:

print(&quot;<input type=\&quot;hidden\&quot; name=\&quot;oldUserInfo\&quot; value=\&quot;$test\&quot;>&quot;);
 
Or, to be more correct to the HTML spec (which does specify that the values of attributes be in double quotes):

print '<input type=&quot;hidden&quot; name=&quot;oldUserInfo&quot; value=&quot;' . $test . '&quot;>';

The parentheses around your print value are unnecessary. print is not a function, but an intrinsic part of the PHP engine.
Want the best answers? Ask the best questions: TANSTAAFL!
 
Oh geeze, exactly as Sleipnir said... my method for double quotes wouldn't work at all. Variables are not expanded within single quotes.

My apologies...

-Rob
 
you could swap quotes for &quot; (the html equiv) --BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top