Jump to content

if statement not working...


Lostnode

Recommended Posts

Ok, a bit of a background into my code, It runs off of 2 different passing variables, I have it set up with multiple if() statements to do certain things based on the inputs... Here is a snipet of my code

 

if ($_REQUEST['postal'] != "" && $_REQUEST['lbs'] != "") {
    $postal = $_REQUEST['postal'];
    $lbs = $_REQUEST['lbs'];
    $type = $_REQUEST['type']
    if ($type == "splist") {
        $ztype = "cansp_zone" ;
        } else {
        $ztype = "canmp_zone";
        }

 

Obviously not the whole thing, Now what you see is line 18-26 of a 216 line document.  The nested if statement is what is causing the problem, I get a "syntax error, unexpected T_IF" on line 22, the "if ($type)" line.  Now theoretically, if I did not pass the variables (in which case the primary if statement would be false) It should bypass this whole section, however its not.  Any ideas?

 

I am thinking its not actually doing the verification and outputting the error because type is not defined. 

Link to comment
Share on other sites

That worked great... 2 more stumpers now. which now that I look at it, are realted... so may be 1 stumper.

 

I am looking get the exact value of one cell

 

$qP2 = "SELECT $dzone FROM $dstoreid WHERE canmp_lbs = '$lbs'  ";
    $rsP2 = mysql_query($qP2);
    $row2 = mysql_fetch_array($rsP2);
    extract($row2);
    $dzone = trim($dzone);

 

Lines 38-42

 

#1 I get the error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in (file) on line 40

 

Warning: extract() [function.extract]: First argument should be an array in (file) on line 41

 

#2, it outputs the column name, not the value...

 

I tried to modify it to simply be:

 

$qP2 = "SELECT $dzone FROM $dstoreid WHERE canmp_lbs = '$lbs'  ";
    $dzone = mysql_query($qP2);

 

and it output nothing.

 

Link to comment
Share on other sites

if ( ($_REQUEST['postal'] != "") && ($_REQUEST['lbs'] != "") ) {
    $postal = $_REQUEST['postal'];
    $lbs = $_REQUEST['lbs'];
    $type = $_REQUEST['type']
    if ($type == "splist") {
        $ztype = "cansp_zone" ;
        } else {
        $ztype = "canmp_zone";
        }

 

 

The only thing I can see from the code is that you didn't have parenthesis around each if condition. However, that would not cause the script to die. You might have a missing semi-colon ; or something, before the if statement. This is quite common.

 

Also. Just a piece of advice, NEVER, use $_REQUEST, as it has security flaws in it. You should define it with $_POST[''] $_GET[''] or $_COOKIE['']

 

Best Regards,

Mantyy

Link to comment
Share on other sites

The only thing I can see from the code is that you didn't have parenthesis around each if condition. However, that would not cause the script to die. You might have a missing semi-colon ; or something, before the if statement. This is quite common.

 

Also. Just a piece of advice, NEVER, use $_REQUEST, as it has security flaws in it. You should define it with $_POST[''] $_GET[''] or $_COOKIE['']

 

Best Regards,

Mantyy

 

Yeah I know, fixed that, but above your post is the new errors I am getting and how I tried to fix it.

Link to comment
Share on other sites

1) Name your variables properly

2) Check if processes are successful

3) Use the right function for the job

 

 

$sql = "SELECT $dzone FROM $dstoreid WHERE canmp_lbs = '$lbs' LIMIT 1";if(!$query = mysql_query($sql)) {   echo "Error on line ".__LINE__.". ".mysql_error();   exit;}$row = mysql_fetch_row($query);$dzone = trim($row[0]);

 

Link to comment
Share on other sites

fix it all... I was pulling from the wrong "where"  canmp_lbs was supposed to be cansp_lbs

 

Here is what I did (some chunks from her and there..)

 


// From One Section
$type = $_REQUEST['type'];
if ($type == "splist") {
	$ztype = "cansp_zone" ;
	$lbstype = "sp";
	} else {
	$ztype = "canmp_zone";
	$lbstype = "mp";
	}

//From another section I pieced together parts
$dzone = $ztype.$zone;
$dlbs = "can" . $lbstype . "_lbs";
$dstoreid = " store350_can" . $type;


//then used the parts to do the query
$query = "SELECT $dzone FROM $dstoreid WHERE $dlbs = '$lbs'  ";
    $result = mysql_query ($query);
    $row = mysql_fetch_array($result);
    $dzone = $row[0];

 

All worked out, no more errors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.