Hi, I'm learning the ropes with PHP and MySQL at the moment, and I've
run into a puzzle. I'm using PHP to process a form and insert some
simple information into a table. The code doesn't have any glaring
errors, and the mysql_query() doesn't error out, but the info never
gets inserted. And if I run the same query inside the mysql client the
data goes in fine. The query looks like this in PHP:
<?
function addNewStory($title_f, $user_f, $intro_f, $full_f){
global $conn; //included from database.php
$q = "INSERT INTO news_stories (story_title, user_id, date_posted,
intro_text, full_text) VALUES ('$title_f', $user_f, CURRENT_DATE(),
'$intro_f', '$full_f')";
return mysql_query($q, $conn);
}
$user = $_SESSION['user_id'];
$title = $_POST['title'];
$intro = $_POST['intro'];
$full = $_POST['full];
if(!$title || !$intro || !$full){
die('error message');
}else{
addNewStory($title, $user, $intro, $full);
}
?>
The related table is:
+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| story_id | int(8) | NO | PRI | | auto_increment |
| story_title | varchar(62) | NO | | | |
| user_id | int(8) | NO | MUL | | |
| date_posted | date | NO | | | |
| intro_text | varchar(512) | NO | | | |
| full_text | varchar(2048) | NO | | | |
+-------------+---------------+------+-----+---------+----------------+