Jump to content

Magic 8 ball


Aphp73

Recommended Posts

    Hey all, I'm a noob PHP programmer who is trying to make a Magic 8-ball application. I have a login form page that takes the user to the 8 ball after they enter there name. The next part I'm having problems starting. I don't have a clue as to how to keep the user at the 8-ball page. I could code this buy making a form on one page and moving the user to the answer page.
    I tryed using a function and call it using the onclick event of a button. I'm not sure if php even uses the onclick event of a html form. I'm going to use $_Session to do this application, but don't know how to keep the user at the 8-ball page after loggin in.
    Thanks for any help, its sorely needed.
Link to comment
https://forums.phpfreaks.com/topic/27063-magic-8-ball/
Share on other sites

It doesn't matter whether you use $_GET or $_POST. Those are both simply methods of passing information to the receiving page. Which page you are sent to is up to the [b]action[/b] of the form itself. If you leave it blank or use $_SERVER['PHP_SELF'], you'll send the form to the page itself. Then, you can use an if() statement to handle it. Try something like this:
[code]
<?php
// Process if the form has been submitted
if (isset($_POST['submit'])) {
  // form has been sent, use your processing here
}

// always output the form itself
echo "<h1>Ask a Question</h1>\n";
echo "<form name=\"8Ball\" action=\"\" method=\"post\">\n";
echo "<input type=\"text\" name=\"question\" />\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Ask!\" />\n";
echo "</form>\n";
?>
[/code]

Hope this helps
Link to comment
https://forums.phpfreaks.com/topic/27063-magic-8-ball/#findComment-124040
Share on other sites

just set the form to go to itself.

set a hidden variable in your form somehting like 'process'.

then at the begining of the page check to see if $_POST['process'] exists

$res = '';
if(isset($_POST['process'])){

put your processing data here

}

display your output from the processing and then your form again

$res = your results
$form = your form

echo $res.$form;
Link to comment
https://forums.phpfreaks.com/topic/27063-magic-8-ball/#findComment-124042
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.