Kez323 Posted June 17, 2016 Share Posted June 17, 2016 (edited) Hi! I'm getting this PHP syntax error on line 87 of my file. ERROR: PHP Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) The function works fine, if I take the function out of that file and put it into a separate file, it works fine. function get_UserId($username){ include('config.php'); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT id FROM users WHERE username='$username'"; $result = $conn->query($sql); $row = $result->fetch_assoc(); $id = $row['id']; $conn->close(); return $id; } Thanks Edited June 17, 2016 by Kez323 Quote Link to comment https://forums.phpfreaks.com/topic/301354-syntax-error-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
Jacques1 Posted June 17, 2016 Share Posted June 17, 2016 It's not the function, it's what comes before that. Your query is also vulnerable to SQL injection attacks. Learn to use prepared statements. Quote Link to comment https://forums.phpfreaks.com/topic/301354-syntax-error-unexpected-t_encapsed_and_whitespace/#findComment-1533772 Share on other sites More sharing options...
ginerjm Posted June 17, 2016 Share Posted June 17, 2016 I would have expected you to actually show us the LINE IN QUESTION instead of talking about some function working "fine". Your line numbers (a PIA when you cut and paste your code!) - are they really the line numbers that the error message refers to or just some editor lines numbers that you pasted here? The line: $id = $row['id']; certainly doesn't have any problem so the " in the error message must be located somewhere else. Does the error message refer to another file perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/301354-syntax-error-unexpected-t_encapsed_and_whitespace/#findComment-1533778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.