username ?> -6ren">
gpt4 book ai didi

php - Sql和Php,插入sql选择选项

转载 作者:行者123 更新时间:2023-11-29 12:31:40 25 4
gpt4 key购买 nike

我在 php 中有一个表单,在此表单中有一个选择选项

<select id="birdname" style="width: 150px; height: 25px; border-radius: 5px;">
<option>--Cambiar vendedor --</option>
<?php
$selectagent = "SELECT * FROM `" . $prefix . "user`";
$resultforagents = mysql_query($selectagent);
while ($agent = mysql_fetch_object($resultforagents)) {
?>
<option value="<?= $agent->user_id ?>" ><?= $agent->username ?></option>
<?php } ?>
</select>
<div id="stage" style="display:none;"></div>

显示用户名的名称,我需要将选定的用户名(引用而不是名称)插入到sql中

<?php
$userId = $_POST['birdname'];
$idtill = $_SESSION['caj'];
$cashid = $_SESSION['cash'];
$mvalue = number_format($givenamount, 2, '.', '');
$mdate = date("Y-m-d H:i:s");
$moption = '1';
$sql = "INSERT INTO `" . DB_PREFIX . "order_user`(`user_id`, `order_Id`, `till`, `value`, `operation`, `comment`, `date`,`cashid`) VALUES ('" . $userId . "','" . $lastorderidis . "','" . $cashid . "','" . $mvalue . "','" . $moption . "', '" . " " . "', '" . $mdate . "','" . $cashid . "')";
$common->showresultsql($sql, 'update', 1);

echo $lastorderidis;
?>

谢谢

最佳答案

name 标签添加到您的 select 值中,以获取 select 的值,如下所示:

<select id="birdname" name="birdname">

现在您将获得 $_POST['birdname'] 的值

更多信息请点击:get the selected index value of <select> tag in php

关于php - Sql和Php,插入sql选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com