开发者

Form data won't add and MySql table remains empty

I know this is not a safe way for inserting data into mysql but this is just for example! Please this script is not adding any data int开发者_如何学编程o mysql table with these fields:

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

?>


Your column name update is a reserved word and need special treatment. Use double quotes with ANSI SQL mode enabled, or back ticks.

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html.

INSERT into newsfeed (cid,`update`,time) values ('$cid1','$update','$time');


One important thing is that you should take care of reserved MySql statements. The next thing is that you should add a or die(mysql_error()) after your mysql_query(). As you didn't use it, you didn't receive a mysql error.

Then reformat your query to:

INSERT INTO `newsfeed` (`cid`,`update`,`time`) VALUES ('$cid1','$update','$time')

Remember: update and time are reserved statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜