0

I have several update statements that need to be run upon submit being clicked. I can run a single update but I am struggling to figure out how to run all of them prior to refreshing the page. Here is what I have tried but I am getting an error on my closing of the connection which did not occur when running a single statement.

if ($conn->query($usqlMC)  == True) {
if ($conn->query($usqlSCn)  == True) {
    if ($conn->query($usqlSCv)  == True) {
        if ($conn->query($usqlTn)  == True) {
            if ($conn->query($usqlTurl)  == True) {
                if ($conn->query($usqlTv)  == True) {
                    header("location: http://localhost/phpkiosk/mc1.php");
                } 
            }
        }
    }
}
}

I am sure this is completely wrong so any suggestions on how to fix this would be greatly appreciated. Thanks!!!

ADDED ERROR MESSAGE

Parse error: syntax error, unexpected end of file in C:\wamp2\www\phpKiosk\mc1.php on line 1196

Again I receive no error when I run:

if ($conn->query($usqlMC)  == True) {
    header("location: http://localhost/phpkiosk/mc1.php");
}

WORKING SOLUTION

using Chris85's suggestion I was able to get this to work:

if ($conn->query($usqlMC) === TRUE && 
   $conn->query($usqlSCn) ===TRUE &&
   $conn->query($usqlSCv) ===TRUE &&
   $conn->query($usqlTn) ===TRUE &&
   $conn->query($usqlTurl) ===TRUE &&
   $conn->query($usqlTv) ===TRUE) {
   header("location: http://localhost/phpkiosk/mc1.php");
   } 
}
Craig Howell
  • 1,114
  • 2
  • 12
  • 28
  • What is the error? You could have all those conditions in one `if` with `&&`s. – chris85 Jan 30 '16 at 19:28
  • @chris85 I have updated my question to include the error message – Craig Howell Jan 30 '16 at 19:32
  • 1
    That error usually means one of the control blocks isn't closed. Is that your exact code? Here, make it way simpler; `if ($conn->query($usqlMC) == True && $conn->query($usqlSCn) == True && $conn->query($usqlSCv) == True && $conn->query($usqlTn) == True && $conn->query($usqlTurl) == True && $conn->query($usqlTv) == True) {`. – chris85 Jan 30 '16 at 19:33
  • Redirect when all queries execute if this is required thancu cant use like that u must need to use && – devpro Jan 30 '16 at 19:37
  • U r getting parse error becuase one of them condition false. – devpro Jan 30 '16 at 19:39
  • @chris85 I updated my code using yours and I am still getting the same error... – Craig Howell Jan 30 '16 at 19:42
  • @devpro shouldnt it just do nothing since I dont have an else catch written in? – Craig Howell Jan 30 '16 at 19:43
  • As Chris suggest use && still getting error? – devpro Jan 30 '16 at 19:44
  • 1
    If you updated with my code then the issue is another control block not being closed. The line number is irrelevant with this error because that is where the file ended, it has no idea what you forgot to close. – chris85 Jan 30 '16 at 19:44
  • Yes same error even after switching to && – Craig Howell Jan 30 '16 at 19:45
  • As @Chris85 said I am adding one thing if u r using only one condition your code works fine right.. So debug line by line test with two fields and three so on.. U will get the idea – devpro Jan 30 '16 at 19:46
  • I ended up deleting the entire block and adding it line by line and checking after each line. There must have been a syntax error that was not being picked up because now its working using what @chris85 suggested. Thanks!!! – Craig Howell Jan 30 '16 at 19:52
  • Cool... Good work. Its best practice to debug step by step. :) – devpro Jan 30 '16 at 19:54
  • @devpro I know. I am knew to coding and tend to get a little excitable and get ahead of myself. Thanks for the reminder though :) – Craig Howell Jan 30 '16 at 19:56
  • I'll post that as an answer so the thread is resolved. Note in your update there are two `}`s but only one opening, so that could have been the issue, something else is open. – chris85 Jan 30 '16 at 20:00
  • @chris85 Yes I see. The second is required for the code to work as it is the closing for the if submit condition but for this example it should have been left out. Thanks! – Craig Howell Jan 30 '16 at 20:06

1 Answers1

2

Unless you need separate checks it is easier keep all conditions in one if, that also simplifies the control blocks opening and closing.

So this:

if ($conn->query($usqlMC)  == True &&  
    $conn->query($usqlSCn)  == True && 
    $conn->query($usqlSCv)  == True && 
    $conn->query($usqlTn)  == True && 
    $conn->query($usqlTurl)  == True && 
    $conn->query($usqlTv)  == True) {
          header("location: http://localhost/phpkiosk/mc1.php");
}

should perform the same for you but only require one control block.

Also with the

unexpected end of file

error never believe the line number. That is just where the file is ending not where the error is. PHP has no way of knowing where a block was meant to be closed.

For example:

<?php
if (1==1) {
echo 'this is true';
echo 'I also want to do this';
echo 'I meant to close here';
echo 'code done';

would throw error on line 6 but the error is actually on line 4/5 where I failed to close the if.

chris85
  • 23,846
  • 7
  • 34
  • 51