I have some PHP code that takes a post from the index and then allows you to log in. When i run it it say:
parse error: unexpected $end;
If anyone has any ideas please let me know ASAP because need it for a class in school.
<?php
$uname = $_POST["username"];
$resultCount = 0;
class MyDB extends SQLite3
{
function __construct()
{
$this->open('users.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
}
$sql =<<<EOF
SELECT $uname from users;
EOF;
$ret = $db->exec($sql);
foreach($ret as $uname){
$resultCount++;
}
if($resultCount > 1){
echo "failed to log in!";
echo "please return <a href='index.php'>home</a>";
}
else{
echo "logged in succesfully!";
echo "welcome" . $_POST[username];
}
?>
$_POST[username](2nd to last line) should be$_POST["username"]. There might be more syntax errors.$sql = "SELECT $uname from users";instead. ATTENTION! Smells like SQL injection issue...SELECT $uname from users;this is going to bite you. You probably want to select a column for a specific user and not a specific column. And the heredocEOF;cannot have any spaces before it, it has to be at the beginning of the line.