I’m getting an
Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
ERROR when I’m using the code directly below.
<?php
$query = dbConnect()->prepare("SELECT `firstname`, `lastname` FROM `loaders` ");
$query->execute();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $rows){
echo "<option value=\\"$rows['firstname']\\">", $rows['firstname'], ' ', $rows['lastname'], '</option>';
}
?>
But when I run the code:
echo '<option value="firstname">', $rows['firstname'], ' ', $rows['lastname'], '</option>';
It displays all the users, but doesn’t submit the information into the database, into process.php
process.php
<?php
if(isset($_POST['firstname'], $_POST['lastname'], $_POST['notes'], $_POST['time'])){
require 'core/connect.php';
$query = dbConnect()->prepare("INSERT INTO `loaders` (firstname, lastname, notes, time) VALUES (:firstname, :lastname, :notes, :time)");
$query->bindParam(':firstname', $_POST['firstname']);
$query->bindParam(':lastname', $_POST['lastname']);
$query->bindParam(':notes', $_POST['notes']);
$query->bindParam(':time', $_POST['time']);
if($query->execute()){
header('Location: index.php');
} else {
echo 'There has been an error';
}
}
?>