Unidentified syntax error

0

Good afternoon. I am trying to program in php (I am newbie), and I created a connection with the bank, but when I try to register a data in my bank through my system, it presents the following error:

  

Parse error: syntax error, unexpected ';' in "code path" on line 24

But honestly, I can not identify the error:

<?php

$input_quantidade_venda = $_POST['input_quantidade_venda'];

foreach ($input_quantidade_venda as $key => $value) {

    $query = "SELECT id_venda FROM vendas WHERE serial = '".mysqli_real_escape_string($serial[$key])."'LIMIT 1";

    $resultSet = $mysqli->query($query);

    if ($resultSet->num_rows == 0) {

        $query = "INSERT INTO vendas(desconto) VALUES('".mysqli_real_escape_string($value)."')";

        $insert = $mysqli->query($query);

        if (!$insert) {

            echo $mysqli->error; //Linha 24 <-
        } else {

            $output.="<p>Adicionado com Sucesso" .$serial[$key].;
        } else {

            $output.="<p>Esse dado já existe" .$mysqli->error;
        }
    }

    $mysqli->close();
}
?>
    
asked by anonymous 10.12.2018 / 15:29

1 answer

0

Syntax errors

First

$output.="<p>Adicionado com Sucesso" .$serial[$key].;
  

A concatenation point before the semicolon without a string to concatenate.

Second

if (!$insert) {
    echo $mysqli->error; //Linha 24 <-
} else {
    $output.="<p>Adicionado com Sucesso" .$serial[$key].;
} else {
    $output.="<p>Esse dado já existe" .$mysqli->error;
}
  

Two elses

Code without syntax errors

<?php
$input_quantidade_venda = $_POST['input_quantidade_venda'];
foreach ($input_quantidade_venda as $key => $value) {
    $query     = "SELECT id_venda FROM vendas WHERE serial = '" . mysqli_real_escape_string($serial[$key]) . "'LIMIT 1";
    $resultSet = $mysqli->query($query);
    if ($resultSet->num_rows == 0) {
        $query  = "INSERT INTO vendas(desconto) VALUES('" . mysqli_real_escape_string($value) . "')";
        $insert = $mysqli->query($query);
        if (!$insert) {
            echo $mysqli->error; //Linha 24 <-
        } else {
            $output .= "<p>Adicionado com Sucesso" . $serial[$key];
        }
    }
    $mysqli->close();
}
?>
  

I removed an else, the conditional structure if only accepts an else, if I wanted to add another condition, use else if, for example:

<?php
if ($a > $b) {
    echo "a is bigger than b";
} elseif ($a == $b) {
    echo "a is equal to b";
} else {
    echo "a is smaller than b";
}
?>

Font

    
10.12.2018 / 15:40