D-Rizzle Designs
D-Rizzle Designs

Reputation: 11

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

?>

Upvotes: 1

Views: 454

Answers (2)

Marco
Marco

Reputation: 980

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.

Upvotes: 0

JK.
JK.

Reputation: 5136

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');

Upvotes: 3

Related Questions