gpt4 book ai didi

php - 我在使用此 sql 查询 html/php 时遇到问题

转载 作者:行者123 更新时间:2023-11-29 06:15:37 25 4
gpt4 key购买 nike

你好,我是网页设计的新手,所以如果这看起来像废话,请原谅!

好的,我在这里尝试做的是为每个帖子设置评论。我认为一个很好的方法是运行一个循环并分配 $save_id[]存储帖子 ID 和分配 $r <input type='text' name = *'".$r."'* style = 'width:478px; margin: 0 auto; margin-top:-9px;'id='butt_box' placeholder='Respond?' title = 'Leave a response.' />这似乎工作正常并返回帖子 ID。当我提交评论时 $_POST['$s']它没有注册并且数据库没有更新所以我想我的问题是任何人都可以看到我做错了什么或者具体为什么if(isset($_POST['$s']))失败了?

enter code here $result =  mysql_query("SELECT * FROM user_posts WHERE user ='$name'  ORDER BY time_date DESC LIMIT 100");
$save_id =array();
while($row = mysql_fetch_assoc($result))
{
$save_id[] = $row["id"];
$r = $row["id"];
echo '<div id = "post">';
echo '<img src = "'.$ico.'" style="margin: 0px" width = "48" height = "48" align = "left"/><h4>';echo $name.'</h4><h5>';echo $row["time_date"].'</h5><br>';
echo $row["post"]. '</div>';
echo "<form method='post' action=''>
<input type='text' name = '".$r."' style = 'width:478px; margin: 0 auto; margin-top:-9px;'id='butt_box' placeholder='Respond?' title = 'Leave a response.' />

<input type='submit' value='Post' class='tfbutton' style =' float:right;'>
</form>";
}


if(!$result)
{
echo mysql_error();
}
foreach($save_id as $s)
{

if(isset($_POST['$s']))
{
echo $_POST['$s'];
$mypost = isset($_POST['$s']) ?
$_POST['$s'] : '';

if(isset($mypost) && strlen($mypost) > 0)
{
$text = addLinks($mypost);
$text = CheckEmotes($text);

$p = $text;
$emote = "none";
$dt = date('Y-m-d H:i:s');

$sql = "INSERT INTO `user_post_comments`(poster,post_id,responder,response,post_date)
VALUES('$name','$s','$name',$text',$dt')";
$rg = mysql_query($sql);

if(!$rg)
{
echo mysql_error();
}
}
//header("Refresh:5; url=refresh.php");
}
}

最佳答案

$_POST['$s'] should be $_POST[$s] ($s without the quotes)

这是真的。这背后的原因是因为您的 $_POST 将您的变量 ($s) 视为 text。由于引号,它认为它不是变量。删除它应该可以解决问题。

更新,这一行看起来有点奇怪:

 mysql_query("SELECT * FROM user_posts WHERE user ='$name'  ORDER BY time_date DESC LIMIT 100");

我希望在删除引号后您的问题得到解决,但如果不是这种情况,id 建议像这样更改您的查询:

$selectAllFromUser = "SELECT * FROM user_posts WHERE user ='".$name."' ORDER BY time_date DESC LIMIT 100";
mysql_query($selectAllFromUser);

您的查询也有可能将您的 $name 变量视为文本。 (虽然我不知道你的版本等细节)

(编辑;已经很长时间了,但我认为这应该让你继续)。

enter code here 
$selectAllFromUser= "SELECT * FROM user_posts WHERE user ='".$name."' ORDER BY time_date DESC LIMIT 100";
$result = mysql_query($selectAllFromUser);
$save_id =array();
while($row = mysql_fetch_assoc($result))
{
//not working with arrays often, but shouldnt it be required to specify a // position?
$save_id[] = $row["id"];
$r = $row["id"];
echo '<div id = "post">';
echo '<img src = "'.$ico.'" style="margin: 0px" width = "48" height = "48" align = "left"/><h4>{$row["id"]}</h4><h5>{ $row["time_date"]}</h5><br>{$row["post"]}</div>';
echo "<form method='post' action=''>
<input type='text' name = '".$r."' style = 'width:478px; margin: 0 auto; margin-top:-9px;'id='butt_box' placeholder='Respond?' title = 'Leave a response.' />

<input type='submit' value='Post' class='tfbutton' style =' float:right;'>
</form>";
}


if(!$result)
{
echo mysql_error();
}
foreach($save_id as $s)
{

if(isset($_POST[$s]))
{
echo $_POST[$s];
$mypost = isset($_POST[$s]) ?
$_POST[$s] : '';

if(isset($mypost) && strlen($mypost) > 0)
{
$text = addLinks($mypost);
$text = CheckEmotes($text);

$p = $text;
$emote = "none";
$dt = date('Y-m-d H:i:s');
//again using the $s without setting a position, is this valid?
$sql = "INSERT INTO `user_post_comments`(poster,post_id,responder,response,post_date)
VALUES('{$name}','{$s}','{$name}','{$text}','{$dt}')";
$rg = mysql_query($sql);

if(!$rg)
{
echo mysql_error();
}
}
//header("Refresh:5; url=refresh.php");
}
}

关于php - 我在使用此 sql 查询 html/php 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36079129/

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