BetaONE will rise again!


Reply
  #1  
Old 25th Jun 03, 07:26 PM
adams adams is offline
Super Moderator
 
Join Date: Jul 2001
Posts: 1,124
adams is an unknown quantity at this point
bought a book to help me learn php. i type the code directly from the book and save it in the root directory on my computer, but then when i type in the address in my browser, the page will load but not work like it is supposed to.

here is the code for both pages. (its just a simple calculation script).
calculate.php:
Code:
<? if (($_POST[val1] == "") || ($_POST[calc] =="")) { header("Location: http://127.0.0.1/calculate_form.html"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2]; } ?> <HTML> <HEAD> <TITLE> Calculation and Result</TITLE> </HEAD> <BODY> <P>The result of the calculation is: <? echo "$result"; ?></P> </BODY> </HTML>
calculate_form.html:
Code:
<HTML> <HEAD> <TITLE>Calculation Form</TITLE> </HEAD> <BODY> <FORM METHOD="POST" ACTION="calculate.php"> <P>Value 1: <INPUT TYPE="text" NAME="val1" SIZE=10></P> <P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P> <P><Calculation:<br> <INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br> <INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br> <INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br> <INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</P> <P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P> </FORM> </BODY> </HTML>
whenever i enter the two values in the blanks and choose to add (or whatever) and click submit, the page just reloads itself.
thanks in advance.
__________________
Camera Equipment:
Canon 40D & Digital Rebel XT
Canon 500mm L IS USM
Canon 100-400mm L IS USM
kit lens
Sigma 70-300mm APO DG
Canon 430 EX Speedlight
Dynatran Tripod
Lowepro Mini Trekker AW backpack
Reply With Quote
  #2  
Old 25th Jun 03, 07:49 PM
billybob3's Avatar
billybob3 billybob3 is offline
Senior Member
 
Join Date: Apr 2003
Location: Earth
Posts: 577
billybob3
Send a message via AIM to billybob3 Send a message via MSN to billybob3
Do you have PHP installed???
Reply With Quote
  #3  
Old 25th Jun 03, 08:36 PM
adams adams is offline
Super Moderator
 
Join Date: Jul 2001
Posts: 1,124
adams is an unknown quantity at this point
yes, i installed phptriad which installs php, mysql, and apache. (it also configures everything). and yes i had apache running also.
__________________
Camera Equipment:
Canon 40D & Digital Rebel XT
Canon 500mm L IS USM
Canon 100-400mm L IS USM
kit lens
Sigma 70-300mm APO DG
Canon 430 EX Speedlight
Dynatran Tripod
Lowepro Mini Trekker AW backpack
Reply With Quote
  #4  
Old 26th Jun 03, 02:21 AM
billybob3's Avatar
billybob3 billybob3 is offline
Senior Member
 
Join Date: Apr 2003
Location: Earth
Posts: 577
billybob3
Send a message via AIM to billybob3 Send a message via MSN to billybob3
Oh, ok, well, that's the only reason that I can think of. Sorry!
Reply With Quote
  #5  
Old 26th Jun 03, 02:30 AM
Sephiroth Sephiroth is offline
BetaONE Supporter
 
Join Date: Jul 2001
Posts: 1,979
Sephiroth is an unknown quantity at this point
Send a message via MSN to Sephiroth
try to comment out this part of your script like this:

//if (($_POST[val1] == "") || ($_POST[calc] =="")) {
//header("Location: //http://127.0.0.1/calculate_form.html");
//exit;
//}

then run it and see what happens, i think something is wrong in that piece of code there and it's just reloading calculate_form.html instead of executing the rest of the script
Reply With Quote
  #6  
Old 26th Jun 03, 04:05 AM
adams adams is offline
Super Moderator
 
Join Date: Jul 2001
Posts: 1,124
adams is an unknown quantity at this point
ok that did it for that, but when the calculate.php loads the following is displayed:
Code:
The result of the calculation is:
i put in a value for 1 and 2 and hit add, but nothing shows up.
__________________
Camera Equipment:
Canon 40D & Digital Rebel XT
Canon 500mm L IS USM
Canon 100-400mm L IS USM
kit lens
Sigma 70-300mm APO DG
Canon 430 EX Speedlight
Dynatran Tripod
Lowepro Mini Trekker AW backpack
Reply With Quote
  #7  
Old 26th Jun 03, 05:18 AM
Sephiroth Sephiroth is offline
BetaONE Supporter
 
Join Date: Jul 2001
Posts: 1,979
Sephiroth is an unknown quantity at this point
Send a message via MSN to Sephiroth
just as a test, try to echo your other variables like you did with $result, just to see if they are getting any data stored in them, i don't think they are from what it's doing
Reply With Quote
  #8  
Old 26th Jun 03, 05:38 PM
cappaberra
 
Posts: n/a
yea... generally a decent idea for the php code I've written is to have a $debug variable at the top of the file that you can toggle (1/0) depending on if you want to print/echo a bunch of other variables... so for example, my code is littered with statements like this:

if ($debug) echo ("var: " . $var . "\n");

you may throw in some formatting to make it look better and more readable, like i did above.... hope this helps, and in the future, documentation always helps debugging too.

Sorry for the lecture, but hope you get things working!!!

Have fun,
cappaberra
Reply With Quote
  #9  
Old 27th Jun 03, 02:35 AM
adams adams is offline
Super Moderator
 
Join Date: Jul 2001
Posts: 1,124
adams is an unknown quantity at this point
ok it turns out there wasn't anything wrong with the code, but with my installation of php(i think).

i had installed phptriad which someone recommended cause it setup everything for you (php, apache, mysql), then someone at another forum told me to install phpdev so i did that and moved my files and now everything works.

thanks again for everyones support.
__________________
Camera Equipment:
Canon 40D & Digital Rebel XT
Canon 500mm L IS USM
Canon 100-400mm L IS USM
kit lens
Sigma 70-300mm APO DG
Canon 430 EX Speedlight
Dynatran Tripod
Lowepro Mini Trekker AW backpack
Reply With Quote
  #10  
Old 27th Jun 03, 03:11 AM
billybob3's Avatar
billybob3 billybob3 is offline
Senior Member
 
Join Date: Apr 2003
Location: Earth
Posts: 577
billybob3
Send a message via AIM to billybob3 Send a message via MSN to billybob3
Ha, knew it was an installation problem . Glad you got it working!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:57 PM.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.