Jump to content


Photo

My php function will not completely run, it seems to just stop execution


  • Please log in to reply
5 replies to this topic

#1 Hardwarez

Hardwarez
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 09 October 2006 - 03:57 PM

???
Ok, my php is doing something weird!  It seem that one of my functions will no completely run.
I placed echo through-out my function and it just stops working half way throug the function.

Is there some kind of buffer/size limit to a function?

My Function:
function IsUserValid ($ipaddr,$Usr)  //--------------Check database FUNCTION
{
echo '<font color="red"><P>Address: ' . $ipaddr . ', User: ' . $Usr;
$query = "SELECT id FROM userlist WHERE clientip='$ipaddr' && user='$Usr'";
$result = mysql_query($query) or die (mysql_error());
$number = mysql_num_rows($result);
// check time out time and kill valid IP if timeout
$Utime = date("U");
$query = "SELECT Utime FROM userlist WHERE clientip='$ipaddr'";
$result = mysql_query($query) or die (mysql_error());
echo '<P>' . $result;
$row = mysql_fetch_array($result) or die(mysql_error());
echo '<BR>rowTime: ' . $row['Utime'] . '</font>';
xxxxxxxxxxxxxxxxxxxxxxxNOTHING BELOW THIS RUNS, THE ECHOs DO NOT EVEN WORKxxxxxxxx
if ($Utime > $row['Utime']) {
$query="UPDATE userlist SET clientip='1.0.0.1' WHERE clientip='$ipaddr' LIMIT 1";
mysql_query($query) or die (mysql_error());
$r='0';// clear flag to require re-validation
}

if ($r != '0' && $number > '0') $x='1';
else $x ='0';
echo 'returning from IsUservalid with: ' . $x;
return $x; //END OF FUNCTION
}

#2 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 09 October 2006 - 05:22 PM

Chances are your script has an error and you have error reporting turned off.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#3 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 09 October 2006 - 05:28 PM

You have two conditional statements starting right after you say the method stops.  

1.) if $UTime is not greater than $row['UTime'] then that statement will not fire, are you sure $UTime is assigned the right value?

2.) if ($r does not equal 0 AND $number is not greater than 0 then $x will equal 0, otherwise it would be 1.  Are you sure that $r AND $x are assigned the right values?

3.) are you able to use display_errors = on in PHP.INI

I also noticed you have several OR die()'s,  your method might be breaking on one of them.

P.S When comparing variables to digits it's best to keep the digit outside of single/double quotes  (0 Vs. '0')


Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#4 Hardwarez

Hardwarez
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 09 October 2006 - 08:36 PM

Is it possable to use to many IF statments?  Or make them to long?

I have error reporting turned on, but I'm not getting any errors..

Also, moving my numbers outside the quotes did make the function run completely.  Why whould this have forzen the codes execution?

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 09 October 2006 - 11:28 PM

Also, moving my numbers outside the quotes did make the function run completely.  Why whould this have forzen the codes execution?


Becasue numbers are not strings. Strings are defined within quotes, not numbers.

#6 Hardwarez

Hardwarez
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 11 October 2006 - 02:43 PM

Thank you for the help!
:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users