Hi, I cannot figure out what is wrong with this and was hoping you guys could help

I keep getting Parse error: syntax error, unexpected T_STRING, expecting '('


<?php

include_once("utils.php");

$SECRET = xxxxxxxxxxx;


$sig = md5($_REQUEST['lt_users_tranid'] . ':' . $_REQUEST['new'] . ':' . $_REQUEST['lt_users_id'] . ':' . $SECRET);


if ($_REQUEST['sig'] == $sig){



$tranid = $_POST["lt_users_tranid"];

$query = mysql_query("SELECT * FROM lt_users WHERE lt_users_tranid='$tranid')");

if (mysql_num_rows($query) != 0)
{
mysql_query("update lt_users set lt_users_balance=lt_users_balance+'$_REQUEST[new]' where lt_users_tranid='$_REQUEST[lt_users_id]')");
}
elseif

mysql_query("INSERT INTO lt_users (lt_users_tranid, lt_users_balance) VALUE ('$_REQUEST[lt_users_tranid]','$_REQUEST[new]')");
}

  echo "1";
}
else{
      echo "0";
}

?>

    You have an elseif just hanging out there by itself, but an elseif must have a parenthesized condition, just like an if does (and you'll probably want a curly brace, too 😉 ).

    That being said, if the objective is to first try to do an update, and if no rows are affected do an insert instead, you could save yourself a query by just doing an insert to begin with, and use the ON DUPLICATE KEY UPDATE syntax, instead.

      Thanks, I've fixed that but now I get an Parse error: syntax error, unexpected $end in C:\wamp\www\auct\postback.php on line 27

      
      
      <?php 
      
      include_once("utils.php"); 
      
      $SECRET = xxxxxxxxxxxxxxxxxxxxx; 
      
      $tranid = $_POST["lt_users_tranid"]; 
      
      $sig = md5($_REQUEST['lt_users_tranid'] . ':' . $_REQUEST['new'] . ':' . $_REQUEST['lt_users_id'] . ':' . $SECRET); 
      
      
      if ($_REQUEST['sig'] == $sig){ 
      
      
      $query = mysql_query("SELECT * FROM lt_users WHERE lt_users_tranid='$tranid')"); 
      
      if (mysql_num_rows($query) != 0) 
      { 
      mysql_query("update lt_users set lt_users_balance=lt_users_balance+'$_REQUEST[new]' where lt_users_tranid='$_REQUEST[lt_users_id]"); 
      } 
      elseif (mysql_num_rows($query) != 1) 
      {
      mysql_query("INSERT INTO lt_users (lt_users_tranid, lt_users_balance) VALUE ('$_REQUEST[lt_users_tranid]','$_REQUEST[new]"); 
      } 
      
      php?>
      
      

        You end php code with a ?> not a php?>. You had that bit right the first time!

          opps, ya I tried both just to see if that was the problem neither of them worked

            #1 cause of 'unexpected $end': missing '}' brace.

            Sure enough, the '{' on this line:

            if ($_REQUEST['sig'] == $sig){ 

            is never closed.

              If you get yourself a decent IDE it will point out these errors to you. Netbeans or Eclipse are pretty capable.

              If you prefer a simple text editor, look at Notepad++ on Windows, Kate on Linux or Coda for the Mac. Each of these offer a feature that highlights the pair if you select a single opening or closing bracket/brace. This is useful in determining if you're missing one.

              It's also well worth looking into the Allman indenting style (http://en.wikipedia.org/wiki/Indent_style#Allman_style) for coding, which means these kinds of errors are very unlikely to happen. Sure it uses a few extra lines up because each bracket/brace is on its own line, but having everything lined up nice and neat is worth so much when you're coding!

                Ashley Sheridan;10982510 wrote:

                If you prefer a simple text editor, (...) offer a feature that highlights the pair if you select a single opening or closing bracket/brace.

                I believe emacs is worth mentioning as well. Not sure if it qualifies as "simple", but it does have functionality for finding matching brackets, works for pretty much any language you use, and probably exists for any OS you'll ever use.

                  Write a Reply...