HTML表单操作url ID,等于从表中获取的php变量 [英] HTML form action url ID to equal php variable fetched from a table

查看:63
本文介绍了HTML表单操作url ID,等于从表中获取的php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我只是想提交一个表单,然后将该表单转到具有从数据库表中获取的页面ID的页面,我目前在我的网站中完成此操作,但在表单.这是我的表格,其中包含一些我的sql:

Hi all im having a problem i simply want to submit a form and for that form to go to a page with the page id that is fetched from a table in my database, ive currently done this with in my website but not in a form. Here is my form with a few my sql:

    $sqltopics = "SELECT topic_id, topic_subject, topic_date, topic_cat FROM `forum_topics` WHERE topic_id =  ". mysqli_real_escape_string($conn, $_GET['id']) or die(mysqli_error()); 
$resulttopics = $conn->query($sqltopics);        
while($rowtopics = $resulttopics->fetch_array(MYSQLI_ASSOC))
{
$topicname = $rowtopics['topic_subject'];
$topicid = $rowtopics['topic_id'];
}

$sqlposts = "SELECT post_id, post_content, post_date, post_by FROM `forum_posts` WHERE post_topic = ". mysqli_real_escape_string($conn, $_GET['id']) or die(mysqli_error()); ; 
$resultposts = $conn->query($sqlposts);        
$row_cntposts = $resultposts->num_rows;

               <form method="post" action="test.php?id=">
        <input type="text" name="reply-content" maxlength="255" size="255" ><br />
        <input type="submit" value="Submit reply" />
        </form>

我正在寻找的是"test.php?id =以等于topic_id,即$ topicid.

What im looking for is the "test.php?id=" to equal the topic_id which is $topicid.

我以前做过这样的事情,例如我用href表示的例子:

I have previously done something like this like i said with href here is the example:

echo '<h3><a href="topic.php?id=' . $rowtopics['topic_id'] . '">' . $rowtopics['topic_subject'] . '</a></h3>';

这是在其他页面上,但是我确定您可以看到即时消息来自何处.如何将变量放入表单?

This is on a different page but im sure you can see where im coming from. How can i put the variable in the form?

谢谢.

推荐答案

创建一个隐藏的输入并将主题ID传递为其值

Create a hidden input and pass the topic id as its value

<input type="hidden" name="topic_id" value="<?php  echo $topic_id ?>" >

提交表单时,您可以从全局变量 $ _ POST

When you submit the form you can access the topic id from the global variable $_POST

$topid_id = $_POST['topic_id'];

希望获得帮助.

这篇关于HTML表单操作url ID,等于从表中获取的php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆