gpt4 book ai didi

php 没有将正确的值存储到数据库中

转载 作者:行者123 更新时间:2023-12-01 00:23:41 25 4
gpt4 key购买 nike

所以我需要php来存储$aid,它应该是用户当前正在评论的文章的ID,但是它总是将它保存为0,例如当我在页面localhost/article上时。 php?article_id=69 并写入 echo $aid;它会回显 69,但是当我想将它存储到数据库中时,它只是将它存储为 0

if (isset($_GET['article_id'])) {

include("mySQLcon.inc.php");
$aid = mysql_real_escape_string($_GET['article_id']);
$query = "SELECT * FROM front_articles WHERE id = '$aid'";
$sql = mysql_query($query);

}

while ($articles = mysql_fetch_object($sql)) {
?>
<div id="IApage">
<?php
echo '<b>' . $articles->title.'</b>'.'<br>'.
$articles->message. '<br>';
?>
</div>
<?php
}
if(isset($_COOKIE['user'])){
?>
<div id="article_comment_form">
<form id="arti_com_form" name="article_com_for" method="post" action="article.php">
<textarea name="comment" rows="7" cols="50"></textarea><br>
<input name="com_submit" type="submit" value="Comment"/>
</form>
</div>
<?php
}
if (isset($_POST['com_submit'])) {
$comment_message = $_POST['comment'];
$comment_query = mysql_query("INSERT INTO front_article_comments (article_id, poster_id, poster_username, message, date) VALUES ('$aid', '$poster_id', '$username', '$comment_message', NOW())");
}
echo $aid;
?>

最佳答案

如果 article_id 在您的数据库中属于 INT 类型,并且您为其提供一个 STRING,它将作为 0 插入。

尝试删除单引号。

此外,如果您打算升级 PHP,请尽早习惯使用 PDO,这样当您最终决定升级时就不必返回并更改所有内容。

关于php 没有将正确的值存储到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com