my if else statement not working

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
newfazfly
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Apr 24, 2018 11:56 pm

Wed Apr 25, 2018 12:05 am

<?php
include("connect_dbMSSQL.php");

if(isset($_GET['updatePROGRESS']))
{
$id = $_GET['updatePROGRESS'];
//echo $id;

$sql_getDETAILS = "SELECT project_ID,due_date FROM JR_progress_project WHERE project_ID = '$id'";

$result_getDETAILS = odbc_exec($connection, $sql_getDETAILS);

while(odbc_fetch_row ($result_getDETAILS))
{
$projectID = odbc_result($result_getDETAILS,"project_ID");
$dueDATE = odbc_result($result_getDETAILS,"due_date");
}

echo "project id: ".$projectID."<br/>";
echo "due date: ".$dueDATE."<br/>";

if($dueDATE == 'NotSet')
{
echo "not set";
}
else
{
echo "already set";
}

}
?>

hii.. this is my code.. what i want is.. if value for $dueDATE is 'NotSet', this code will display 'not set'. But the problem is, it always display 'already set'.. please help me

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 761
Joined: Mon Feb 22, 2016 5:52 pm

Wed Apr 25, 2018 8:17 am

odbc_result Returns the string contents of the field, FALSE on error, NULL for NULL data, or TRUE for binary data.
Does your database column "due_date"?
does it contain a date value?
could it contain the string literal 'NotSet'

Do you mean NULL?

chorn
php-forum Fan User
php-forum Fan User
Posts: 564
Joined: Fri Apr 01, 2016 2:18 am

Wed Apr 25, 2018 10:24 am

your condition is false. just check the variables with var_dump().

newfazfly
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Apr 24, 2018 11:56 pm

Wed Apr 25, 2018 4:22 pm

hyper wrote:
Wed Apr 25, 2018 8:17 am
odbc_result Returns the string contents of the field, FALSE on error, NULL for NULL data, or TRUE for binary data.
Does your database column "due_date"?
does it contain a date value?
could it contain the string literal 'NotSet'

Do you mean NULL?

hai Hyper..
yup.. my database volumn name "due_date" and data type is varchar. this column will stored date like "26/04/18" and also "NotSet"

newfazfly
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Apr 24, 2018 11:56 pm

Wed Apr 25, 2018 4:43 pm

chorn wrote:
Wed Apr 25, 2018 10:24 am
your condition is false. just check the variables with var_dump().

hai Chorn..
can you show me the right condition?

i already check with var_dump.. is it correct to check like this?

<?php

$result_getDETAILS = odbc_exec($connection, $sql_getDETAILS);

while(odbc_fetch_row ($result_getDETAILS))
{
$projectID = odbc_result($result_getDETAILS,"project_ID");
$dueDATE = odbc_result($result_getDETAILS,"due_date");
}

echo "project id: ".$projectID."<br/>";
echo "due date: ".$dueDATE."<br/>";

var_dump($dueDATE);

if($dueDATE == 'DD/MM/YY')
{
echo "not set";
//header("location:update_progress1.php?updatePROGRESS=$projectID");
}
else
{
echo "already set";
//header("location:update_progress2.php?updatePROGRESS=$projectID");
}

}
?>

the output is

project id: P-REQ4
due date: NotSet
string(10) "NotSet " already set

it read "NotSet" but not working in if else statement

chorn
php-forum Fan User
php-forum Fan User
Posts: 564
Joined: Fri Apr 01, 2016 2:18 am

Thu Apr 26, 2018 2:59 am

the value is string(10) "NotSet ", so it's !== 'DD/MM/YY' and the else matches, no problem there.

Post Reply