View Full Version : How do I ask a simple yes/no question in php
Hi,
Can someone please tell me if it is possible for php to ask a simple message dialog where the user clicks on a "yes" or "no" button.
Thanks
Ian Cook
BerksWebGuy
7-6-06, 07:47 PM
Not really. PHP is server-side, so you can't really interact with the visitor/browser (using PHP).
You can use javascript or a form that is submitted.
mingmong
7-13-06, 09:13 PM
BWG is correct, but here is a pretty cumbersome solution that should work if you are avoiding Javascript:
if you are using MySQL with forms, and I'm guessing from your question that you are not, then set a field as ENUM with Yes and No as the only two choices. Even if this seems weighty, you can have a one line form in the appropriate place on your page using the POST method and directing your user right back to the same page. Cumbersome indeed but entirely doable if you are avoiding Javascript. High on the page set the incoming POST variable to null or to a default value, PHP won't care. Then below that collect the incoming value to reset the holding variable to your user's answer. SO:
$yn = "yes";
$yn = $_POST["yn"];
You can then build the parallel functionality in an HTML option type lower on the page:
<table width=25%>
<form method="post" action-="thissamepage.php">
<tr><td>Answer Yes or No</td></tr>
<tr><td><select name="yn">
<option value="yes">Yes
<option value="no">No
</select>
</td></tr>
<tr><td><input type="submit" value="Click"></td></tr>
</form></table>
If you do not need to store the result beyond the session you can skip setting up the MySQL part and just recapture the HTML response. Use MySQL only if you need to store the answer, for example in a client profile, beyond the session.
This is, by the way, how you might implement BWG's "or a form that is submitted" solution.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.