INSERT语句不能正常工作

时间:2014-07-20 07:53:00

标签: php mysql

处理此数据时,数据未插入到我的数据库中。这是我目前的数据库结构:

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

我不知道为什么不插入。我没有收到错误消息,我看到成功插入的数据片段。

<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";

}
?>

1 个答案:

答案 0 :(得分:1)

使用mysql_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";