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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shobinsunCommented:
Hi

use '!=' instead of '^='

I dont see any error than this.

Regards.
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

Terry WoodsIT GuruCommented:
Also,

is_unique = 'yes';

needs a $ in front of it:

$is_unique = 'yes';

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Terry WoodsIT GuruCommented:
And:

 } while (is_unique != 'yes');

should be:

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

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
shobinsunCommented:
Hi,

Yes ..you miss '$' in two places with is_unique.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.