Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何确定在PHP表单中单击了哪个动态生成的提交按钮?_Php_Mysql_While Loop_Submit Button - Fatal编程技术网

如何确定在PHP表单中单击了哪个动态生成的提交按钮?

如何确定在PHP表单中单击了哪个动态生成的提交按钮?,php,mysql,while-loop,submit-button,Php,Mysql,While Loop,Submit Button,我想编辑一个动态生成的表单,意思是:我不知道将生成多少行。该内容是在while循环中生成的,生成的HTML创建了input type=submit的按钮,生成的按钮与循环中的迭代次数相同 在生成的按钮中,我想知道单击了哪个submit按钮,以便为用户提供与单击该按钮相同的表单。忽略数据库的名称和连接数据库的密码;连接良好 请随意建议任何新方法以实现所需的功能 代码如下: echo "you have reached your travel details page. your recen

我想编辑一个动态生成的表单,意思是:我不知道将生成多少行。该内容是在while循环中生成的,生成的HTML创建了input type=submit的按钮,生成的按钮与循环中的迭代次数相同

在生成的按钮中,我想知道单击了哪个submit按钮,以便为用户提供与单击该按钮相同的表单。忽略数据库的名称和连接数据库的密码;连接良好

请随意建议任何新方法以实现所需的功能

代码如下:

    echo "you have reached your travel details page. your recent travelling details are as follows".'</br>';
$dbc=mysqli_connect('localhost','xyz','xyz','abc') or die("connection to DB failed");
$query="SELECT * FROM travel_details WHERE emailid='{$_SESSION['username']}' ORDER BY dep_date DESC";
$result=mysqli_query($dbc,$query) or die("error in querying the DB");
?>
<h1>Your travel details are:-</h1>
<form name="showtraveldet" METHOD="POST" action="edittraveldet.php">
    <table border="1">
    <tr>
    <th>Starting point</th><th>Ending point</th><th>No of passengers</th><th>Expected fare</th><th>Departure date</th>
    <th>Departure time</th><th>Arrival Date</th><th>Arrival Time</th><th>Car Model</th><th>Car number</th>
    <th>Who is driving</th><th>Driver's license number</th>
    </tr>
<?php
while ($row=mysqli_fetch_array($result)) 
{
    $tid=$row['travel_id'];
    echo "the value of tid is '{$tid}'";
    echo'<tr><td>'.$row['start_point'].'</td><td>'.$row['end_point'].'</td><td>'.$row['no_of_pass'].'</td><td>'.
    $row['exp_fare'].'</td><td>'.$row['dep_date'].'</td><td>'.$row['dep_time'].'</td><td>'.$row['arr_date'].'</td><td>'.$row['arr_time'].'
    </td><td>'.$row['car_model'].'</td><td>'.$row['car_no'].'</td><td>'.$row['who_is_driving'].'</td><td>'.$row['driver_license_no'].'</td>
    <td><input type="submit" name="edit" value="Edit"></td></tr><input type="hidden" name="travelid" value="'.$row['travel_id'].' ;?>">';

}
edittraveldet.php:-

    $travelid=$_POST['travelid'];
echo "the travel id in the variable is $travelid and got the value from '{$_POST['travelid']}'";
$dbc=mysqli_connect('localhost','xyz','xyz','abc') or die("connection to DB failed");
$query="SELECT * FROM travel_details WHERE travel_id='{$travelid}'";
$result=mysqli_query($dbc,$query) or die("error in querying the DB");
mysqli_close($dbc);
$row=mysqli_fetch_array($result);
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validatewheregoing()" name="wheregoing">
        <h1> Enter your travelling details so that other travellers can join you</h1>
        <fieldset>
            <legend> Travelling details </legend>
            Start Point: <input type="text" name="start" value="<?php echo $row['start_point']; ?>"/><br />
            End point: <input type="text" name="end" value="<?php echo $row['end_point']; ?>"/><br />
            Passengers allowed: <input type="number" name="noofpass" value="<?php echo $row['no_of_pass']; ?>"/><br />
            Expected Fare per passengers in rupees:<input type="number" name="fare" value="<?php echo $row['exp_fare']; ?>"/><br />
            Departure Date:<input type="date" name="depdate" value="<?php echo $row['dep_date']; ?>"/><br/>
            Departure time:<input type="time" name="deptime" value="<?php echo $row['dep_time'] ;?>"/><br/>
            Arrival Date:<input type="date" name="arrdate" value="<?php echo $row['arr_date']; ?>"/><br/>
            Arrival time at destination:<input type="time" name="arrtime" value="<?php echo $row['arr_time']; ?>"/><br/>
            Car Model and name:<input type="text" name="cardet" value="<?php echo $row['car_det']; ?>"/><br/> <!--make this as a dropdown box for better database matching-->
            Car Number:<input type="text" name="carno" /><br/><input type="checkbox" name="taxi" value="check this box if pooling a taxi">
            Is the car self driven or driven by driver?<input type="radio" name="drivedet" value="Selfdriven" checked=""/>Self Driven<input type="radio" name="drivedet" value="driverdriven" />Driver driven<br />
            Driver's License number<input type="text" name="licence_no"/></br>
            <input type="checkbox" name="taxi" value="check this box if pooling a taxi"></br>
            <input type="hidden" name="travelid" value="<?php echo $travelid ;?>" />
            <input type="submit" value="invite travellers" name="editwheregoing"/>
        </fieldset>
     </form>

以标准方式命名提交按钮,并在末尾附加一个3位数的数字,按钮_XXXX u其中是数字,XXX是按钮的原始名称

提交后,检查以name button_XXXX开头的所有变量的请求参数,并将实际的name button_XXXX_uu分割为“uu”字符,后缀将显示按下的按钮的编号


但是,为每一行创建一个表单可能更容易。

如果您可以更改代码,我建议您将表单标记本身放入while循环,每个表单标记都有相同的操作指向相同的url,但向目标页面提交不同的信息。这样你就不用担心按钮被点击了

while($row=mysqli_fetch_array($result))
{
    //<form action="sameactionurl.php" name="form_1">
       //<input type="hidden" name="travelid" value="$row['travelid']" />
    //</form>
}
如果不想更改代码,另一种解决方案是在提交表单之前使用JavaScript将公共隐藏字段设置为当前ID的值