10 Replies - 318 Views - Last Post: 09 February 2013 - 09:31 AM Rate Topic: -----

#1 dsgoodwin82  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 08-October 11

Results page not working...

Posted 07 February 2013 - 11:48 AM

I am creating a cents calculator. On the first page the user enters the amount of quarters and dimes they have. Than when the user clicks on the calculate button it is supposed to take them to a results page that gives them the total for quarters, dimes, and all together. However, When the calculate button is clicked it simply clears the text boxes and nothing happens. Since PHP does not give a syntax error I have no idea what is causing the problem. I am sure it is probably something small, but if some one could take a look and let me know if they see anything that would be great. Thanks. Here is the code for the input as well as the results page.

INPUT

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>David Goodwin Cents Calcualtion</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.auto-style1 {
	border: 1px solid #000080;
	background-color: #C0C0C0;
}
.auto-style2 {
	text-align: left;
}
</style>
</head>

<body bgcolor="#C0C0C0">

<h1>Welcome to David's Cents Calculation Page</h1>
<?php if (!empty($error_message)){ ?>
        <p class="error"><?php echo $error_message; ?></p>
<?php } ?>

<p>&nbsp;</p>
<form action="DavidGoodwin_CentsCalculationProcess.php" method="post" style="text-align: center">
<table class="auto-style1" style="width: 55%">
	<tr>
		<td style="width: 282px">Pease enter number of dimes:</td>
		<td class="auto-style2">
		<form method="post">
			<input name="Text1" type="text" value="<?php echo $dimes; ?>" /></form></td>
	</tr>
	<tr>
		<td style="width: 282px">Please enter number of quarters:</td>
		<td class="auto-style2">
		<form method="post">
			<input name="Text2" type="text" value="<?php echo $quarters; ?>" /></form></td>
	</tr>
	<tr>
		<td style="width: 282px">
		<form method="post">
			<input name="Submit" style="width: 147px; height: 41px" type="submit" value="Calculate" /></form></td>
		<td>&nbsp;</td>
	</tr>
</table>
</form>
</body>
</html>



RESULTS PAGE

<?php
    // get the data from the form
    $quarters = $_POST['quarters'];
    $dimes = $_POST['dimes'];
    
    
     // validate 
    if ( empty($dimes) ) {
        $error_message = 'Dimes is a required field.'; 
    } else if ( !is_numeric($dimes) )  {
        $error_message = 'Dimes must be a valid number.'; 
    } else if ( $dimes <= 0 ) {
        $error_message = 'Dimes must be greater than zero.';        
	}
	
	    if ( empty($quarters) ) {
        $error_message = 'Quarters is a required field.'; 
    } else if ( !is_numeric($quarters) )  {
        $error_message = 'Quarters must be a valid number.'; 
    } else if ( $quarters <= 0 ) {
        $error_message = 'Quarters must be greater than zero.';        
	}

    // if an error message exists, go to the index page
    if ($error_message != '') {
        include('Basics.php');
        exit();
    }
    
    //calculate for the total number of cents
    $quarters = 25;
    $dimes = 10;
    $total = ($quarters + $dimes);
    
    
    //formatting
    $quarters_f = number_format($quarters, 0);
    $dimes_f = number_format($dimes, 0);
    $total_f = number_format($total, 0);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language"/>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>DavidGoodwin Cents Calculation</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	border: 1px solid #000080;
}
</style>
<link href="main.css" rel="stylesheet" type="text/css"/>
</head>

<body bgcolor="#C0C0C0">

<h1 class="auto-style1">Total Cents</h1>
<table class="auto-style2" style="width: 100%">
	<tr>
		<td style="width: 383px">Total cents in quarters:</td>
		<td><?php echo $quarters; ?></td>
	</tr>
	<tr>
		<td style="width: 383px">Total cents in dimes:</td>
		<td><?php echo $dimes; ?></td>
	</tr>
	<tr>
		<td style="width: 383px">Total all together:</td>
		<td><?php echo $total; ?></td>
	</tr>
</table>
<p class="auto-style1">&nbsp;</p>

</body>

</html>




Is This A Good Question/Topic? 0
  • +

Replies To: Results page not working...

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2877
  • View blog
  • Posts: 9,548
  • Joined: 12-December 12

Re: Results page not working...

Posted 07 February 2013 - 12:38 PM

You are not posting to your results page:

<form method="post">

- you need to add the action attribute.

BTW You should check the post-data with empty() etc., before you attempt to assign the data to variables.
Was This Post Helpful? 4
  • +
  • -

#3 creativecoding  Icon User is online

  • Hash != Encryption
  • member icon


Reputation: 922
  • View blog
  • Posts: 3,195
  • Joined: 19-January 10

Re: Results page not working...

Posted 07 February 2013 - 05:13 PM

To add on,

The default value of action method is "get", so if you don't assign it, that's what will be used. You can tell if your inputs were sent using GET if they show up in the URL in the format:

?name=value&name2=value2&so and and so forth

For example:

script.php?username=hi&DOB=030190

This post has been edited by creativecoding: 07 February 2013 - 08:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2877
  • View blog
  • Posts: 9,548
  • Joined: 12-December 12

Re: Results page not working...

Posted 07 February 2013 - 05:30 PM

View Postcreativecoding, on 07 February 2013 - 05:13 PM, said:

To add on,

The default value of action is "get", so if you don't assign it, that's what will be used.

You mean the default value of method.
Was This Post Helpful? 0
  • +
  • -

#5 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 403
  • View blog
  • Posts: 1,720
  • Joined: 30-April 10

Re: Results page not working...

Posted 07 February 2013 - 05:57 PM

View Postandrewsw, on 07 February 2013 - 12:38 PM, said:

You are not posting to your results page:

<form method="post">


This is part of the OP first post

<form action="DavidGoodwin_CentsCalculationProcess.php" method="post" style="text-align: center">

The method is post in this code. (See next post)

This post has been edited by laytonsdad: 07 February 2013 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

#6 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 403
  • View blog
  • Posts: 1,720
  • Joined: 30-April 10

Re: Results page not working...

Posted 07 February 2013 - 07:41 PM

Ok, the problem is on the first page just before the submit button is an extra <form method="post"> tag. this makes the inputs above it to not be submitted and it goes to the main page instead of the page you do the work in.
Was This Post Helpful? 0
  • +
  • -

#7 creativecoding  Icon User is online

  • Hash != Encryption
  • member icon


Reputation: 922
  • View blog
  • Posts: 3,195
  • Joined: 19-January 10

Re: Results page not working...

Posted 07 February 2013 - 08:05 PM

View Postandrewsw, on 07 February 2013 - 04:30 PM, said:

View Postcreativecoding, on 07 February 2013 - 05:13 PM, said:

To add on,

The default value of action is "get", so if you don't assign it, that's what will be used.

You mean the default value of method.


haha, it's been a long day :P
Was This Post Helpful? 0
  • +
  • -

#8 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: Results page not working...

Posted 08 February 2013 - 07:31 AM

Try deleting the
<form method = "post">

in line 33, 39, 44.
</form>

34,40,45. AND THEN TRY TO RUN AGAIN.
Was This Post Helpful? 0
  • +
  • -

#9 dsgoodwin82  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 08-October 11

Re: Results page not working...

Posted 08 February 2013 - 09:01 PM

OK that problem is fixed. Thank you for the help. I am now faced with a new problem. It does not actually add the quarters and dimes up. No matter what is placed in the input, it only adds one quarter and one dime for a total of 35. I put in 50 quarters and 50 dimes and it still gave me 35 cents. It should just be $total = $quarters + $dimes, right? If someone could take a look that would be great. Thanks for the help.
New Code:

Input screen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>David Goodwin Cents Calcualtion</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.auto-style1 {
	border: 1px solid #000080;
	background-color: #C0C0C0;
}
.auto-style2 {
	text-align: left;
}
</style>
</head>
<body bgcolor="#C0C0C0">
<h1>Welcome to David's Cents Calculation Page</h1>

<p>&nbsp;</p>
<form action="DavidGoodwin_CentsCalculationProcess.php" method="post" style="text-align: center">
<table class="auto-style1" style="width: 55%">
	<tr>
		<td style="width: 282px">Pease enter number of dimes:</td>
		<td class="auto-style2">
		<form method="post">
			<input name="Text1" type="text" value="<?php echo $dimes; ?>" /></form></td>
	</tr>
	<tr>
		<td style="width: 282px">Please enter number of quarters:</td>
		<td class="auto-style2">
		<form method="post">
			<input name="Text2" type="text" value="<?php echo $quarters; ?>" /></form></td>
	</tr>
	<tr>
		<td style="width: 282px">
		
			<input name="Submit" style="width: 147px; height: 41px" type="submit" value="Calculate" /></td>
		<td>&nbsp;</td>
	</tr>
</table>
</form>

</body>

</html>



Process Page:
<?php
    // get the data from the form
    $quarters = $_POST['quarters'];
    $dimes = $_POST['dimes'];
    
    
    //calculate for the total number of cents
    $quarters = 25;
    $dimes = 10;
    $total = ($quarters + $dimes);
    
    
    //formatting
    $quarters_f = number_format($quarters, 0);
    $dimes_f = number_format($dimes, 0);
    $total_f = number_format($total, 0);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language"/>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>DavidGoodwin Cents Calculation</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	border: 1px solid #000080;
}
</style>
<link href="main.css" rel="stylesheet" type="text/css"/>
</head>

<body bgcolor="#C0C0C0">

<h1 class="auto-style1">Total Cents</h1>
<table class="auto-style2" style="width: 100%">
	<tr>
		<td style="width: 383px">Total cents in quarters:</td>
		<td><?php echo $quarters; ?></td>
	</tr>
	<tr>
		<td style="width: 383px">Total cents in dimes:</td>
		<td><?php echo $dimes; ?></td>
	</tr>
	<tr>
		<td style="width: 383px">Total all together:</td>
		<td><?php echo $total; ?></td>
	</tr>
</table>
<p class="auto-style1">&nbsp;</p>

</body>

</html>



Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2877
  • View blog
  • Posts: 9,548
  • Joined: 12-December 12

Re: Results page not working...

Posted 09 February 2013 - 03:35 AM

You are retrieving and assigning values from the post-data:

$quarters = $_POST['quarters'];

but then you over-write these values by setting them to 25 (and 10):

$quarters = 25;

Was This Post Helpful? 0
  • +
  • -

#11 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 403
  • View blog
  • Posts: 1,720
  • Joined: 30-April 10

Re: Results page not working...

Posted 09 February 2013 - 09:31 AM

you could do somthing like:

$quarters = 25;
$dimes = 10;

$quarters *= $_POST['quarters'];
$dimes *= $_POST['dimes'];

$total = $quarters + $dimes;



The *= assignment operater works like this,
$a *= $b or $a = $a * $b.

This post has been edited by laytonsdad: 09 February 2013 - 09:32 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1