1

I have a simple if / else statement repeated in a second code block that should trigger and include an additional html code block but for some reason I havent been able to see it's not. I've been driving myself a little nuts trying to find the issue but for the life of me I can't. Excerpt below, thanks in advance :)

<?php
require_once("includes/conn.php");

  $validateSQL="SELECT `email`,`token` FROM `users` WHERE `token`='".$_GET['token']."' AND `state`='1'";
  $userData =$link->query($validateSQL) or trigger_error($link->error." [$validateSQL]");
  $user=$userData->fetch_assoc();

  $row_cnt = $userData->num_rows;
  if ($row_cnt < 0){
    $user=$userData->fetch_assoc();
  };
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="css/login.css" />
        <link href="css/Raku.css" rel="stylesheet">
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <title>Raku Māturanga : The Knowledge Tree</title>

    </head>
    <body style="">
        <div class="background-plate">
            <div id="heading-main">
                <h1 class="">Raku Māturanga : The Knowledge Tree<br>
                <small style="color:#ddddbb">Nau mai, welcome to where knowledge grows.</small></h1>
                <p style="color: white; text-align: center">Making colobrative planning and evaluation eaiser than ever before.</p>
            </div>

<?php
if ($row_cnt < 0){
    include("includes/snippets/validate_setPassword.php");
  }else{

  }
  ?>

        </div>
        <div class="container-low">

3 Answers 3

2

First of all you have a syntax error in your code, you have to remove ; after brakcets in your if statement.

$row_cnt = $userData->num_rows;
  if ($row_cnt < 0){
    $user=$userData->fetch_assoc();
  };

Should be :

$row_cnt = $userData->num_rows;
  if ($row_cnt < 0){
    $user=$userData->fetch_assoc();
  }

Then the second reason your if statements are not working is your conditions. you check for the value under zero which won't ever be true to run through your if statement.

you should put :

first part:

$row_cnt = $userData->num_rows;
  if ($row_cnt <= 0 || $row_cnt == null){
    $user=$userData->fetch_assoc();
  }

Second part:

if ($row_cnt <= 0 || $row_cnt == null){
    include("includes/snippets/validate_setPassword.php");
  }else{

  }

Let me know if it's working

Sign up to request clarification or add additional context in comments.

2 Comments

Appreciate this - It wasn't quite what I needed but it got me in the right direction - seems I have a good ability to mix up < and >. I couldn't see the if statement fire because I was trying to set $user=$userData->fetch_assoc(); again inside the loop. Made the condition $row_cnt === 1 as I really just want to know if there is one row returned and we're all good now
@MichaelClark Glad to be able to help you.
0

I think you $userData->num_rows returns zero or null thats why your if condition is not executed change your if condition to

    if ($row_cnt <= 0 || $row_cnt != null){
    include("includes/snippets/validate_setPassword.php");
  }else{

  }

I hope it will help you

Comments

0

you $userData->num_rows returns zero or null or number of rows from database so just change your if else condition from

($row_cnt < 0) to ($row_cnt >= 0)

I think will fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.