Error "Parse error: syntax error, Unexpected '('"

Asked

Viewed 84 times

0

The system generates a sequence of random numbers and depending on the combination of these numbers the sequence will be inserted in one of the two tables the table of bad sequences and the table of good sequences I made this script but it is missing some detail because it is giving the error

Parse error: syntax error, Unexpected '(' in C: xampp htdocs teste.php on line 24

<?php
set_time_limit(10000);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = mysqli_connect('localhost', 'root', '');
// Check connection
if (!$conn) {die("Connection failed: " . mysqli_connect_error());}
mysql_select_db("test");

for ($x = 0; $x <= 1000000; $x++) {
$D1  = (mt_rand(1,3));$D2  = (mt_rand(1,3));$D3  = (mt_rand(1,3));
$D4  = (mt_rand(1,3));$D5  = (mt_rand(1,3));$D6  = (mt_rand(1,3));
$D7  = (mt_rand(1,3));$D8  = (mt_rand(1,3));$D9  = (mt_rand(1,3));
$D10 = (mt_rand(1,3));$D11 = (mt_rand(1,3));$D12 = (mt_rand(1,3));
$D13 = (mt_rand(1,3));$D14 = (mt_rand(1,3));$D15 = (mt_rand(1,3));   

if(
( $D1==$D7 && $D7==$D8 && $D8==$D9 && $D9==$D5 ) || ( $D11==$D7 && $D7==$D8 && $D8==$D9 && $D9==$D15 ) || ( $D6==$D2 && $D2==$D3 && $D3==$D4 && $D4==$D10 ) || ( $D6==$D12 && $D12==$D13 && $D13==$D14 && $D14==$D10 ) || ( $D6==$D7 && $D7==$D8 && $D8==$D4 && $D4==$D5 ) || ( $D10==$D9 && $D9==$D8 && $D8==$D2 && $D2==$D1 ) || ( $D11==$D12 && $D12==$D13 && $D13==$D9 && $D9==$D10 ) || 
( $D15==$D14 && $D14==$D13 && $D13==$D7 && $D7==$D6 ) || ( $D1==$D2 && $D2==$D3 && $D3==$D9 && $D9==$D10 ) || ( $D5==$D4 && $D4==$D3 && $D3==$D7 && $D7==$D6 ) || ( $D1==$D7 && $D7==$D13 && $D13==$D9 && $D9==$D5 ) || ( $D11==$D7 && $D7==$D3 && $D3==$D9 && $D9==$D15 ) || ( $D1==$D7 && $D7==$D3 && $D3==$D9 && $D9==$D5 ) || ( $D11==$D7 && $D7==$D13 && $D13==$D9 && $D9==$D10 ) || ( $D6==$D2 && $D2==$D8 && $D8==$D4 && $D4==$D10 )
( $D6==$D12 && $D12==$D8 && $D8==$D14 && $D14==$D10 ) || ( $D1==$D2 && $D2==$D3 && $D3==$D4 && $D4==$D5 ) || ( $D6==$D7 && $D7==$D8 && $D8==$D9 && $D9==$D10 ) || ( $D11==$D12 && $D12==$D13 && $D13==$D14 && $D14==$D15 )
)
{
$query = "INSERT INTO candypot_best (D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15) VALUES ('$D1','$D2','$D3','$D4','$D5','$D6','$D7','$D8','$D9','$D10','$D11','$D12','$D13','$D14','$D15')";
$result=mysql_query($query) or die(mysql_error());

}
else
{
$query = "INSERT INTO candypot_lose (D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15) VALUES ('$D1','$D2','$D3','$D4','$D5','$D6','$D7','$D8','$D9','$D10','$D11','$D12','$D13','$D14','$D15')";
$result=mysql_query($query) or die(mysql_error());

}


 //   echo "The number is:   $D1 ,  $D2 , $D3 ,  $D4 ,  $D5 , $D1 ,  $D6 , $D7 ,  $D8 , $D9 , $D10 , $D11 , $D12 , $D13 , $D14 , $D15<br>";
} 



//if (mysqli_multi_query($conn, $result)) {
//    echo "New records created successfully";
//} else {
//    echo "Error: " . $result . "<br>" . mysqli_error($conn);}
//
//mysqli_close($conn);



?>
  • 1

    Good afternoon, I recommend making intuitive titles. Related: http://answall.com/q/51002/3635

1 answer

2

By the syntax error returned on line 24, a comparison is missing || in your condition:

Excerpt from his condition

( $D6==$D2 && $D2==$D8 && $D8==$D4 && $D4==$D10 )
( $D6==$D12 && $D12==$D8 && $D8==$D14 && $D14==$D10 )

Answer

( $D6==$D2 && $D2==$D8 && $D8==$D4 && $D4==$D10 ) ||
( $D6==$D12 && $D12==$D8 && $D8==$D14 && $D14==$D10 )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.