简体   繁体   English

如何使用 $_POST 在同一页面上获取输入值

[英]How to use $_POST to get input values on the same page

I know that this question was repeated a lot, but I searched a lot of topics and tried many codes without result.我知道这个问题被重复了很多次,但是我搜索了很多主题并尝试了很多代码都没有结果。

First, I get the row number to be deleted from another page, here is no problem.首先,我从另一个页面获取要删除的行号,这里没有问题。

> if(!empty($_GET["del"])){ 
  include("config.php"); $id
> =$_GET["del"];     
> 
> echo ' <ul data-role="listview" data-theme="a"> <li><p
> style="background-color: #FF0000; color:#ffffff" align="center"><font
> size="3" >Will it be permanently deleted?</font></p></li> </ul> ';    
> $result = mysqli_query($con,"SELECT * FROM payment where id='$id'");
> 
> ?>
> 
> <div class="alert alert-dismissible alert-secondary">
> 
> 
> <table class="table table-hover">
>     <thead>
>   
>       <tr class="table-active">
>             <th scope="row">name</th>
>             <td>amount</td>
>                        
>         </tr>
>  
>     </thead>
>     <tbody>
> 
> <?php while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo
> "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['amount'] .
> "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo
> "</div>";
> 
> 
> mysqli_close($con);
> 
> ?>
> 
> <form action="pay.php" method="post" data-ajax='false'>
> 
> <input type="hidden" name="id" id="id" value="<? echo $id;?>" />
> <center><input type="submit" name="del" id="del" value="Delete"  />
> </center> </form>
> 
> 
> <button onclick="goBack()">Back</button> <script> function goBack() {
>     window.history.back(); } </script>

here the code is not work:这里的代码不起作用:

if(isset($_POST['del'])){

$id = $_POST['id'];

$sql = "DELETE FROM payment WHERE id='$id'";


    if ($con->query($sql) === TRUE) {
echo '<p style="background-color: #00d855; color:#ffffff">Deletion successful</p>';
    } else {
        echo "Error deleting record: " . $con->error;
    }

    $con->close();

}

The codes here are all on one page pay.php.这里的代码都在一页上 pay.php。

Any Help?有什么帮助吗?

Your question is confusing as to whether you want to delete a row or get input values on the same page.您的问题令人困惑,您是要删除一行还是要在同一页面上获取输入值。 I'm assuming since you've written that there is no problem with row deletion, you want to know how to input values from say a form on the same page.我假设既然您已经写过删除行没有问题,您想知道如何从同一页面上的表单中输入值。

Suppose you have a form with method = "post" then you can use the following code for any element with name say name = "myelement" :假设您有一个带有method = "post"的表单,那么您可以对任何名称name = "myelement"的元素使用以下代码:

<p>My element is: <?php echo $_POST['myelement']; ?> .</p>

I must say I can't clearly understand your question so I hope this is what you were looking for.我必须说我不能清楚地理解你的问题,所以我希望这就是你要找的。 If it isn't, reply to this and I'll try to help you out.如果不是,请回复此问题,我会尽力帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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