Lostnode Posted October 1, 2010 Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/ Share on other sites More sharing options...
girish.kc Posted October 1, 2010 Share Posted October 1, 2010 Semicolon missing in the line 21. $type = $_REQUEST['type'] ; I don't think there is any other problem in the code. Link to comment https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117896 Share on other sites More sharing options...
Lostnode Posted October 1, 2010 Author Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117909 Share on other sites More sharing options...
DarkMantis Posted October 1, 2010 Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117910 Share on other sites More sharing options...
Lostnode Posted October 1, 2010 Author Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117913 Share on other sites More sharing options...
Pawn Posted October 1, 2010 Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117933 Share on other sites More sharing options...
DarkMantis Posted October 1, 2010 Share Posted October 1, 2010 Yeahh, I couldn't agree more with Pawn. Always name your Variables to the best possible way you can. Check if the statement has been executed or not Always report errors whilst debugging. Link to comment https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117945 Share on other sites More sharing options...
Lostnode Posted October 1, 2010 Author Share Posted October 1, 2010 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 https://forums.phpfreaks.com/topic/214893-if-statement-not-working/#findComment-1117948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.