gpt4 book ai didi

javascript - 输入类型文本数据未插入 SQL DB 中

转载 作者:行者123 更新时间:2023-11-29 17:51:14 25 4
gpt4 key购买 nike

我正在尝试制作一个表单并将这些值插入到我的数据库中。我在这里尝试做的是,将下拉菜单的值获取到其上方的禁用文本字段中,并将这些值插入到我的数据库中。问题是:任何下拉/禁用文本字段的值都没有插入到我的数据库中,它们只是空白。我希望将它们插入。

下面是我的 HTML 代码。

<html>
<head>
<title>Trademark Filing Application</title>

<link rel="icon" href="\images\trademark_icon.png" type="image/gif" sizes="16x16">

<link rel="stylesheet" type="text/css" href="mystyle.css">


</head>
<body>


<h2 ><img src="images/hero_logo.png" class="herologo" ><span class="form-title">Trademark Filing Application</span></h2><br>

<div>
<p style="padding-left:20px"><span class="error">* required field.</span></p>

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

<!-- Department -->

<b>Select Department:</b><span class="error"> *</span>
<select id="dept" name="department" required>
<option value="">Please Select...</option>
<option value="CEO Office">CEO Office</option>
<option value="Global">Global</option>
<option value="Marketing">Marketing</option>
<option value="Parts">Parts</option>

</select>
<br><br><br>


<!-- Class -->

<b>Select Class:</b><span class="error"> *</span><br><br>
<input type="radio" id="wordradio" name="classs" value="Word" required>Word
<input type="radio" id="deviceradio" name="classs" value="Device" style="margin-left:20px">Device
<input type="radio" id="logoradio" name="classs" value="Logo" style="margin-left:20px">Logo
<input type="radio" id="soundradio" name="classs" value="Sound" style="margin-left:20px">Sound
<input type="radio" id="taglineradio" name="classs" value="Tagline" style="margin-left:20px">Tagline
<br><br><br>


<!-- Preferences -->


<b>Enter Preference(s):</b><br>
1. <input type="text" id="pref1" name="preference1" style="width:30%" placeholder="Preference 1" required>
<input type="file" id="prefbtn1" name="image" multiple="" required>
<span class="error">*</span>
<br>

2. <input type="text" id="pref2" name="preference2" style="width:30%" placeholder="Preference 2">
<input type="file" id="prefbtn2" name="preferTwo[]" multiple="" >

<br>
3. <input type="text" id="pref3" name="preference3" style="width:30%" placeholder="Preference 3">
<input type="file" id="prefbtn3" name="preferThree[]" multiple="" >

<br>
4. <input type="text" id="pref4" name="preference4" style="width:30%" placeholder="Preference 4">
<input type="file" id="prefbtn4" name="preferFour[]" multiple="" >

<br>
5. <input type="text" id="pref5" name="preference5" style="width:30%" placeholder="Preference 5">
<input type="file" id="prefbtn5" name="preferFive[]" multiple="" >

<br><br><br>


<!-- Goods and Services -->


<b>Enter The Types of Goods & Services :</b><span class="error"> *</span>
<br>
<input type="text" id="goodss" name="goodsnservice" placeholder="Select the type of Goods and Services" required>

<br><br><br>


<!-- Mark in Use? -->

<b>Is Mark In Use?</b><span class="error"> *</span><br><br>
<input type="radio" id="marky" name="mark" value="yes" onclick="disableNo()" required>Yes


<!-- Mark in Use?: YES -->


<div id="markyes" class="show-hide" style="background-color:white;width:600px ;margin-left:40px; border:1px solid black; border-radius:5px"><br>
<b>When Did You Use It?</b>
<input type="date" name="yeswhen" style="margin-left:10px" id="markyesdate" required><span class="error"> *</span><br><br>

<b>Where Did You Use It?</b><span class="error"> *</span><br>

<input type="text" style="height:10px;width:50%" id="selected_yes" name="yes_country_values" disabled /> <br/>
<select name="yescountry" id="yescountry" style="width:40%" multiple required>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Yemen">Yemen</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select><br><br>

<b>Proof Of First Use:</b><span class="error"> *</span><br>
<input type="file" id="markyesproof" name="yesProof[]" value="Upload proof" multiple="" required>
</div><br>


<!-- Mark in Use?: NO -->


<input type="radio" name="mark" value="no" onclick="disableYes()" >No<br>
<div id="markno" class="show-hide" style="background-color:white;width:600px ;margin-left:40px; border:1px solid black; border-radius:5px"><br>
<b>When Are You Expected To Use It?</b>
<input type="date" name="nowhen" style="margin-left:10px" id="marknodate" required><span class="error"> *</span><br><br>

<b>Where will You Use It?</b><span class="error"> *</span><br>

<input type="text" style="height:10px;width:50%" id="selected_no" name="no_country_values" disabled /><br/>

<select name="marknocountry" id="nocountry" style="width:40%" multiple required>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select><br/><br/>


<input type="submit" value="Submit">
</form>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {
$('#yescountry').on('change', function() {
$('#selected_yes').val($(this).val());
});

$('#nocountry').on('change', function() {
$('#selected_no').val($(this).val());
});

$('#appliedcountry').on('change', function() {
$('#selected_applied').val($(this).val());
});

});
</script>

<script>
function disableNo() {
document.getElementById("nocountry").required = false;
document.getElementById("marknodate").required = false;
}

function disableYes() {
document.getElementById("yescountry").required = false;
document.getElementById("markyesdate").required = false;
document.getElementById("markyesproof").required = false;
}
</script>

</body>
</html>

下面是我的 PHP 代码:

    <?php

include'upload.php';
$con = mysqli_connect('localhost','root','abcdef','trademark');

if(!$con) {
echo "Not Connected To Server";
} else {

$_POST = array_map(function($value) {
return empty($value) ? "NULL" : $value;
}, $_POST);

$Department = !empty($_POST['department']) ? $_POST['department'] : "";
$Classs = !empty($_POST['classs']) ? $_POST['classs'] : "";
$Preference1 = !empty($_POST['preference1']) ? $_POST['preference1'] : "";
$Preference2 = !empty($_POST['preference2']) ? $_POST['preference2'] : "";
$Preference3 = !empty($_POST['preference3']) ? $_POST['preference3'] : "";
$Preference4 = !empty($_POST['preference4']) ? $_POST['preference4'] : "";
$Preference5 = !empty($_POST['preference5']) ? $_POST['preference5'] : "";
$Goods = !empty($_POST['goodsnservice']) ? $_POST['goodsnservice'] : "";
$Mark = !empty($_POST['mark']) ? $_POST['mark'] : "";
$MarkYesWhen = !empty($_POST['yeswhen']) ? $_POST['yeswhen'] : "";
$MarkYesCountry = !empty($_POST['yes_country_values']) ? $_POST['yes_country_values'] : "";
$MarkNoWhen = !empty($_POST['nowhen']) ? $_POST['nowhen'] : "";
$MarkNoCountry = !empty($_POST['no_country_values']) ? $_POST['no_country_values'] : "";
$MarkAppliedCountry = !empty($_POST['applied_selected_values']) ? $_POST['applied_selected_values'] : "";

$sql = "INSERT INTO requestor (
Department,
Class,
Preference_One,
Preference_Two,
Preference_Three,
Preference_Four,
Preference_Five,
Goods_Services,
Mark_In_Use,
Mark_Yes_When,
Mark_Yes_Country,
Mark_No_When,
Mark_No_Country,
Mark_Applied_Country,
Flag
) VALUES(
'$Department',
'$Classs',
'$Preference1',
'$Preference2',
'$Preference3',
'$Preference4',
'$Preference5',
'$Goods',
'$Mark',
'$MarkYesWhen',
'$MarkYesCountry',
'$MarkNoWhen',
'$MarkNoCountry',
'$MarkAppliedCountry',
0
)";

$r = mysqli_query($con,$sql);

header("refresh:0 ; url=success.php");

}



?>​

最佳答案

您无法在 Post 请求中获取禁用字段值。您可以使用隐藏来代替禁用。

在你的 html 中更改它,它应该可以工作。

关于javascript - 输入类型文本数据未插入 SQL DB 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49317018/

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