PHP form question-link a button to url

Hello Experts,
     I am a PHP beginner and I am trying to create a simple form in php page.
I made a form with html and when I click a submission button, it goes to a php page.
In that page, I would like to create buttons, one is if a user input info from html page is correct, click "Yes" and then goes to another page, stating thank you.  Another button is "No", which means input info is not right and go back to the first html form.

     Up to display the user input info, I'm doing fine.  But somehow, once I add the last part of the code, it stops working and get a blank page.
     The code I have an issue is as follows:

print "<p>If this is correct, click <input type="button" onclick="location.href('url')" value="Yes" />. 
Otherwise, click <input type="button" onclick="location.href('url')" value="No" /></p>";

Open in new window

     If I comment out the above code, the PHP page works fine.  But I would like to add an additional function on my form.  
     I might be doing totally wrong, as I don't have coding brains, but I really appreciate if someone let me know what part I am not doing right and how to solve my problem.

     Thank you in advance.
Who is Participating?
Marco GasiConnect With a Mentor FreelancerCommented:
If you don't escape double quotes, php engine will think that your string ends at the next double quotes, that is at the <input type= All the rest of your code will be treated as an error. Since probably you have no set properly error displaying, you get a blank page. At the top of your script it's convenient to put these two lines (but only in development environment: don't forget to delete them in your production web site in order to avoid to give useful informations about your code to bad guys):

ini_set('display_errors', 'On');

Open in new window

You might also consider to use heredoc notation:

echo <<<FRM
<p>If this is correct, click <input type="button" onclick="location.href('url')" value="Yes" />. 
Otherwise, click <input type="button" onclick="location.href('url')" value="No" /></p>;

Open in new window

This way you'll avoid to worry about escaping quotes when you'll print forms and other strings. Please, be careful with the big pink warnin in the Php man page to avoid errors.

Marco GasiFreelancerCommented:
You have to escape double quotes

print "<p>If this is correct, click <input type=\"button\" onclick=\"location.href('url')\" value=\"Yes\" />.
Otherwise, click <input type=\"button\" onclick=\"location.href('url')\" value=\"No\" /></p>";
sabregirlAuthor Commented:
Thank you so much for your quick responses, marqusG!
I set error_reporting(E_ALL & ~E_NOTICE); on my codes, but I guess it's  not enough...
I knew that I need to escape double quotes, but I didn't think about that also applies to even in my input type...  I need to pay more attention when I write some codes...
Thank you again for your help.  I really appreciate it :)
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Marco GasiFreelancerCommented:
Glas to help you: when we're writing code the attention is never enough - it looks like a James Bond movie title ;)

Thanks for points and good luck with your project.
Marco GasiFreelancerCommented:
Have you seen? I wrote 'Glas' instead of 'Glad': the attention is never enough indeed!!!
sabregirlAuthor Commented:
You are so nice to a beginner, Marco :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.