gpt4 book ai didi

php - 使用 PHP 表单将值放入 M​​ySQL 表中

转载 作者:行者123 更新时间:2023-12-01 00:31:58 25 4
gpt4 key购买 nike

我正在使用 PHP 表单将值放入我的表中。一切正常,除了问题是下拉列表中的文本不是下拉列表中的文本,而是下拉选择的值。

此外,当我尝试连接我的日期和时间时,它以某种方式生成了另一个 MySQL 行并将斜杠和冒号放在该行中。

有什么解决办法吗?

(我没有制作表格,我使用了表格制作器)

代码如下:

    <div id="form_container">                   
<ul >

<li id="li_4" >
<label class="description" for="element_4">restaurant </label>
<div>
<select class="element select medium" id="element_4" name="element_4">
<option value="" selected="selected"></option>
<option value="1" >Burger King</option>
<option value="2" >McDonald's</option>
<option value="3" >Wendy's</option>
<option value="4" >KFC</option>
<option value="5" >Taco Bell</option>
<option value="6" >Domino's Pizza</option>
<option value="7" >Pizza Hut</option>
<option value="8" >Quizno's</option>
<option value="9" >Chili's</option>
<option value="10" >TGI Friday's</option>
<option value="11" >Starbucks</option>
<option value="12" >Red Lobster</option>
<option value="13" >Olive Garden</option>

</select>
</div>
</li> <li id="li_1" >
<label class="description" for="element_1">date </label>
<span>
<input id="element_1_1" name="element_1_1" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="element_1_1">MM</label>
</span>
<span>
<input id="element_1_2" name="element_1_2" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="element_1_2">DD</label>
</span>
<span>
<input id="element_1_3" name="element_1_3" class="element text" size="4" maxlength="4" value="" type="text">
<label for="element_1_3">YYYY</label>
</span>

<span id="calendar_1">
<img id="cal_img_1" class="datepicker" src="calendar.gif" alt="Pick a date.">
</span>
<script type="text/javascript">
Calendar.setup({
inputField : "element_1_3",
baseField : "element_1",
displayArea : "calendar_1",
button : "cal_img_1",
ifFormat : "%B %e, %Y",
onSelect : selectDate
});
</script>

</li> <li id="li_2" >
<label class="description" for="element_2">time </label>
<span>
<input id="element_2_1" name="element_2_1" class="element text " size="2" type="text" maxlength="2" value=""/> :
<label>HH</label>
</span>
<span>
<input id="element_2_2" name="element_2_2" class="element text " size="2" type="text" maxlength="2" value=""/> :
<label>MM</label>
</span>
<span>
<input id="element_2_3" name="element_2_3" class="element text " size="2" type="text" maxlength="2" value=""/>
<label>SS</label>
</span>
<span>
<select class="element select" style="width:4em" id="element_2_4" name="element_2_4">
<option value="AM" >AM</option>
<option value="PM" >PM</option>
</select>
<label>AM/PM</label>
</span>
</li> <li id="li_3" >
<label class="description" for="element_3">catering </label>
<span>
<input id="element_3_1" name="element_3" class="element radio" type="radio" value="1" />
<label class="choice" for="element_3_1">Yes</label>
<input id="element_3_2" name="element_3" class="element radio" type="radio" value="2" />
<label class="choice" for="element_3_2">No</label>

</span>
</li> <li id="li_5" >
<label class="description" for="element_5">driver </label>
<div>
<select class="element select medium" id="element_5" name="element_5">
<option value="" selected="selected"></option>
<option value="1" >Derek</option>
<option value="2" >Joe</option>

</select>
</div>
</li> <li id="li_6" >
<label class="description" for="element_6">destination </label>
<div>
<select class="element select medium" id="element_6" name="element_6">
<option value="" selected="selected"></option>
<option value="1" >NYC</option>
<option value="2" >LA</option>
<option value="3" >Chicago</option>
<option value="4" >Boston</option>
<option value="5" >Miami</option>
<option value="6" >San Francisco</option>
<option value="7" >Seattle</option>
<option value="8" >Other</option>

</select>
</div>
</li>

<li class="buttons">
<input type="hidden" name="form_id" value="76657" />

<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>

PHP代码

<?php
$restaurant = $_POST['element_4'];
$dateM = $_POST['element_1_1'];
$dateD = $_POST['element_1_2'];
$dateY = $_POST['element_1_3'];
$timeH = $_POST['element_2_1'];
$timeM = $_POST['element_2_2'];
$timeS = $_POST['element_2_3'];
$amPM = $_POST['element_2_4'];
$catering = $_POST['element_3'];
$driver = $_POST['element_5'];
$destination = $_POST['element_6'];

$date = $dateM . "/" . $dateD . "/" . $dateY;
$time = $timeH . ":" . $timeM . ":" . $timeS . " " . $amPM;



$con = mysql_connect("localhost","asdf","asdf");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("tableName", $con);

mysql_query("INSERT INTO stats (restaurant, date, time, catering, driver, destination)
VALUES ('$restaurant', '$date', '$time', '$catering', '$driver', '$destination')");

mysql_close($con);
?>

最佳答案

只需设置与文本匹配的值,示例:

<option value="Burger King">Burger King</option>
<option value="McDonald's">McDonald's</option>

关于php - 使用 PHP 表单将值放入 M​​ySQL 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4552162/

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