我知道这不是一个安全的方式插入数据到mysql,但这只是一个例子!请不要在mysql表中添加这些字段:
<?php
session_start();
if(!isset($_SESSION['c_id']) || !isset($_SESSION['sid']) ||!isset($_SESSION['ip'])) {
header("Location: login.php");
exit;
}
?>
<?php
$cid1= $_POST['hiddencid'];
$update= $_POST['hiddenupdate'];
$time = strftime("%b %d %Y %X");
mysql_connect('localhost', 'xxx', 'xxx') or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
mysql_query("INSERT into newsfeed (cid,update,time) values ('$cid1','$update','$time')");
echo "Profile Updated";
?>
列名update是保留字,需要特殊处理。在启用ANSI SQL模式时使用双引号,或者反引号。
http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html。
INSERT into newsfeed (cid,`update`,time) values ('$cid1','$update','$time');
一个重要的事情是你应该注意保留MySql语句。下一件事是你应该在你的mysql_query()
后面加上一个or die(mysql_error())
。因为你没有使用它,所以你没有收到mysql错误。
然后将您的查询重新格式化为:
INSERT INTO `newsfeed` (`cid`,`update`,`time`) VALUES ('$cid1','$update','$time')
注意:update
和time
是保留语句