We will be creating four processing pages that each handles one action of the CRUD. We start off with the Create-file, which will INSERT data for us into any database table we desire. To do this we need some additional in-data.
<?php
include("mysq_conn.php");
$fieldNames = $_GET["fieldNames"];
$fieldArray = split(",",$fieldNames);
$table = $_GET["table"];
$datum = time();
for ($i=0; $i < count($fieldArray); $i++) {
$fieldValues = $fieldValues."'".$_GET[$fieldArray[$i]]."',";
}
$fieldValues = htmlspecialchars(substr($fieldValues,0,strlen($fieldValues)-1));
$query = "INSERT INTO ".$table."(".$fieldNames.",dateAdded) VALUES (".$fieldValues.",'".$datum."')";
mysql_query($query);
if (mysql_affected_rows() > 0) {
echo "<h2>NEW ".ucfirst(substr($table,0,strlen($table)-1))." successfully ADDED!</h2>";
}
mysql_close();
?>
Next Up: Listing the database content