DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   HELP: Undefined variable (http://www.daniweb.com/forums/thread165231.html)

mattbaker Dec 31st, 2008 9:42 am
HELP: Undefined variable
 
Help!
I keep getting the following error:

<b>Notice</b>: Underfined variable: theHash in <b>C:\wamp\www\HelloSeanThisIsForYourMyFriend.php</b>on line<b>46</b><br/>
f5bd6294083c680ec4a0e05bf1dbce38


From file:
<?php
/*--------------------------------------------------------------------------------------
-       
-
 -
  -
 -
  -
  -
  -
-

-
 -
 -
 -
-
-
--
-
//
$theMD5 = md5("ayht" . $_POST["rn"] . "thy", 1);

$hexArr[0] = "0";
$hexArr[1] = "1";
$hexArr[2] = "2";
$hexArr[3] = "3";
$hexArr[4] = "4";
$hexArr[5] = "5";
$hexArr[6] = "6";
$hexArr[7] = "7";
$hexArr[8] = "8";
$hexArr[9] = "9";
$hexArr[10] = "A";
$hexArr[11] = "B";
$hexArr[12] = "C";
$hexArr[13] = "D";
$hexArr[14] = "E";
$hexArr[15] = "F";
       
for($i=0;$i<strlen($theMD5);$i++)
{
        $tmp1 = ord($theMD5[$i]) / 16;
        $tmp2 = ord($theMD5[$i]) % 16;

        $theHash = $theHash. $hexArr[$tmp1] . $hexArr[$tmp2];
}

$theHash = strtolower($theHash);

echo $theHash;
?>


Is there a simple fix to this please?

buddylee17 Dec 31st, 2008 11:58 am
Re: HELP: Undefined variable
 
Set $theHash equal to empy before the for loop.
Also, I think you'll want to poulate $theHash like this:
$theHash="";
for($i=0;$i<strlen($theMD5);$i++)
{
        $tmp1 = ord($theMD5[$i]) / 16;
        $tmp2 = ord($theMD5[$i]) % 16;

        $theHash.= $hexArr[$tmp1] . $hexArr[$tmp2];
}


All times are GMT -4. The time now is 11:57 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC