我使用以下HTML表单:
<form name="request" action="include/process_ns_request.php" onsubmit="return ValidateNewSupplierRequest()" method="POST">
<input type="text" id="comp_name" placeholder="Company Name" class="login_form2"/>
<select class="login_form2_select" id="comp_type">
<option value="" disabled selected>Select Company Type</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type="text" id="comp_reg" placeholder="Company Reg. Number" class="login_form2" />
<select class="login_form2_select" disabled id="address">
<option value="" disabled selected>Select Address Line</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type="text" id="vat_numb" placeholder="Company VAT Number" class="login_form2" />
<input type="text" id="postcode" placeholder="Postcode" class="login_form2" />
<input type="text" id="cont_name" placeholder="Contact Name" class="login_form2" />
<input type="text" id="cont_email" placeholder="Contact Email" class="login_form2" />
<input type="text" id="cont_tel" placeholder="Contact Tel. Number" class="login_form2" />
<input type="text" id="conf_email" placeholder="Confirm Contact Email" class="login_form2" />
<input type="text" id="cont_mob" placeholder="Mobile Number (Optional)" class="login_form2" />
<input type="text" id="promo" placeholder="Promotional Code" class="login_form2" />
<input type="submit" value="Submit">
</form>
然后我将表单数据发布到我的mysql查询页面:process_ns_request.php
<?php
session_start();
include("config.php");
if (isset($_POST['request'])) {
// do stuff
//retrieve our data from POST
$comp_name = $_POST['comp_name'];
$comp_reg = $_POST['comp_reg'];
$comp_type = $_POST['comp_type'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$vat_numb = $_POST['vat_numb'];
$cont_name = $_POST['cont_name'];
$cont_email = $_POST['cont_email'];
$conf_email = $_POST['conf_email'];
$cont_tel = $_POST['cont_tel'];
$cont_mob = $_POST['cont_mob'];
$comp_name = stripslashes($comp_name);
$comp_name = mysql_real_escape_string($comp_name);
$comp_reg = stripslashes($comp_reg);
$comp_reg = mysql_real_escape_string($comp_reg);
$comp_type = stripslashes($comp_type);
$comp_type = mysql_real_escape_string($comp_type);
$address = stripslashes($address);
$address = mysql_real_escape_string($address);
$postcode = stripslashes($postcode);
$postcode = mysql_real_escape_string($postcode);
$vat_numb = stripslashes($vat_numb);
$vat_numb = mysql_real_escape_string($vat_numb);
$cont_name = stripslashes($cont_name);
$cont_name = mysql_real_escape_string($cont_name);
$cont_email = stripslashes($cont_email);
$cont_email = mysql_real_escape_string($cont_email);
$conf_email = stripslashes($conf_email);
$conf_email = mysql_real_escape_string($conf_email);
$cont_tel = stripslashes($cont_tel);
$cont_tel = mysql_real_escape_string($cont_tel);
$cont_mob = stripslashes($cont_mob);
$cont_mob = mysql_real_escape_string($cont_mob);
}else{
echo 'form was not submitted';
}
$query = "INSERT INTO new_supplier_request (id, reference, user_id, date, status, payment_term) VALUES ('', '123','2', now(), 'Pending', '$comp_name')";
echo 'ok';
?>
但是,我得到了所有变量的索引未定义错误。有谁能告诉我我做错了什么?提前致谢
答案 0 :(得分:1)
以及php如何获取没有name属性的发布值:
<input type="text" name="comp_name" id="comp_name" placeholder="Company Name" class="login_form2"/>
为所有输入添加名称