Jump to content

Unexplainable error_log. Maybe a fresh set of eyes can shed some light on this


dzhax
 Share

Recommended Posts

OK so i am working on this click to tweet script and I am basically checking the database to make sure it doesn't already exist before inserting it into the database.

 

I am getting the following error_log

[29-Jun-2014 18:55:07] PHP Parse error:  syntax error, unexpected T_STRING in /.../c2t/tweet.html on line 72

Here is the relative code:

<?     if(isset($_GET['tweet'])){          $string = urlencode($_GET['tweet']);          $crc32 = crc32($string);          $con = mysqli_connect("localhost","USER","PASSWORD","DATABASE");          if(!$con){               die('Database Unavailable');          }          $query = "SELECT * FROM `redirect` WHERE `crc32` = '".$crc32."');								          if ($result = $mysqli->query($query)) {               $row_cnt = $result->num_rows;   		 							               if($row_cnt > 0){                    echo 'This Click 2 Tweet Already Exists!<br /><br />';               } else {                    //$query2 = "INSERT INTO `redirect` (`crc32`,`tweet`,`created-by`) VALUES ('".$crc32."','".$string."','".$_SERVER['REMOTE_ADDR']."')";                    //$mysqli->query($query2);                    echo 'Here is your Click 2 Tweet. Enjoy!<br /><br />';               }               $result->close();          }     }     echo 'http://c2t.co/'.$crc32;?>

Any help would be greatly appreciated.

Edited by dzhax
Link to comment
Share on other sites

I don't know if this will fix it or not, but give this a try.....

<?phpif(isset($_GET['tweet'])){      $string = urlencode($_GET['tweet']);      $crc32 = crc32($string);      $con = mysqli_connect("localhost","USER","PASSWORD","DATABASE");            if(!$con){                  die('Database Unavailable');            }      $query = "SELECT * FROM redirect WHERE crc32 = $crc32";      if ($result = $mysqli->query($query)) {            $row_cnt = $result->num_rows;                  if($row_cnt > 0){                        echo 'This Click 2 Tweet Already Exists!<br /><br />';                  }                  else {                        $query2 = "INSERT INTO redirect(crc32,tweet,created-by) VALUES ('$crc32','$string','$_SERVER['REMOTE_ADDR'])";                        $mysqli->query($query2);                              echo 'Here is your Click 2 Tweet. Enjoy!<br /><br />';                       }                  $result->close();      }}echo 'http://c2t.co/'.$crc32;?>

I changed your `(back tick) to '(single quote) and removed what didn't look correct to me (following code I have used in the past).

 

Also, it's not a good idea to use PHP short tags (so I've been told) even if they are turned on on your server. (ie... changed <? to <?php)

Edited by scout1idf
Link to comment
Share on other sites

took a different approach at this. Letting the database handle the duplicate instead of php.

 

added ON DUPLICATE KEY UPDATE to the INSERT INTO query.

 

thanks for looking into it :Happy:

Link to comment
Share on other sites

You can try this if it helps:

$query2 = "INSERT INTO redirect(crc32,tweet,created-by) VALUES ('{$crc32}','{$string}','{$_SERVER['REMOTE_ADDR']})";

or

$query2 = "INSERT INTO redirect(crc32,tweet,created-by) VALUES ('" . $crc32 . "','" . $string . "','" . $_SERVER['REMOTE_ADDR'] . "')";
Edited by Don E
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...