简体   繁体   中英

not getting the proper Result when the Sql query is executed

I want if the sql query is executed then and give the count means result 1 then it redirect to profile.php otherwise it redirect to candidate.php

 <?php include "includes/header.php";?> <?php $email=$_SESSION['email']; $link = mysqli_connect("localhost", "root", "", "hr"); if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } $sql = "SELECT * FROM candidate_registration WHERE resume IS NULL && email='$email'"; if(mysqli_query($link, $sql)==true){ header('Location:candidateprofile.php'); } else if(mysqli_query($link, $sql)==false){ header('Location:user\\profile.php'); } 

Your query should look like that

SELECT count(*) AS counter FROM candidate_registration WHERE resume IS NULL && email='$email'

After that you must check what is the value of your counted records.

Based on your request if it finds at least 1 records it will points it to profile.php otherwise to candidateprofile.php

    $result = mysqli_query($link, $sql);
    $row = $result->fetch_row();

    if($row[0]>0){
     header('Location:user\profile.php');
    }
    else{
      header('Location:candidateprofile.php');
    }

Basically you want to COUNT your records. The way you are doing it your statement is always true because an empty mysql return is still valid. So checking if the result is true will actually always returns true.

Tip: Your code is open to SQL injection. Read about using prepared statements so you don't run into "unexpected" problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM