Need Help with block of code

Greetings All,

I'm puzzled. When I add the code block below to my PHP script my web page goes blank. I've eyeballed it several times and don't see anything wrong. Perhaps there is a kind soul who could review the code and tell me if there are any errors.

I've narrowed my problem down to the do while loop. For some reason my page doesn't like do... while (some condition) loop.

TIA,
Tim
$stock_num = $_SESSION['stocknumber'];
if ($stock_num ^= '') {
$check = "SELECT * FROM recycle_it_in WHERE stock_num='$stock_num'";
$checkResult = mysql_query($check); 
$checkRows = mysql_num_rows($checkResult);
if ((isset($checkRows)) && ($checkRows == 0))
{
	$_SESSION['ri_stocknumber'] = "RI" . rand(000000,999999);
	$is_unique = 'no';
	do {
		$ri_stock_num = $_SESSION['ri_stocknumber'];
		$check2 = "SELECT * FROM recycle_it_in WHERE ri_stock_num='$ri_stock_num'";
		$checkResult2 = mysql_query($check2); 
		$checkRows2 = mysql_num_rows($checkResult2);
		if ((isset($checkRows2)) && ($checkRows2 == 0))
		{
			is_unique = 'yes';
		}
		else {
			$_SESSION['ri_stocknumber'] = "RI" . rand(000000,999999);
		}
	} while (is_unique ^= 'yes');
}
else {
	$row = mysql_fetch_array($checkResult);
	$_SESSION['ri_stocknumber'] = $row['ri_stock_num'];
}
}// closing if ($stock_num ^= '') {

Open in new window

bigmoxyAsked:
Who is Participating?
 
Terry WoodsIT GuruCommented:
Also,

is_unique = 'yes';

needs a $ in front of it:

$is_unique = 'yes';
0
 
shobinsunCommented:
Hi

use '!=' instead of '^='

I dont see any error than this.

Regards.
0
 
shobinsunCommented:
Hi,

Full code should be following:

Regards
$stock_num = $_SESSION['stocknumber'];
if ($stock_num != '') {
$check = "SELECT * FROM recycle_it_in WHERE stock_num='$stock_num'";
$checkResult = mysql_query($check); 
$checkRows = mysql_num_rows($checkResult);
if ((isset($checkRows)) && ($checkRows == 0))
{
        $_SESSION['ri_stocknumber'] = "RI" . rand(000000,999999);
        $is_unique = 'no';
        do {
                $ri_stock_num = $_SESSION['ri_stocknumber'];
                $check2 = "SELECT * FROM recycle_it_in WHERE ri_stock_num='$ri_stock_num'";
                $checkResult2 = mysql_query($check2); 
                $checkRows2 = mysql_num_rows($checkResult2);
                if ((isset($checkRows2)) && ($checkRows2 == 0))
                {
                        is_unique = 'yes';
                }
                else {
                        $_SESSION['ri_stocknumber'] = "RI" . rand(000000,999999);
                }
        } while (is_unique != 'yes');
}
else {
        $row = mysql_fetch_array($checkResult);
        $_SESSION['ri_stocknumber'] = $row['ri_stock_num'];
}
}// closing if ($stock_num != '') {

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Terry WoodsIT GuruCommented:
And:

 } while (is_unique != 'yes');

should be:

 } while ($is_unique != 'yes');

0
 
Michael701Commented:
You can't do this

$_SESSION['ri_stocknumber'] = "RI" . rand(000000,999999);
        $is_unique = 'no';
        do {
                $ri_stock_num = $_SESSION['ri_stocknumber'];


/////////////////

$_SESSION variables are NOT available for reading until the NEXT page view

try something like this

$ri_stock_num = "RI" . rand(000000,999999);
$_SESSION['ri_stocknumber'] = $ri_stock_num
        $is_unique = 'no';
        do {

////////////////

change other read references to the $_SESSION
0
 
shobinsunCommented:
Hi,

Yes ..you miss '$' in two places with is_unique.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.