I am writing a PHP script to add data to a MySql database.
There is an input form to add the data and a Captcha before posting.
If the Captcha is entered correctly, everything works fine and the data is added to the database.

However, if the Captcha is entered incorrectly, the script re-directs to a resend page which loads up the data that was input on the original input page.
This is the part that does not work correctly.

It appears to me that anything in a 'Textarea' displays in the resend form OK, but in an input box, it will only display up to the first 'space'.
Also, in a Textbox, the resend form will only display up to '&' and nothing after it.

Can anybody advise what is wrong with my coding ???

Thanks,

04-19-2013, 04:05 PM

Fou-Lu

Quote:

Originally Posted by countrydj

It appears to me that anything in a 'Textarea' displays in the resend form OK, but in an input box, it will only display up to the first 'space'.

Which is normal. That is an HTML issue, not a PHP one. Check the HTML source generated; so long as data is within the value= section of the input, than PHP has done its job. You need to correct the HTML which requires quotations around attributes with spaces.

04-19-2013, 04:38 PM

countrydj

Many thanks, Fou-Lu..

That worked fine.

However, when a & is included in the data, the resend stops there.

e.g.

Input: Robert & Sharon --- Resend: Robert

Input: Robert and Sharon --- Resend: Robert and Sharon.

Have you any idea why this is, or should I repost on the HTML forum ???

Thank you...

04-19-2013, 04:41 PM

Fou-Lu

I would presume that still has to do with the spaces. Best I know & is valid within a form value. Otherwise, wrap it in htmlentities to convert it to &amp;.

04-19-2013, 05:44 PM

countrydj

Quote:

Originally Posted by Fou-Lu

I would presume that still has to do with the spaces. Best I know & is valid within a form value. Otherwise, wrap it in htmlentities to convert it to &amp;.

Thanks for your reply.

I have done some testing and the problem is to do with '&' not spaces.

I have googled "wrap it in htmlentities to convert it to &amp;. ", but I cannot see how to solve my problem.
It would be very easy if I was doing the coding, but the form is for 'Users' to be able to input their own data.

What I can't understand is that there is no problem with '&' if the Captcha is input correctly. The data, as input, is inserted into the database. But there is when it is input incorrectly.
The forms are the same, but with the data already displayed for the user.
If the User just input the Captcha correctly, the data would be wrong.

You're re-requesting the page via header location. & is defined as the querystring separator, so it considers the next half to be that of a new variable. Use urlencode() on the values prior to sending them. Alternatively, use http_build_query and give it an array and it will automatically issue the urlencode.

04-19-2013, 08:02 PM

countrydj

Quote:

Originally Posted by Fou-Lu

You're re-requesting the page via header location. & is defined as the querystring separator, so it considers the next half to be that of a new variable. Use urlencode() on the values prior to sending them. Alternatively, use http_build_query and give it an array and it will automatically issue the urlencode.

Hi Fou-Lu...
Thank you very much for your advice.

However, I have no idea how to do either of your suggestions.

I have googled both of your suggestions and I can't understand how to do it.

Can you advise me how it's done ???

Regards,

04-19-2013, 09:09 PM

Fou-Lu

You specify each of the variables before the location header wrapped in urlencode:

PHP Code:

$officers = urlencode($officers);

Or, as I'd suggest a better approach, use http_build_query with all of the variables:

I have tried both of the above suggestions, and they both work fine for me.

The first one is so simple when you know how.

I felt the the second one was a little more difficult, but that may well have been because I had to think about the final coding.
However, it is something new to me, so it will be very useful in building an array, in other projects.

I would be very interested to know WHY you prefer the second suggestion.