Jump to content
Sign in to follow this  
dzhax

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

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

Share this post


Link to post
Share on other sites

for the record line 72 and 73 were originally not commented out and it was still producing the same error log.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

ok i will give it a shot but it still doesn't explain why the error log is telling me the string is wrong when it was commented out.

Share this post


Link to post
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:

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...