Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

HTML form action url ID to equal php variable fetched from a table

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>

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

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?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

$topid_id = $_POST['topic_id'];

hope this help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...