enter image description here错误:解析错误:语法错误,意外' ==='第7行的C:\ xampp \ htdocs \ new \ add.php中的(T_IS_IDENTICAL)
代码:
<?php
require_once('db.php');
if (
!empty($_POST['name']) &&!empty($_POST['alias']) &&!empty($_POST['date']) &&!empty($_POST['address']) &&!empty($_POST['educational']) &&!empty($_POST['father']) &&!empty($_POST['mother']) &&!empty($_POST['brother']) &&!empty($_POST['sister']) &&!empty($_POST['spouse']) &&!empty($_POST['children']) &&!empty($_POST['training']) &&!empty($_POST['employment']) &&!empty($_POST['organization']) &&!empty($_POST['affiliation']) &&!empty($_POST['criminal']) &&!empty($_POST['activities']) &&
is_array($_POST['name']) && is_array($_POST['alias']) && is_array($_POST['date']) && is_array($_POST['address']) && is_array($_POST['educational']) && is_array($_POST['father']) && is_array($_POST['mother']) && is_array($_POST['brother']) && is_array($_POST['sister']) && is_array($_POST['spouse']) && is_array($_POST['children']) && is_array($_POST['training']) && is_array($_POST['employment']) && is_array($_POST['organization']) && is_array($_POST['affiliation']) && is_array($_POST['criminal']) && is_array($_POST['activities']) &&
count($_POST['name']) === count($_POST['alias']) === count($_POST['date']) === count($_POST['address']) === count($_POST['educational']) === count($_POST['father']) === count($_POST['mother']) === count($_POST['brother']) === count($_POST['sister']) === count($_POST['spouse']) === count($_POST['children']) === count($_POST['training']) === count($_POST['employment']) === count($_POST['organization']) === count($_POST['affiliation']) === count($_POST['criminal']) === count($_POST['activities'])
) {
$name_array = $_POST['name'];
$alias_array = $_POST['alias'];
$date_array = $_POST['date'];
$address_array = $_POST['address'];
$educational_array = $_POST['educational'];
$father_array = $_POST['father'];
$mother_array = $_POST['mother'];
$brother_array = $_POST['brother'];
$sister_array = $_POST['sister'];
$spouse_array = $_POST['spouse'];
$children_array = $_POST['children'];
$training_array = $_POST['training'];
$employment_array = $_POST['employment'];
$organization_array = $_POST['organization'];
$affiliation_array = $_POST['affiliation'];
$criminal_array = $_POST['criminal'];
$activities_array = $_POST['activities'];
for ($i = 0; $i < count($name_array); $i++) {
$name = mysql_real_escape_string($name_array[$i]);
$alias = mysql_real_escape_string($alias_array[$i]);
$date = mysql_real_escape_string($date_array[$i]);
$address = mysql_real_escape_string($address_array[$i]);
$educational = mysql_real_escape_string($educational_array[$i]);
$father = mysql_real_escape_string($father_array[$i]);
$mother = mysql_real_escape_string($mother_array[$i]);
$brother = mysql_real_escape_string($brother_array[$i]);
$sister = mysql_real_escape_string($sister_array[$i]);
$spouse = mysql_real_escape_string($spouse_array[$i]);
$children = mysql_real_escape_string($children_array[$i]);
$training = mysql_real_escape_string($training_array[$i]);
$employment = mysql_real_escape_string($employment_array[$i]);
$organization = mysql_real_escape_string($organization_array[$i]);
$affiliation = mysql_real_escape_string($affiliation_array[$i]);
$criminal = mysql_real_escape_string($criminal_array[$i]);
$activities = mysql_real_escape_string($activities_array[$i]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
mysql_query("INSERT INTO student (name, alias, date, address, educational, father, mother, brother, sister, spouse, children, training, employment, organization, affiliation, criminal, activities)
VALUES ('$name', '$alias', '$date', '$address', '$educational', '$father', '$mother', '$brother', '$sister', '$spouse', '$children', '$training', '$employment', '$organization', '$affiliation', '$criminal', '$activities')");
}
}
$conn->exec($sql);
echo "<script>alert('Account successfully added!'); window.location='pis.php'</script>";
?>
答案 0 :(得分:0)
您不能像PHP中那样将比较运算符串起来。
而是尝试像https://stackoverflow.com/a/6920551/635522
中建议的内容编辑:改编自考虑我们在此处比较数组计数。
$arrays = [$_POST['name'],$_POST['alias'],$_POST['date'],$_POST['address'],...];
//create a second array with the lengths of all the arrays we want to compare
$lengths = [];
foreach($arrays as $array){
$lengths[] = count($array);
}
//check if all the lengths are the same
if(count(array_unique($lengths)) == 1){
// all match
}