我有一个包含5列的数据库:join_date,week,done,should和comment。
我有一个insert.php文件:
<body>
<div id="insert">
<?php
if(isset($_POST['add']))
{
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() )
{
$join_date = addslashes ($_POST['join_date']);
$week = addslashes ($_POST['week']);
$done = addslashes ($_POST['done']);
$should = addslashes ($_POST['should']);
$comment = addslashes ($_POST['comment']);
}
else
{
$join_date = addslashes ($_POST['join_date']);
$week = addslashes ($_POST['week']);
$done = addslashes ($_POST['done']);
$should = addslashes ($_POST['should']);
$comment = addslashes ($_POST['comment']);
}
$sql = "INSERT INTO statistika2014 ".
"(join_date, week, done, should, comment ) ".
"VALUES('$join_date','$week','$done','$should', '$comment', NOW())";
mysql_select_db('table');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td><input name="join_date" type="date" id="join_date" ></td>
</tr>
<tr>
<td><input name="week" type="number" id="week" placeholder="week"></td>
</tr>
<tr>
<td><input name="done" type="number" id="emp_done" placeholder="done"></td>
</tr>
<tr>
<td><input name="should" type="number" id="should" placeholder="should"></td>
</tr>
<tr>
<td><input name="comment" type="text" id="comment" placeholder="comment"></td>
</tr>
<tr>
</tr>
<tr>
<td>
<input name="add" type="submit" id="add" value="Submit">
</td>
</tr>
</table>
</form>
<?php
}
?>
</div>
</body>
当我使用这个insert.php文件时,我收到消息: &#34;无法输入数据:列数与第1行和第34行的值计数不匹配; 但我不懂!我有5列和5个值,或者我错了吗?
我正在使用免费主机。他们是否有可能需要刷新一些东西?
请帮忙
答案 0 :(得分:2)
学会数数?
"(join_date, week, done, should, comment ) ".
1 2 3 4 5
"VALUES('$join_date','$week','$done','$should', '$comment', NOW())";
1 2 3 4 5 6???
从什么时候开始5 == 6
?
答案 1 :(得分:0)
您输入Now()作为第六个值
答案 2 :(得分:0)
你的values子句有一个额外的字段NOW(),它对5个字段产生6个值。
"(join_date, week, done, should, comment ) ".
"VALUES('$join_date','$week','$done','$should', '$comment', NOW())";
答案 3 :(得分:0)
你要么想要这个......
//assuming your time column is named timestamp
$sql = "INSERT INTO statistika2014 ".
"(join_date, week, done, should, comment, timestamp ) ".
"VALUES('$join_date','$week','$done','$should', '$comment', NOW())";
或者这......
// Just set your 6th column to TIMESTAMP in your DB and it will auto update on a new insert
$sql = "INSERT INTO statistika2014 ".
"(join_date, week, done, should, comment ) ".
"VALUES('$join_date','$week','$done','$should', '$comment')";
但您明确尝试将6个值插入5列。 在SQL调用中添加第6列。 或者将其设置为自动将数据库中的时间戳更新为NOW,并将其从通话中删除
答案 4 :(得分:0)
您需要为日期或数据库中调用字段添加另一个字段。
$sql = "INSERT INTO statistika2014 ".
"(join_date, week, done, should, comment, date ) ".
"VALUES('$join_date','$week','$done','$should', '$comment', NOW())";