I have this php code, no error is thrown but the data is not inserted to the table and no table is created, can you please tell me where i am going wrong?
Cheers in advance 🙂
DB_Functions.php
private $db;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
public function storeUnit($email, $units, $maint, $attent, $done) {
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error());
mysql_select_db(DB_DATABASE, $con);
$format = 'Y-m-d G:i:s';
$date = date($format);
$result = mysql_query("CREATE TABLE IF NOT EXISTS $email( Units VARCHAR(10), Finish VARCHAR(20), Attent VARCHAR(200), Maint VARCHAR(200), created_at VARCHAR(30))",$con);
$result = mysql_query("INSERT INTO '$email'(Units, Finish, Attent, Maint, created_at) VALUES('$units', '$done', '$attent', '$maint', '$date')");
return true;
}
try using ` instead of ‘ for tablename
Edit : Try looking if your database uses InnoDB, you may use transactional mode… so you must commit changes if autocommit is disabled