doufu7464 2018-10-09 10:03
浏览 30

错误的值os按钮项目正在使用PHP发送

I have this apply page where i'm listing different jobs one can apply for each job has specific values and id, i'm listing all the values dynamically.

i'm printing the sql data inside an html table, now what i wanted to do was when i click on apply in want to process and send the job id to another page, but what is happening is same job id is being sent to the process page , regardless os which row's apply button i click on

1.apply.php

<?php 
include("db.php");
session_start();
$result=mysqli_query($con,"SELECT * FROM news_upload order by id desc");
?>


<form action='process.php' method='post'>
    <table class="table table-bordered">  
        <tr>  
            <th width="5%">Job ID</th> 
            <th width="13%">Apply</th>                             
            <th width="10%">Date Uploaded</th>  
            <th width="33%">Job Title</th> 
            <th width="22%">Education</th> 
            <th width="10%">Salary</th>  
            <th width="12%">Location</th>
            <th width="33%">Last Date of Apply</th>
        </tr>      
        <tbody>
        <?php  
        while($row=mysqli_fetch_array($result)){
            echo "<tr>";
            echo '<td><input type="text" name="name" value="'.$row['id'].'"></td>';
            echo '<td> <input width="10px" id="view" type="submit" name="submit" value="Apply"></td>';
            echo "<td>".$row['created_at']."</td>";
            echo "<td>".$row['heading']."</td>";
            echo "<td>".$row['education']."</td>";
            echo "<td>".$row['salary_max']."</td>";
            echo "<td>".$row['location']."</td>";
            echo "<td>".$row['last_date']."</td>";
            echo "</tr>";
        }
        ?>
        </tbody>
    </form>
  1. process.php

    <?php 
    session_start();
    if (isset($_POST['name'])){
        $name = $_POST['name'];
        echo $name;
        //echo("Selected Radio Button is".$button);
    }
    ?>
    
  • 写回答

1条回答 默认 最新

  • douxiuyu2028 2018-10-09 10:07
    关注

    You are using the same name for the multiple elements. That is the reason the value is overriding.

    For eg., Consider the name of the element as the index of the array. If you assign different values to the same index in the array, the values will be overridden.

    The same is the case with form elements. So instead of

    echo '<td><input type="text" name="name" value="'.$row['id'].'"></td>';

    Try this,

    echo '<td><input type="text" name="name[]" value="'.$row['id'].'"></td>';

    Make Sure to change the Form tag from

    <form action='process.php' method='post'>

    to

    <form action='process.php' method='post' enctype="multipart/form-data">

    This makes the name field unique and you'll receive the desired values in the other page.

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算