Redirect pages using if, Else if and Else attributes what is wrong?

Asked

Viewed 498 times

0

my php code

<?php

include "conectar.php";


//comando para iserir dados direto do formul?rio para o banco de dados

$nome=$_POST["nome"];
$cpf=$_POST["cpf"];
$identidade=$_POST["identidade"];
$telefone=$_POST["telefone"];
$celular=$_POST["celular"];
$email=$_POST["email"];
$cep=$_POST["cep"];
$endereco=$_POST["endereco"];
$complemento=$_POST["complemento"];
$bairro=$_POST["bairro"];
$cidade=$_POST["cidade"];
$uf=$_POST["uf"];
$sexo=$_POST["sexo"];
$idade=$_POST["identidade"];
$peso=$_POST["peso"];
$individual=$_POST["individual"];
$tresvidas=$_POST["tresvidas"];
$cincovidas=$_POST["cincovidas"];


$sql="INSERT INTO cadsolidario VALUES ('$nome', '$cpf', '$identidade', '$telefone', '$celular', '$email', '$cep', '$endereco', '$complemento', '$bairro', '$cidade', '$uf', '$sexo', '$idade', '$peso', '$individual', '$tresvidas', '$cincovidas')";
$RES=mysqli_query($con,$sql);
$num=mysqli_affected_rows($con);

if($num = "tresvidas"){
include('busca.php');

}else if($num = "cincovidas"){
    include('index.php');

}else{
     include('consulta-consultas.php');
}

?>

Note: You are entering the data correctly. But aren’t you redirecting what I should do? Thank you!

  • Hello Flavio, the code is missing.

  • 1

    To compare values use two equal signs == and not one (which is attribution)

  • OK I’ll authenticate and I’ll tell you if there have been changes, thank you! -rray

  • I get the feeling you’ll always fall for else, $num receives a number but you compare it to a string...

  • As for what is happening, should I put $res? I confess that I was totally lost! Rs.

  • @Flaviocordas Where do the words "tresvidas" and "cincovidas" come from? From the database?

  • I don’t know what you’re comparing nor the pq, need to explain these details by editing the question.

  • Sorry for the delay! i want from the data typed in the form, where $tresvidas=$_POST['tresvidas']; for chosen take me to page php search! Understand?

  • tresvidas is a radio button or select?

Show 4 more comments

1 answer

1

The mysqli_affected_rows() return the NUMBER of affected Rows, however, you are comparing with a string.

I also noticed that you’re using = in their if. What’s wrong is that = is used in comparisons in PHP while == is used to see if one value is exactly the same as the other.

  • True, it also has this, it takes and adds the answer the problem that rray spoke https://answall.com/questions/255954/redirecionar-paginas-usando-attributeif-else-if-e-else-o-que-est%C3%a1-wrong#comment525182_255954

  • Good evening, I want to select on the form either tresvidas or cincovidas and from there according to the selection send me to the respective pages. I really need this help, sorry for the delay!

  • Friends already solved!

  • if($tresvidas == "tresvidas"){ include('tresvidas.php'); }Else if($cincovidas == "cincovidas"){ include('dependents.php'); }Else{ include('index.php'); } mysqli_close($con);

Browser other questions tagged

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