简体   繁体   中英

Search and insert the search results in database in PHP

I've two forms in a single page. One form fetches data from database table. In the other form I need those fetched values to be added in another table, with additional values.

<form method="post" action="same.php" name="form1">
<input type="text" name="search" />
<input type="submit" name="result" value="search_for" />
</form>

<form method="post" action="same.php" name="form2">
<input type="date" name="add_date" />
<input type="submit" name="result" value="search_for" />
</form>

After searching I will get values in a variable $search .

Now I need to post the variable $search in another table, but when I click submit the search values get null.

i don't think you can do this you have only one way to do this is to include all input's in to one form

i think you can do this by 2 way

  1. putting all input in one form

or you can do this by making two step as

page 1 contains form one and page2 contain form2 as follows

page 1

<form method="post" action="same.php" name="form1">
<input type="text" name="search"/>
<input type="submit" name="result" value="search_for">
</form>

page 2

<form method="post" action="same.php" name="form2">
//data from page1 {form1} 
<input type="hidden" name="search" value=<?php echo $_POST['search']; ?> />

//you will not need this
<input type="submit" name="result" value="search_for">

<input type="date" name="add_date"/>
<input type="submit" name="result" value="search_for">
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM