[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need Help with block of code

Posted on 2009-04-19
6
Medium Priority
?
171 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:bigmoxy
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24182040
Hi

use '!=' instead of '^='

I dont see any error than this.

Regards.
0
 
LVL 14

Assisted Solution

by:shobinsun
shobinsun earned 600 total points
ID: 24182054
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
 
LVL 35

Accepted Solution

by:
Terry Woods earned 1000 total points
ID: 24182092
Also,

is_unique = 'yes';

needs a $ in front of it:

$is_unique = 'yes';
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 35

Expert Comment

by:Terry Woods
ID: 24182094
And:

 } while (is_unique != 'yes');

should be:

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

0
 
LVL 19

Assisted Solution

by:Michael701
Michael701 earned 400 total points
ID: 24182112
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
 
LVL 14

Expert Comment

by:shobinsun
ID: 24182138
Hi,

Yes ..you miss '$' in two places with is_unique.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question