I’m having trouble with the last one

Asked

Viewed 49 times

0

        if(is_numeric($id) && $id >=1){
            $stmt = $obj_mysqli->prepare("UPDATE 'clientes' SET 'nome'=$nome, 'email'=$email, 'cidade'=$cidade, 'uf'=$uf WHERE id= $id");
            $stmt->bind_param('ssssi', $nome, $email, $cidade, $uf, $id);

            if(!$stmt->execute()){
                $erro = $stmt->error;
            }
            else{
                header("Location:cadastro.php");
                exit;
            }
            /*retorna o erro<!--O PROBLEMA ESTÁ AQUI PRA BAIXO-->
            else{
                $erro = "Número Inválido";
            }*/
  • What’s the matter?

  • 2

    Only thing I see wrong is that the first if is not closing the keys before opening the second I.

2 answers

3

You cannot use 2 elses without conditions followed.

Either you place a condition (Else if()), or you close the if "father" with a "}" before the second Else:

   if(is_numeric($id) && $id >=1){
        $stmt = $obj_mysqli->prepare("UPDATE 'clientes' SET 'nome'=$nome, 'email'=$email, 'cidade'=$cidade, 'uf'=$uf WHERE id= $id");
        $stmt->bind_param('ssssi', $nome, $email, $cidade, $uf, $id);

        if(!$stmt->execute()){
            $erro = $stmt->error;
        }
        else{
            header("Location:cadastro.php");
            exit;
        }
   }
   else {
       $erro = "Número Inválido";
   }

0

You are making syntax error, missing close a key just before the second else, thus:

if(is_numeric($id) && $id >=1){
    $stmt = $obj_mysqli->prepare("UPDATE 'clientes' SET 'nome'=$nome, 'email'=$email, 'cidade'=$cidade, 'uf'=$uf WHERE id= $id");
    $stmt->bind_param('ssssi', $nome, $email, $cidade, $uf, $id);

    if(!$stmt->execute()){
        $erro = $stmt->error;
    }
    else{
        header("Location:cadastro.php");
        exit;
    }
}
else{
    $erro = "Número Inválido";
}
  • is the same as above!

  • Parse error: syntax error, Unexpected 'Else' (T_ELSE) in C: xampp htdocs crud_php_simples_facil cadastro.php on line 57

  • @rafaelgrohl yes, now that I noticed it, but in case I answered first :) put the filter to show older ones first that you will see

Browser other questions tagged

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