Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Forms


PHP Forms

Reply
  #1 (permalink)  
Old 09-24-09, 02:59 PM
donald_nqn donald_nqn is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
PHP Forms

This is more of an inquiry rather than coding help. And if its not in the right forums, please forgive me. But i posted it here, since the coding is done in PHP language.

I've made this small project, creating a GPA calculator. You would input your average percentage of the subject and then it would calculate the GPA for you and the honor role. However once i compute it, the 'data' that the user input disappears. Is there a way to make the 'data' stay where it is?

Screen Shots:
http://i33.tinypic.com/2py7wwn.png
http://i34.tinypic.com/4fx4p5.png
http://i38.tinypic.com/2eqcnd4.png
Reply With Quote
  #2 (permalink)  
Old 09-24-09, 03:51 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Please post your code.
Reply With Quote
  #3 (permalink)  
Old 09-24-09, 05:15 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
Set a cookie.
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #4 (permalink)  
Old 09-24-09, 07:55 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
If it is just for that ONE page load, echo your SuperGlobals back to the form inputs.
Reply With Quote
  #5 (permalink)  
Old 09-25-09, 03:10 AM
donald_nqn donald_nqn is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
This is my code.

PHP Code:

<form action="<?php $_SERVER['../PHP_SELF']; ?>" method="POST">

<table align="center">

<tr bgcolor="#99a5b3"><td colspan="3"><h2>Grade Point Average Calculator</h2></td></tr>
<tr><td style="font-size: 0.5pt;" bgcolor="#ffcc66" colspan="3">&nbsp;</td></tr>

<tr bgcolor="#EBEBEB"><td colspan="3"><b>Core Subjects</b></td></tr>
<tr bgcolor="#D0D0D0"><td width="157">English</td><td width="65"><input type="checkbox" name="hlenglish" value="yes" />HL/AP</td><td ><input width="30" name="english"> %</td></tr>
<tr bgcolor="#EBEBEB"><td width="157">Math</td><td width="65"><input type="checkbox" name="hlmath" value="yes" />HL/AP</td><td><input width="30" name="math"> %</td></tr>
<tr bgcolor="#D0D0D0"><td width="157">Social Studies</td><td width="65"><input type="checkbox" name="hlsocialstudies" value="yes" />HL/AP</td><td><input width="30" name="westernciv"> %</td></tr>
<tr bgcolor="#EBEBEB"><td width="157">Science</td><td width="65"><input type="checkbox" name="hlscience" value="yes" />HL/AP</td><td><input width="30" name="science"> %</td></tr>
<tr bgcolor="#D0D0D0"><td width="157">PE/Health</td><td width="65"></td><td><input width="30" name="pehealth"> %</td></tr>
<tr bgcolor="#EBEBEB"><td colspan="3"><b>Electives</b></td></tr>
<tr bgcolor="#D0D0D0"><td width="157">Elective 1</td><td width="65"><input type="checkbox" name="hlelective1" value="yes" />HL/AP</td><td><input width="30" name="arabic"> %</td></tr>
<tr bgcolor="#EBEBEB"><td width="157">Elective 2</td><td width="65"><input type="checkbox" name="hlelective2" value="yes" />HL/AP</td><td><input width="30" name="guitar"> %</td></tr>
<tr bgcolor="D0D0D0"><td align="right" colspan="3"><input type="submit" value="Calculate" name="Submit"/></td></tr>
<tr bgcolor="#EBEBEB"><td colspan="3"><b><?php
if (isset($_POST['Submit'])){

$english $_POST['english'];
$math $_POST['math'];
$westernciv $_POST['westernciv'];
$science $_POST['science'];
$pehealth $_POST['pehealth'];
$arabic $_POST['arabic'];
$guitar $_POST['guitar'];
$hlenglish $_POST['hlenglish'];
$hlmath $_POST['hlmath'];
$hlsocialstudies $_POST['hlsocialstudies'];
$hlscience $_POST['hlscience'];
$hlelective1 $_POST['hlelective1'];
$hlelective2 $_POST['hlelective2'];


if ( 
$english <=  59 ) {
    
$a 0.0;
} elseif ( 
$english <=  62 ) {
    
$a 0.7;
} elseif (
$english <= 66 ) {
    
$a 1.0;
} elseif (
$english <= 69 ) {
    
$a 1.3;
} elseif (
$english <= 72 ) {
    
$a 1.7;
} elseif (
$english <= 76 ) {
    
$a 2.0;
} elseif (
$english <= 79 ) {
    
$a 2.3;
} elseif (
$english <= 82 ) {
    
$a 2.7;
} elseif (
$english <= 86 ) {
    
$a 3.0;    
} elseif (
$english <= 89 ) {
    
$a 3.3;    
} elseif (
$english <= 92 ) {
    
$a 3.7;    
} elseif (
$english <= 96 ) {
    
$a 4.0;    
} else {
    
$a4.3;
}

if ( 
$math <=  59 ) {
    
$b 0.0;
} elseif ( 
$math <=  62 ) {
    
$b 0.7;
} elseif (
$math <= 66 ) {
    
$b 1.0;
} elseif (
$math <= 69 ) {
    
$b 1.3;
} elseif (
$math <= 72 ) {
    
$b 1.7;
} elseif (
$math <= 76 ) {
    
$b 2.0;
} elseif (
$math <= 79 ) {
    
$b 2.3;
} elseif (
$math <= 82 ) {
    
$b 2.7;
} elseif (
$math <= 86 ) {
    
$b 3.0;    
} elseif (
$math <= 89 ) {
    
$b 3.3;    
} elseif (
$math <= 92 ) {
    
$b 3.7;    
} elseif (
$math <= 96 ) {
    
$b 4.0;    
} else {
    
$b4.3;
}

if ( 
$westernciv <=  59 ) {
    
$c 0.0;
} elseif ( 
$westernciv <=  62 ) {
    
$c 0.7;
} elseif (
$westernciv <= 66 ) {
    
$c 1.0;
} elseif (
$westernciv <= 69 ) {
    
$c 1.3;
} elseif (
$westernciv <= 72 ) {
    
$c 1.7;
} elseif (
$westernciv <= 76 ) {
    
$c 2.0;
} elseif (
$westernciv <= 79 ) {
    
$c 2.3;
} elseif (
$westernciv <= 82 ) {
    
$c 2.7;
} elseif (
$westernciv <= 86 ) {
    
$c 3.0;    
} elseif (
$westernciv <= 89 ) {
    
$c 3.3;    
} elseif (
$westernciv <= 92 ) {
    
$c 3.7;    
} elseif (
$westernciv <= 96 ) {
    
$c 4.0;    
} else {
    
$c4.3;
}

if ( 
$science <=  59 ) {
    
$d 0.0;
} elseif ( 
$science <=  62 ) {
    
$d 0.7;
} elseif (
$science <= 66 ) {
    
$d 1.0;
} elseif (
$science <= 69 ) {
    
$d 1.3;
} elseif (
$science <= 72 ) {
    
$d 1.7;
} elseif (
$science <= 76 ) {
    
$d 2.0;
} elseif (
$science <= 79 ) {
    
$d 2.3;
} elseif (
$science <= 82 ) {
    
$d 2.7;
} elseif (
$science <= 86 ) {
    
$d 3.0;    
} elseif (
$science <= 89 ) {
    
$d 3.3;    
} elseif (
$science <= 92 ) {
    
$d 3.7;    
} elseif (
$science <= 96 ) {
    
$d 4.0;    
} else {
    
$d4.3;
}

if ( 
$pehealth <=  59 ) {
    
$e 0.0;
} elseif ( 
$pehealth <=  62 ) {
    
$e 0.7;
} elseif (
$pehealth <= 66 ) {
    
$e 1.0;
} elseif (
$pehealth <= 69 ) {
    
$e 1.3;
} elseif (
$pehealth <= 72 ) {
    
$e 1.7;
} elseif (
$pehealth <= 76 ) {
    
$e 2.0;
} elseif (
$pehealth <= 79 ) {
    
$e 2.3;
} elseif (
$pehealth <= 82 ) {
    
$e 2.7;
} elseif (
$pehealth <= 86 ) {
    
$e 3.0;    
} elseif (
$pehealth <= 89 ) {
    
$e 3.3;    
} elseif (
$pehealth <= 92 ) {
    
$e 3.7;    
} elseif (
$pehealth <= 96 ) {
    
$e 4.0;    
} else {
    
$e4.3;
}

if ( 
$arabic <=  59 ) {
    
$f 0.0;
} elseif ( 
$arabic <=  62 ) {
    
$f 0.7;
} elseif (
$arabic <= 66 ) {
    
$f 1.0;
} elseif (
$arabic <= 69 ) {
    
$f 1.3;
} elseif (
$arabic <= 72 ) {
    
$f 1.7;
} elseif (
$arabic <= 76 ) {
    
$f 2.0;
} elseif (
$arabic <= 79 ) {
    
$f 2.3;
} elseif (
$arabic <= 82 ) {
    
$f 2.7;
} elseif (
$arabic <= 86 ) {
    
$f 3.0;    
} elseif (
$arabic <= 89 ) {
    
$f 3.3;    
} elseif (
$arabic <= 92 ) {
    
$f 3.7;    
} elseif (
$arabic <= 96 ) {
    
$f 4.0;    
} else {
    
$f4.3;
}
    
if ( 
$guitar <=  59 ) {
    
$g 0.0;
} elseif ( 
$guitar <=  62 ) {
    
$g 0.7;
} elseif (
$guitar <= 66 ) {
    
$g 1.0;
} elseif (
$guitar <= 69 ) {
    
$g 1.3;
} elseif (
$guitar <= 72 ) {
    
$g 1.7;
} elseif (
$guitar <= 76 ) {
    
$g 2.0;
} elseif (
$guitar <= 79 ) {
    
$g 2.3;
} elseif (
$guitar <= 82 ) {
    
$g 2.7;
} elseif (
$guitar <= 86 ) {
    
$g 3.0;    
} elseif (
$guitar <= 89 ) {
    
$g 3.3;    
} elseif (
$guitar <= 92 ) {
    
$g 3.7;    
} elseif (
$guitar <= 96 ) {
    
$g 4.0;    
} else {
    
$g4.3;
}

if ( 
$hlenglish == 'yes' ) {
    
$a $a 0.3;
} else {
    
$a $a;
}

if ( 
$hlmath == 'yes' ) {
    
$b $b 0.3;
} else {
    
$b $b;
}

if ( 
$hlsocialstudies == 'yes' ) {
    
$c $c 0.3;
} else {
    
$c $c;
}

if ( 
$hlscience == 'yes' ) {
    
$d $d 0.3;
} else {
    
$d $d;
}

if ( 
$hlelective1 == 'yes' ) {
    
$f $f 0.3;
} else {
    
$f $f;
}

if ( 
$hlelective2 == 'yes' ) {
    
$g $g 0.3;
} else {
    
$g $g;
}
    
$gpa = ($a+$b+$c+$d+$e+$f+$g)/7;
$gpa2 round($gpa2);

echo 
"Your GPA is ".$gpa2;

    }
?>
</b></td></tr>

</table>

</form>
Reply With Quote
  #6 (permalink)  
Old 09-25-09, 12:08 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
Use a hidden field.
HTML Code:
<input type="hidden" name="GPA" value="<?php echo$gpa2; ?>"
Or as I said use a cookie
__________________
This post was created with 100% recycled electrons.

Last edited by Nico; 09-25-09 at 12:11 PM.
Reply With Quote
  #7 (permalink)  
Old 09-25-09, 08:13 PM
pyr0t3chnician pyr0t3chnician is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 30
Thanks: 0
Thanked 1 Time in 1 Post
PHP Code:

<input type="text" name="english" value="<?php echo $_POST['english']; ?>">
That should do the trick, just do that for every text input.
Reply With Quote
The Following User Says Thank You to pyr0t3chnician For This Useful Post:
donald_nqn (09-27-09)
  #8 (permalink)  
Old 09-26-09, 03:48 AM
donald_nqn donald_nqn is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pyr0t3chnician View Post
PHP Code:

<input type="text" name="english" value="<?php echo $_POST['english']; ?>">
That should do the trick, just do that for every text input.
This worked thank you

One more thing. How could you do it for the checkboxes? Since they already have a value="yes"

Last edited by donald_nqn; 09-26-09 at 03:51 AM.
Reply With Quote
  #9 (permalink)  
Old 09-26-09, 11:19 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

<input type="checkbox" name="hlscience" value="yes" <?php if($_POST['hlscience'] == 'yes') { echo 'checked="checked"'; } ?> />
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
donald_nqn (09-27-09)
Reply

Bookmarks


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] it works on localhost but not on hosting account? myslowquietlife PHP 42 12-19-08 09:31 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP to calculate HTML forms jamesian PHP 1 10-25-04 07:45 AM
PHP and Forms? nickweb PHP 2 04-23-04 03:51 PM
Forms and php? move3rd PHP 2 04-01-04 06:38 PM


All times are GMT -5. The time now is 08:00 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.