Value not being returned from function
Posted: Mon Aug 18, 2003 11:47 am
Hi all. I'm trying to return a value from a function to the page that called it, but the value is not showing up. Please take a look at the following code and tell me where I'm going wrong.
This first snippet is the function call:
This snippet is the function, included in the page containing the previous snippet:
Obviously, I'm trying to return the $num variable. Thanks!
This first snippet is the function call:
Code: Select all
<?php
// call the function to query the product/user tables
get_account($_POST['regNumber'], $_POST['mailZipCode']);
// if there is no match
if ($num == 0) {
$error = "<span class="body"><strong><font color="#FF0000">Invalid registration number/zip code combination. Please re-enter your information.</font></strong></span> <br><strong>\$num</strong> = $num<br><br>";
}
// if there is only one match
if ($num == 1) {?>
<script type="text/javascript" language="JavaScript">
<!--
location.href="display_account.php";
//-->
</script><?php
exit;
}
?>Code: Select all
<?php
// function to get account information based upon
// the reg number and zip code provided by the
// customer
function get_account($regNumber, $mailZipCode) {
$query = "SELECT p.productID FROM
customers AS c,
products AS p
WHERE
p.regNumber = $regNumber AND
c.mailZipCode = $mailZipCode AND
p.customerID = c.customerID";
$result = mysql_query($query) or die ('There''s a problem!' . mysql_error());
$num = mysql_num_rows($result);
return $num;
/*echo "\$query = " . $query . " \$num = " . $num;
exit;*/
}
?>