开发者

PHP insert problems

Righ,t so on my website an admin puts the information into a form and then this is sent and becomes a news feed on the main page (Title, Body, Dateposted), but for some reason, (And I've checked against working code) this code is not working and I don't know why, can someone help me?

<?php
        $post = mysql_query("INSERT INTO news(`title`,`body`,`date_posted`) VALUES('$title','$body','$date')开发者_如何学运维");

        mysql_close($connect);

        header("Location: news.php");
    } 
    else 
    {
        echo "The body of the news post you entered is too short.";
    }
} 
?>

my datebase rows:

[id]
[title]
[body]
[date_posted]


This will only work if your ID field is designated as being AUTO-INCREMENTING

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

EDIT

The other technique you could adopt is to put your sql into a variable and when you hit problems you can echo it out onto the page (or into your error_log). It just means doing this:

$sql = "INSERT INTO news(`title`,`body`,`date_posted`) VALUES('$title','$body','$date')";
$post = mysql_query($sql);
// now have an optional line of debug
echo $sql;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜