-1

enter image description hereerror: Parse error: syntax error, unexpected '===' (T_IS_IDENTICAL) in C:\xampp\htdocs\new\add.php on line 7

Code:

<?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>";
?>
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
Karl Danao
  • 1
  • 1
  • 2

1 Answers1

0

You can't string comparison operators together like that in PHP.

Instead try something like suggested here https://stackoverflow.com/a/6920551/635522

EDIT: Adapted to take into account that we're looking to compare array counts here.

$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
}
Bananaapple
  • 2,984
  • 2
  • 25
  • 38
  • By stringing together a huge number of comparison operators, things get confusing, not just for you, but for PHP as well; It might be best to call a function to check to see if your entry variables are fine. Something along the lines of: `if(variablesOkay())` That way, you can perform all these checks in an orderly fashion out of the way. The above code from Bananaapple will certainly help you! – Will Aug 30 '17 at 07:58
  • I very much doubt that the OP wants to check if all variables are the same. The code suggests that `$_POST['name']`, etc. are arrays that have to have the same *length*. You could solve that using `count()` on each POST variable when you assign the array. – jeroen Aug 30 '17 at 07:58
  • That does something very different than what OP is trying to do. And you *can* string comparisons together like that, it just might not do what you expect it to. – deceze Aug 30 '17 at 08:02
  • @Will If it's not a syntax error, PHP won't ever be "confused". It just might do something other than what you wanted it to. – deceze Aug 30 '17 at 08:04
  • Good point jeroen and @deceze - have edited my answer accordingly – Bananaapple Aug 30 '17 at 08:20