dzhax Posted June 30, 2014 Share Posted June 30, 2014 (edited) 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 June 30, 2014 by dzhax Link to comment Share on other sites More sharing options...
dzhax Posted June 30, 2014 Author Share Posted June 30, 2014 for the record line 72 and 73 were originally not commented out and it was still producing the same error log. Link to comment Share on other sites More sharing options...
scout1idf Posted June 30, 2014 Share Posted June 30, 2014 (edited) 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 June 30, 2014 by scout1idf Link to comment Share on other sites More sharing options...
dzhax Posted June 30, 2014 Author Share Posted June 30, 2014 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. Link to comment Share on other sites More sharing options...
dzhax Posted June 30, 2014 Author Share Posted June 30, 2014 still throwing the same error. Link to comment Share on other sites More sharing options...
dzhax Posted June 30, 2014 Author Share Posted June 30, 2014 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 More sharing options...
Don E Posted June 30, 2014 Share Posted June 30, 2014 (edited) 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 June 30, 2014 by Don E Link to comment Share on other sites More sharing options...
justsomeguy Posted June 30, 2014 Share Posted June 30, 2014 The original error was a missing quote on line 64. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now