Unidentified syntax error

Asked

Viewed 26 times

0

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

Parse error: syntax error, Unexpected ';' in "code path" online 24

But honestly, I can’t identify the mistake:

<?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();
}
?>
  • $output.=" <p>Added Successfully" . $serial[$key]. ; try to take this point, which is before the ;

  • and you’re wearing 2 elses

1 answer

0

Syntax errors

First

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

A concatenation point before the dot and comma without a string to concatenate.

According to

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-fold

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 one more condition use Else if, 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";
}
?>

Source

Browser other questions tagged

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