user1788542
user1788542

Reputation:

inserting date time into table

I am inserting few values including time into table. But here all other attr are being stored except datatime.

query:

$date = strtotime(date("Y-m-d H:i:s"));
$insertQuery2 = "INSERT INTO userpost(`userid`, `url`, `desc`, `preview`, `img_url`, `title` ,`hash`,`time`) 
VALUES     ('".$user_id."','".$url."','".$content."','".$Preview."','".$logo."','".$title_display."','".$hash."','".$rate."','".$date."')";

table:

mysql> desc userpost;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| userid  | varchar(40)   | NO   | PRI |         |       |
| url     | varchar(255)  | YES  |     | NULL    |       |
| desc    | varchar(2048) | YES  |     | NULL    |       |
| preview | varchar(255)  | YES  |     | NULL    |       |
| img_url | varchar(128)  | YES  |     | NULL    |       |
| title   | varchar(128)  | YES  |     | NULL    |       |
| hash    | varchar(128)  | NO   | PRI |         |       |
| rate    | varchar(16)   | YES  |     | NULL    |       |
| time    | varchar(64)   | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+

Upvotes: 0

Views: 82

Answers (1)

Krish R
Krish R

Reputation: 22711

Column count doesn't match, ,'".$rate."' you are added $rate value in insert query

 $insertQuery2 = "INSERT INTO userpost(`userid`, `url`, `desc`, `preview`, `img_url`, `title` ,`hash`,`time`)
VALUES     ('".$user_id."','".$url."','".$content."','".$Preview."','".$logo."','".$title_display."','".$hash."','".$date."')";

Added rate column and its value ,

   $insertQuery2 = "INSERT INTO userpost(`userid`, `url`, `desc`, `preview`, `img_url`, `title` ,`hash`,`rate`,`time`)
VALUES     ('".$user_id."','".$url."','".$content."','".$Preview."','".$logo."','".$title_display."','".$hash."','".$rate."','".$date."')";

Upvotes: 2

Related Questions