doxd96148 2014-06-16 12:42
浏览 42
已采纳

如何将值添加到从表单传递给脚本的URL

I have the an edit data form where the user selects the id of the record they want to edit in a selection box.

Then in the next php script I print the existing values and then allow the user to change the values. Once the form is submitted the form data is send using GET to my php script that will update the values for this record.

My problem is this, how do I include the id of the record to the rest of the values send by the form? I don't want to use cookies (if it is possible not to).

Here is my code:

The first form:

<?php
$myTitle = 'Interface to edit a license';
require 'header.php';
$licid = $_GET ['license_id'];
$sql = 'select * from all_license where id =' . $licid;
$result = mysqli_query ( $con, $sql );
$rowm = mysqli_fetch_array ( $result )?>

<br>
<center>
    <table>
        <tr>
            <td class="acentre">Select below what admin task you would like to do</td>
        </tr>
        <tr>
            <td><?php require 'admmenu.php' ?></td>
        </tr>
        <tr>
            <td class="acentre">Displaying the current values for license id: <?php echo $licid ?></td>
        </tr>
        <tr>
            <td><form name="license_edit" action="e2license.php" method="get">
            <center>
                    <table>
                        <tr>
                            <th>Field Name:</th>
                            <th>Existing Value:</th>
                            <th>New Value:</th>
                        </tr>
                        <tr>
                            <td>License ID:</td>
                            <td><?php echo $licid ?></td>
                            <td><input type="text" value="<?php echo $licid ?>" name="licid" disabled>
                        <tr>
                            <td>Product Name:</td>
                            <td><?php echo $rowm['prodname'] ?></td>
                            <td><?php require 'cmbprodname.php';?></td>
                        </tr>
                        <tr>
                            <td>Supplier Name:</td>
                            <td><?php echo $rowm['suppliername'] ?></td>
                            <td><?php require 'cmbsupplier.php';?></td>
                        </tr>
                        <tr>
                            <td>Lease Type:</td>
                            <td><?php echo $rowm['leasetype'] ?></td>
                            <td><?php require 'cmbleasetype.php'?></td>
                        </tr>
                        <tr>
                            <td>Expiry Date:</td>
                            <td><?php echo $rowm['expirydate'] ?></td>
                            <td><input type="text" id="datepicker" name="expirydate"></td>
                        </tr>
                        <tr>
                            <td>License Price:</td>
                            <td><?php echo toRand($rowm['licenseprice']) ?></td>
                            <td><input type="text" name="price"></td>
                        </tr>
                        <tr>
                            <td class="aright" colspan="3"><input type="submit"></td>
                        </tr>
                    </table>
                    </center>
                </form></td>
        </tr>
    </table>
</center>

<?php
require 'footer.php';
?>

Then the second one:

<?php
$licid = $_GET['licid'];
$product_id = $_GET['prodname'];
$supplier_id = $_GET['supplier'];
$leasetype_id = $_GET['leasetype'];
$expirydate = $_GET['expirydate'];
$price = $_GET['price'];

require 'conn.php';

$sql = 'update license set product_id =' . $product_id;
$sql = $sql . ', leasetype_id =' . $leasetype_id;
$sql = $sql . ', supplier_id=' . $supplier_id;
$sql = $sql . ', expirydate=' . $expirydate;
$sql = $sql . ', price=' . $price;
$sql = $sql . ' where id=' . $licid;


echo $sql;

//$result = mysqli_query ( $con, $sql );

//header("Location: http://localhost/license/admin.php");

?>

Now the code printed by the echo of the $sql is:

update license set product_id =4, leasetype_id =4, supplier_id=3, expirydate=2014-07-14, price=5000 where id=

Thus, the $licid does not seem to get transferred from the first php script to the second one (possibly because the input is set to disabled?. How can I achieve this?

  • 写回答

1条回答 默认 最新

  • doujiao1814 2014-06-16 12:50
    关注

    I'd simply use a hidden field within your form which has the id outputted.

    <input type="hidden" name="licid" id="licid" value="<?php echo $licid ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图