If you want more of my pastes visit: https://randompaste.000webhostapp.com/index.html
--------------------------------------------------------------------------------------
setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM modules";
//output in a table form
echo "
SQL Query using PDO showing results in Table form
";
echo "
";
echo "| Code | Name | Lecturer |
";
foreach ($conn->query($sql) as $row) {
echo " | " . $row["code"] .
" | " . $row["name"] .
" | " . $row["lecturer"] . " |
";
}
//end for each
//defining variables to enter into database
$sqlValueCode="";
$sqlValueName="";
$sqlValueLecturer="";
?>
". $modCode . "
" . $modName . "
". $lectName ;
//define sql insert command
$sqlAdd= "INSERT INTO modules (code, name, lecturer) values ("."'$sqlValueCode',"." '$sqlValueName',"." '$sqlValueLecturer')";
//only inserting data if variables have been set
if ($sqlValueCode != NULL or $sqlValueName != NULL or $sqlValueLecturer != NULL) {
//executing sql insert command
$conn->exec($sqlAdd);
echo "entry added successfully";
} else {
echo "could not add the entry";
}
?>