Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

String to Integer issue in php

Posted on 2011-02-23
5
Medium Priority
?
335 Views
Last Modified: 2012-05-11
Hi
I'm having trouble with retrieving a couple variables appended to a url and dividing them and assigning the result to a new variable. I suspect it has something to do with them possibly being strings as opposed to integers so the math is returning 0 for a value. But I could be absolutely wrong.

Below is the pertinent code.

When dividing expenses by income the value for $tdsr keeps appearing as '0'

Any ideas?
<?php
header("content-type: text/xml");
echo  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$recording = $_REQUEST['recording'];
$numbertocall = $_REQUEST['numbertocall'];
$income = $_REQUEST['income'];
$expenses = $_REQUEST['expenses'];

$tdsr = $expenses/$income;


?>

Open in new window

0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 2000 total points
ID: 34966694
have a look at http://www.php.net/manual/en/function.intval.php


$income = intval ($_REQUEST['income']);
$expenses = intval ($_REQUEST['expenses']);
0
 
LVL 1

Author Comment

by:tjyoung
ID: 34966727
Hi, I did try that but I suspect my implementation must be wrong. Below is a more comprehensive view of the code I'm using with intval in.

Do you see what I'm doing wrong? It may be something very newbie...

Its mixed in with some Twilio code. All works except the value of $tdsr is '0'.
<?php
header("content-type: text/xml");
echo  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$recording = $_REQUEST['recording'];
$numbertocall = $_REQUEST['numbertocall'];
$income = intval($_REQUEST['income']);
$expenses = intval($_REQUEST['expenses']);

$tdsr = $expenses/$income;


?>

<Response>

<?php
if ($_REQUEST['Digits']=="1"){

	$approvalID = mt_rand(301, 9950);
	$approvalSlow = wordwrap($approvalID,1,",",TRUE);


	if ($tdsr >= 70) { ?>
		<Say>This is hopeless</Say>
	
	<?php } elseif ($tdsr >= 60 && $tdsr < 70) { ?>
		<Say>You're application requires a few additional questions to be pre-approved</Say>
		<Say>Our Dealership will contact you so we can gather some additional information to get your application approved.</Say>
	
	<?php } elseif ($tdsr < 60) {?>
		<Say> Congratulations, you are Pre-Approved!</Say>
		<Say> Your Approval ID is <?php echo $approvalSlow ?></Say>
		<Say> Please make a note of your Pre-Approval ID </Say>
		<Say> That number again is <?php echo $approvalSlow ?></Say>
		<Say> Your total debt service ratio is <?php echo $tdsr ?></Say>
	<?php
	
	$email = "email@email.com";
	$subject = "New 5 Second Phone Credit App! Approval ID: ". $approvalID;
	$body .= "The Caller's recorded name is:";
	$body .= $_REQUEST['recording'].".mp3\n\n";
	$body .= "The Caller's reverse lookup name if available was: ${_REQUEST['CallerName']}\n\n";
	$body .= "The Caller's preferred phone number is: ${_REQUEST['numbertocall']}\n\n";
	$body .= "The Caller's display phone number is: ${_REQUEST['From']}\n\n";
	$body .= "The Caller is in: ${_REQUEST['CallerCity']}\n\n";
	$body .= "The Caller's TDSR: ". $tdsr."\n\n";

    
	$headers = 'From: me@me.com' . "\r\n";
	$headers .= 'Reply-To: me@me.com' . "\r\n";
	$headers .= 'X-Mailer: Twilio';

	mail ($email, $subject, $body, $headers);
	}
	?>

Open in new window

0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 34966745
Your answer was correct. I was implementing it incorrectly initially.
thanks!
0
 
LVL 6

Expert Comment

by:MatthewP
ID: 34966760
I can't see what's wrong with that and you shouldn't even need intval. Have you checked the raw values as they come into the script before you've touched them?

Just add

var_dump($_REQUEST);

to the top of your script for a quick way to check this out.
0
 
LVL 1

Author Comment

by:tjyoung
ID: 34966780
Thanks. That was my issue. I marked your answer as correct simply because had I actually had the 'correct problem' your response was right.
var_dump is good to know as well.

Thanks again.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question