2

All this section is supposed to do is collect an int from active and use it in the if statement to continue with the code. Can somebody please tell me why this is not working?

$act_qry = "Select active FROM user_m WHERE username = '$username' and password = '$Menrypted_password'";
$result_act = mysqli_query ( $connMS, $act_qry );
$value_act = mysqli_fetch_object($result_act);

if($value_act == 1)
{
    //Do php stuff.
}
wogsland
  • 9,106
  • 19
  • 57
  • 93
GenGen
  • 103
  • 1
  • 12

1 Answers1

2

I am having this table in my database:-http://prntscr.com/9tnalx

Check this code:-

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
//connect to database
$link = mysqli_connect('localhost','root','','stack');
$act_qry = "Select product_id FROM bom WHERE bom_description = 'Table Tops'";
$result_act = mysqli_query ( $link, $act_qry ) or die(mysqli_error($link));

$value_act = mysqli_fetch_object($result_act);

if($value_act->product_id == 1)
{
    echo $value_act->product_id;
}
// or you can do this 

$value_act = mysqli_fetch_assoc($result_act);

    if($value_act['product_id'] == 1)
    {
        echo $value_act->product_id;
    }
    mysqli_close($link);
    ?>

Output on my browser:- http://prntscr.com/9tnazj

Note:- I hope you can understand the code by checking my screenshot of table.Thanks

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • if($value_act->product_id == 1) How would I write that using procedural style? – GenGen Jan 23 '16 at 04:17
  • Although I dont fully understand the $value_act->product_id it does work what I needed it to. Thank you @A-2-A. – GenGen Jan 23 '16 at 04:35
  • @GenGen Note the `mysqli_fetch_assoc` is returning an array. When you ask for an object, `mysqli_fetch_object`, you get an object. – chris85 Jan 23 '16 at 04:38
  • 1
    Thanks @GenGen. Since `$value_act` is an object so if you want to get any property of that object then you have to do `$object name->property name`. I added another one in my code also – Alive to die - Anant Jan 23 '16 at 04:39