嘿我需要帮助解决这个错误我有 **注意:未定义的变量:第16行的C:\ xampp \ htdocs \ ZoomiezWebApp \ addNewCustomer.php中的反馈** 。 我正在尝试创建一个表单来添加新客户。
这是代码
<?php
#1> Retrieve Form Details
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$address= $_POST['address'];
$cNumber= $_POST['contactNumber'];
#2 SANITIZE AND VALIDATE DATA
$fname = filter_var($fname, FILTER_SANITIZE_STRING);
$lname = filter_var($lname, FILTER_SANITIZE_STRING);
$address = filter_var($address, FILTER_SANITIZE_STRING);
$cNumber = filter_var($cNumber, FILTER_SANITIZE_STRING);
if($fname==""){//Validate fields for null or empty
***ERROR IS IN THIS LINE***$feedback .= "<br>First Name Field Empty.";
}if($lname==""){
$feedback .= "<br>Last Name Field Empty.";
}if($address==""){
$feedback .= "<br>Address Field Empty.";
}if($cNumber==""){
$feedback .= "<br>Contact Number Field Empty.";
}else{ //Validation Passed...
// #3> CONNECT MYSQL ON THE DB SERVER /
$con = mysql_connect('localhost', "root", "test")
or die ('Could not connect to the database');
// #4> SELECT THE DATABASE ON THE SERVER /
$con = mysql_select_db('zoomiezdb', $con)
or die ('Could not locate database');
// #5> CREATE INSERT QUERY
$addCustomerQuery =
"INSERT INTO customertable (First Name, Last Name, Address, Contact Number) VALUES ('$fname', '$lname', '$address', '$cNumber')) ";
// #6> EXECUTE QUERY
$queryResult = mysql_query($addCustomerQuery);
// #7> VERIFY IF QUERY IS SUCCESSFUL
if($queryResult)
$feedback = "New Customer Added";
else
$feedback = "<i>Add New Customer was Unsuccessful.</i>
<br>
Please Contact Site Administrator...";
// #8> REDIRECT
Header("Location:newCustomer.php?feedbackMsg=$feedback");
}
&GT?;
答案 0 :(得分:0)
如果没有错误,你应该在条件之前初始化那个变量$ feedback永远不会初始化,在这种情况下你可以用&#39;&#39;来初始化它。因为当你连接它时,PHP没有任何东西可以连接