Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过使用HTML表单插入ID_Php_Html_Sql_Web - Fatal编程技术网

Php 通过使用HTML表单插入ID

Php 通过使用HTML表单插入ID,php,html,sql,web,Php,Html,Sql,Web,我有一个关于使用PHP和html表单在数据库中插入外键ID的快速查询 我的评论数据库设置如下: Comment_ID PK Name Comment_Body Recipe_ID FK 食谱: HTML/PHP: *<input type="hidden" class="form-control" name="Recipe_ID" autofocus value=<?php echo $row["Recipe_ID"]; ?> readonly&g

我有一个关于使用PHP和html表单在数据库中插入外键ID的快速查询

我的评论数据库设置如下:

Comment_ID PK
Name
Comment_Body
Recipe_ID FK 
食谱:

HTML/PHP:

      *<input  type="hidden" class="form-control"  name="Recipe_ID" autofocus value=<?php echo $row["Recipe_ID"];   ?>    readonly>
Name: <input type="text" class="form-control" name="name" required autofocus> 
Comment: <input type="text" class="form-control" name="comment_body" required autofocus> </br>*
PHP变量和SQL:

$id = $_GET["Recipe_ID"];*
         *$sqlcomment = "SELECT * FROM comment WHERE Recipe_ID = '". $id . "'"; 
         $commentsresult = mysqli_query($con, $sqlcomment);
         $row = mysqli_fetch_assoc($commentsresult);*
查看配方时,将显示与配方ID 1相关的所有注释

HTML表单不会发布配方ID,因为在查看特定配方页面时找不到该ID

如何使用HTML表单将特定ID发布到数据库?这是否适合在我的设计中为各种食谱创建注释


非常感谢。

您的表单应该使用$id或$u-GET[Recipe\u-id],而不是$row[Recipe\u-id]。如果用于获取注释的SQL没有返回任何行,那么将根本没有$row[Recipe\u ID]

同时,您已经将所需的ID传递到页面中。我假设它是作为POST参数传递的——这就是构造SQL语句的方式

因此,请尝试以下形式:

<input  type="hidden" name="Recipe_ID" autofocus value=<?php echo $id; ?>

表单应该在隐藏的输入中包含配方ID。为整理我之前的帖子干杯。不要用这么多!我的PHP页面设置主页,由各种配方组成,带有动态URL->下一页,该页获取所选配方的ID,表单显示为“只读”,仅此而已。我不确定我哪里出错了。你需要在一个循环中调用mysqli\u fetch\u assoc来获取所有注释。在问题中发布你的代码。看到了吗,既然你还没有显示表单的代码,我怎么知道它为什么没有发布?很好,将ID发布到数据库中,谢谢。现在我必须找到一种方法来显示具有相同配方ID的所有注释。因此,如果配方ID=7,那么将显示与配方7相关的所有注释。我有一个select all from comments,其中recipe_id=$id我猜,因为我已经显示了一个特定的get id,所以我无法获得用于显示与此相关的所有注释的相同id?值得一提的问题是:while$row=mysqli_fetch_assoc$commentsresult{printf%s%s\n,$row[Name],$row[注释_body];}
$id = $_GET["Recipe_ID"];*
         *$sqlcomment = "SELECT * FROM comment WHERE Recipe_ID = '". $id . "'"; 
         $commentsresult = mysqli_query($con, $sqlcomment);
         $row = mysqli_fetch_assoc($commentsresult);*
<input  type="hidden" name="Recipe_ID" autofocus value=<?php echo $id; ?>