简体   繁体   中英

INSERT statement not working mysql

When I process this data, the data is not being inserted into my database. This is my current database structure:

https://drive.google.com/file/d/0BzJ9StkJe55WaG1oaVhqcUJmSGc/edit?usp=sharing

I have no clue why it is not inserting. I am not getting an error message and I am seeing the successfully inserted data piece.

<head><title>Process Punch</title></head>

<?php

define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'host');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link){
    die('Could not connect: ' .mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}else{

$userid_value = $_POST['userid'];
$punchtype_value = $_POST['punchtype'];
$group_value = $_POST['group'];
$dept_value = $_POST['dept'];
$notes_value = $_POST['notes'];
$table = "tc_".$userid_value;
$date_value = date("Y-m-d h:i:s");
echo $table;
$sql = "INSERT INTO $table (punchtype, groupname, dept, notes) VALUES ('$punchtype_value',     '$group_value', '$dept_value', '$notes_value')";
echo "Successfully inserted data";

}
?>

Execute the query with mysql_query(), concatenate the query

$sql = "INSERT INTO `".$table."` (`punchtype`, `groupname`, `dept`, `notes`) VALUES ('".$punchtype_value."',       '".$group_value."', '".$dept_value."', '".$notes_value."')";
$qry = mysql_query($sql ,$link);
echo "Successfully inserted data";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM