bluez26 Posted February 18, 2008 Share Posted February 18, 2008 Hey I'm new to php ... obviously lol ... anyway I'm having a hard time getting this code to work. It's for a hw assignment in my class and we have to use a function to calculate a part of a form. Every time I try to incorporate this function/call it or whatever I end up getting a blank page when I click the submit button on the page. Someone please help me! I am completely lost here. function HourlyRate($_GET["THrs"], $_GET["Rate"]){ $TotHrs = $_GET["THrs"]; $PRate = $_GET["Rate"]; If($TotHrs <= "40") $HRate = ($TotHrs * $PRate); else $HRate = ("40" * $PRate) + (($TotHrs - "40") * ($PRate * "1.5")); echo $HRate; } echo "<p>Employee Last Name: ", $_GET["EmpName"], "</p>"; echo "<p>Employee SSN: ", $_GET["EmpSSN"], "</p>"; echo "<p>Employee Status: ", $_GET["EmpStat"], "</p>"; echo "<p>Week Beginning: ", $_GET["BDate"], "</p>"; echo "<p>Hours Worked: ", $_GET["THrs"], "</p>"; echo "<p>Pay Rate: ", $_GET["Rate"], "</p>"; echo "<p>Gross Pay: "; If ($_GET["EmpStat"] == "Exempt") echo $_GET["THrs"] * $_GET["Rate"] else HourlyRate($_GET["THrs"], $_GET["Rate"]); Please help! Quote Link to comment Share on other sites More sharing options...
btherl Posted February 18, 2008 Share Posted February 18, 2008 Can you post the code for the form? If you are using post method in the form, then you must check $_POST instead of $_GET (or $_REQUEST, which includes both methods) Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 Post your Form Try function HourlyRate($thrs,$rate){ $TotHrs = $thrs; $PRate = $rate; If($TotHrs <= 40){ $HRate = ($TotHrs * $PRate); } else { $HRate = (40 * $PRate) + (($TotHrs - 40) * ($PRate * 1.5)); } return $HRate; } $hrate = HourlyRate($_GET['THrs'],$_GET['Rate']); echo $hrate; Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 It still won't work I changed my function like you have it there and put this in as part of the IF statement and it still gives me a blank page... If ($_GET["EmpStat"] == "Exempt") echo $_GET["THrs"] * $_GET["Rate"] else $hrate = HourlyRate($_GET['THrs'],$_GET['Rate']); echo $hrate; I'm not using any $_POST or anything like that in my form, just the "get" method. Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 OH scratch that.. I forgot the brackets.. lemme try again Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 Still not working ??? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 i think we still need your FORM code (submittion code). I think the problem (without the form code) is that your trying to use $_GET variables (these variables are in the browser URL as a "Query String") Most Form use "Method=post", therefor you should change all of your $_GET vars to $_POST vars as btherl explained earlier. Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 Well my teacher left us the source code for the form and he's using the get method but here's what i have: <form method="get" action="Proj2.php"> <table width="600px"><tr><td> <strong>Employee Name:</strong> </td><td colspan="3"> <input name="EmpName" type="text" style="width:300px;" /> </td></tr> <tr><td> <strong>Employee SSN:</strong> </td><td> <input name="EmpSSN" type="text" style="width:100px;" /> </td><td> <strong>Employee Status:</strong> </td><td> <input name="EmpStat" type="radio" value="Exempt" checked="checked" style="border:0px;" /> Exempt <input name="EmpStat" type="radio" value="Hourly" style="border:0px;" />Hourly </td></tr> <tr><td> <strong>Week Begining:</strong> </td><td> <input name="BDate" type="text" style="width:100px;" /> </td><td> <strong>Total Hours:</strong> </td><td> <input name="THrs" type="text" style="width:100px;" /> </td></tr> <tr><td> <strong>Pay Rate:</strong> </td><td> <input name="Rate" type="text" style="width:100px;" /> </td></tr> <tr><td colspan="4"> <input name="reset" type="reset" value="Reset" /> <input name="submit" type="submit" value="Submit" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 try <?php function HourlyRate($thrs,$rate){ $TotHrs = $thrs; $PRate = $rate; If($TotHrs <= 40){ $HRate = ($TotHrs * $PRate); } else { $HRate = (40 * $PRate) + (($TotHrs - 40) * ($PRate * 1.5)); } return $HRate; } echo "<p>Employee Last Name: ", $_POST["EmpName"], "</p>"; echo "<p>Employee SSN: ", $_POST["EmpSSN"], "</p>"; echo "<p>Employee Status: ", $_POST["EmpStat"], "</p>"; echo "<p>Week Beginning: ", $_POST["BDate"], "</p>"; echo "<p>Hours Worked: ", $_POST["THrs"], "</p>"; echo "<p>Pay Rate: ", $_POST["Rate"], "</p>"; echo "<p>Gross Pay: "; If ($_POST["EmpStat"] == "Exempt"){ echo $_POST["THrs"] * $_POST["Rate"]; } else{ $hrate = HourlyRate($_POST['THrs'],$_POST['Rate']); echo $hrate; } ?> Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 That's gotten me somewhere but it's not pulling the information from the form now.. do I have to change something in my form ? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 in the form html change the <form method="get" to <form method="post" Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 That's gotten me somewhere but it's not pulling the information from the form now.. do I have to change something in my form ? Change form to <form method="post" action="Proj2.php"> <table width="600px"><tr><td> <strong>Employee Name:</strong> </td><td colspan="3"> <input name="EmpName" type="text" style="width:300px;" /> </td></tr> <tr><td> <strong>Employee SSN:</strong> </td><td> <input name="EmpSSN" type="text" style="width:100px;" /> </td><td> <strong>Employee Status:</strong> </td><td> <input name="EmpStat" type="radio" value="Exempt" checked="checked" style="border:0px;" /> Exempt <input name="EmpStat" type="radio" value="Hourly" style="border:0px;" />Hourly </td></tr> <tr><td> <strong>Week Begining:</strong> </td><td> <input name="BDate" type="text" style="width:100px;" /> </td><td> <strong>Total Hours:</strong> </td><td> <input name="THrs" type="text" style="width:100px;" /> </td></tr> <tr><td> <strong>Pay Rate:</strong> </td><td> <input name="Rate" type="text" style="width:100px;" /> </td></tr> <tr><td colspan="4"> <input name="reset" type="reset" value="Reset" /> <input name="submit" type="submit" value="Submit" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 FYI your problem i believe was your Function had syntax errors, which php ended the script, it seems your php installation doesn't "display_errors". Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 try putting ini_set('display_errors', 1) at the top of your script Quote Link to comment Share on other sites More sharing options...
bluez26 Posted February 18, 2008 Author Share Posted February 18, 2008 Yeah I'm not sure why the get method won't work for me and will for my teacher's script but the post one is working perfectly. Thank you all for your help I really appreciate it! Quote Link to comment Share on other sites More sharing options...
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.