Jump to content
Sign in to follow this  
mboehler3

Converting Asp Code To Php, Values Are Missing

Recommended Posts

I am trying to convert my ASP code to PHP. This code is used to display a price quote based on information a user has submitted through a form on the previous page. The Price Quote is determined by a math equation: the Base fee + (Number of Employees x TransTotal). On the previous page, the user has entered in the Number of Employees as well as selected their Frequency (Weekly, Bi-Weekly, Semi-Monthly or Monthly). Both Frequency and Number of Employees will be passed through the query string. On my first include file, I set the Employees and Frequency. For Number of Employees, I first want to check the query string for a value. If nothing is in the query string, the default value should be 1. Then, do the same for Frequency. Monthly is set as the default value if nothing is entered in the query string. On my second include file, I have the equations, where I set the Base fee and TransTotal. For Weekly, Bi-Weekly and Semi-Monthly, the Base fee is $69.99. For Monthly it is $54.99. The TransTotal only applies if the Number of Employees is greater than 5. If the number is greater than 5, the TransTotal is $1.99, for all frequencies. And then I want to pull each variable on my page to display. I wrote the code this morning and tested it locally, but the variables to not show up on my page. Am I close to getting this to work? With nothing in the query string, the Price Quote should be $54.99 (Monthly default, 1 employee default). But, no price shows up at all. First include:

<?phpif ( $emp_cnt == "" ) {$emp_cnt == $_SERVER["NumberOfEmployees"];}if ( $emp_cnt == "" or $emp_cnt < 1 ) {$emp_cnt == 1;}if ( $str_pf == "" ) {$str_pf == $_SERVER["Frequency"];switch ($str_pf){case "Weekly":  $str_pf == "Weekly";  break;case "Bi-Weekly":  $str_pf == "Bi-Weekly";  break;case "Semi-Monthly":  $str_pf == "Semi-Monthly";  break;default:  $str_pf == "Monthly";}}?>

Second include:

<?phpif ( $str_pf == "Weekly" && $emp_cnt <= 5 ) {$base == 69.99;$trans == 0;}if ( $str_pf == "Weekly" && $emp_cnt > 5 ) {$base == 69.99;$trans == 1.99;}if ( $str_pf == "Bi-Weekly" && $emp_cnt <= 5 ) {$base == 69.99;$trans == 0;}if ( $str_pf == "Bi-Weekly" && $emp_cnt > 5 ) {$base == 69.99;$trans == 1.99;}if ( $str_pf == "Semi-Monthly" && $emp_cnt <= 5 ) {$base == 69.99;$trans == 0;}if ( $str_pf == "Semi-Monthly" && $emp_cnt > 5 ) {$base == 69.99;$trans == 1.99;}if ( $str_pf == "Monthly" && $emp_cnt <= 5 ) {$base == 54.99;$trans == 0;}if ( $str_pf == "Monthly" && $emp_cnt > 5 ) {$base == 54.99;$trans == 1.99;}$total == ( $base + ( $trans*$emp_cnt ) )?>

And my page:

<html><head><style type="text/css">a {text-decoration:none; color:#0c72b2;}a:hover {text-decoration:underline;}.fontsize12 {font-size:12px;}.fontsize10 {font-size:10pt;}.color0c72b2 {color:#0c72b2;}.colorc86d14 {color:#c86d14;}.head {font-size:30px;font-family:Arial;font-weight:bold;float:left;padding-top:4px;}.quote {font-size:16px;font-family:Arial;font-weight:bold;float:left;padding:4px 0 0 0;}.clear {clear:both;display:block;overflow:hidden;visibility:hidden;width:0;height:0;}.dlquote {font-size:18px;font-family:Arial;padding-bottom:10px;font-weight:bold;padding:5px 0 5px 15px;}.subbody {font-size:8pt;font-family:Arial;padding-left:15px;}.price-container {width:354px;height:224px}.bottom-border {font-size:18px;font-family:Arial;padding:5px 0 10px 15px;font-weight:bold;border-bottom:1px solid #807e7e}.price-copy {font-size:18px;font-family:Arial;font-weight:bold;}</style></head><body><?php include("ipq_vars.php"); ?><?php include("ipq_prices.php"); ?><div class="price-container"><div class="head">$<?php ($total); ?></div><img src="/images/960/quote/quote-divider.gif" style="float:left;" /><div class="quote">Your Payroll Quote<br />$<?php $total ?>* per payroll</div><div class="clear"> </div><div class="body"><div class="bottom-border"><div class="price-copy">For Payroll <?php $freq ?> <?php ($emp_cnt) ?> Employees</div></div><div class="dlquote"><span class="color0c72b2">>></span><a href="/quote/GoodFaith.asp?Total=<?php $total ?>&BaseFee=<?php $base ?>&EmCount=<?php $emp_cnt ?>&TransTotal=<?php $trans ?>&Frequency=<?php $freq ?>" target="_blank">Download Your Quote <span class="fontsize12">(pdf)</span> <img src="/images/960/quote/acrobat13x13.gif" border="0" /></a></div><div class="subbody"><span class="fontsize10">*Quote Details:</span><br />Per Payroll Base Price: $<?php $base ?><br />Per Employee Price: $<?php $trans ?><br /><br /></div></div></body></html>

Share this post


Link to post
Share on other sites

You're not defining the variables like $emp_cnt and $str_pf before trying to use them. If you're looking for things submitted through a form or through the URL, they aren't going to be in $_SERVER. The $_SERVER array holds information about the web server. Variables in the URL are found in $_GET.

Share this post


Link to post
Share on other sites

I think that's where I'm running into the issue - defining the variable. All of the examples I've found online give variables a set value. Like, $emp_cnt = 1 or $emp_cnt = "Hello World"... The value for $emp_cnt changes, depending on what they entered in the form. I tried changing my code to this:

<?php$emp_cnt = $_GET["NumberOfEmployees"];if ( $emp_cnt == "" or $emp_cnt < 1 ) {$emp_cnt == 1;}$str_pf = $_GET["Frequency"];if ( $str_pf == "" ) {switch ($str_pf){case "Weekly":  $str_pf == "Weekly";  break;case "Bi-Weekly":  $str_pf == "Bi-Weekly";  break;case "Semi-Monthly":  $str_pf == "Semi-Monthly";  break;default:  $str_pf == "Monthly";}}?>

But I still don't see the numbers populate. Can I define them like I did above?

Share this post


Link to post
Share on other sites

It's fine the way you're getting the values from $_GET, assuming those names are correct. You need to use "=" to assign a value though, the == operator is only for comparison, not assignment.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...