Blade Maker Posted October 28, 2009 Posted October 28, 2009 Someone is teaching me PHP and he is not on right now. He left me with this: and if you want a script to do something when someone clicks a certain button youd go like this <?php switch($_GET['action']) { case 'testfunction': test_function(); break; } function Test_function() { if ($test==1) print "Ze test works!!!"; else die ("Ze test isn't working"); } ?> then whenever the function opened if $test (a variable ) =1 it would say "Ze test works!!!" and if test equaledd anything else it would say "Ze test isn't working. then you could change whats in the Print quotes to change the message and change the $test variable to change what variable its checking. you could also change the =1 to another number or something like > or != which means doesn't equal. now to run this function you could go like this print "<form action='file.php?action=testfunction' method='post'> <input type='submit' value=test function' /></form>"; put that in your file (but outside your function) and it would make a button called "test function" and when clicked it would open the "test_function" function Can someone help explain this? Thanks. Quote
seanybob Posted October 28, 2009 Posted October 28, 2009 RE: Help <?php switch($_GET['action']) { case 'testfunction': test_function(); break; } function Test_function() { if ($_POST['test']==1) print "Ze test works!!!"; else die ("Ze test isn't working"); } print "<form action='file.php?action=testfunction' method='post'> <input type=hidden name=test value=0> <input type='submit' value='Fail button' /></form> <form action='file.php?action=testfunction' method='post'> <input type=hidden name=test value=1> <input type='submit' value='Win button' /></form> "; ?> Stick that in a php file, run it. See what happens. Look at the code. Learn ;) Quote
Blade Maker Posted October 28, 2009 Author Posted October 28, 2009 ?Buttons that do nothing pop up? Quote
Danny696 Posted October 28, 2009 Posted October 28, 2009 seanybob you left out a { and if you want a js popup, use this: <?php switch($_GET['action']) { case 'testfunction': test_function(); break; } function Test_function() { if ($_POST['test']==1) echo'<script type="text/javascript"> function message() { alert("The test works."); } </script> <body onload="message()">'; else if($_POST != 1) { echo'<script type="text/javascript"> function message() { alert("The test doesnt work."); } </script> <body onload="message()">'; } else { print "<form action='file.php?action=testfunction' method='post'> <input type=hidden name=test value=0> <input type='submit' value='Fail button' /></form> <form action='file.php?action=testfunction' method='post'> <input type=hidden name=test value=1> <input type='submit' value='Win button' /></form> "; } ?> Quote
Blade Maker Posted October 28, 2009 Author Posted October 28, 2009 Do I need to download a server? or can I use notepad? Quote
Danny696 Posted October 28, 2009 Posted October 28, 2009 To run it, a sever to look at the code, notepad. Quote
Blade Maker Posted October 28, 2009 Author Posted October 28, 2009 So can I view it without downloading? Quote
Nickson Posted October 30, 2009 Posted October 30, 2009 seanybobs code works fine, he didn't forget a " { ", it's just another way of using if's. @OP html/css/js files can be viewed locally without installing additional software, however if you want to execute php files (or files with php code and later on with a database interaction probably) you do need extra software installed. To achieve this, many people install wampserver, xampp or additional software. Once this is done you can execute php files, and run queries on your computer. Quote
Blade Maker Posted October 31, 2009 Author Posted October 31, 2009 Does anyone have a web host that I can use part of to practice php? Quote
a_bertrand Posted November 1, 2009 Posted November 1, 2009 Kirk: as said, install on your own PC xampp and you will have ALL what you need. Or find a free hosting but that will be for sure lot more complex. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.