1

This is my HAUNTED code.

ini_set("display_errors", true);
ini_set("html_errors", false); 
require "conn.php";
echo "debug 1";
$stmt2 = $conn->prepare("SELECT * FROM UserData WHERE username = ?");
$stmt2->bind_param('s',$username);
//$username = $_POST["username"];
$username ="netsgets";
$stmt2->execute();
$stmt2->store_result(); 
if ($stmt2->num_rows == 0){ // username not taken
echo "debug 2.5";

die;
}else{
// prepare query
$stmt=$conn->prepare("SELECT * FROM UserData WHERE username = ?");
// You only need to call bind_param once
$stmt->bind_param('s',$username);
$username = "netsgets";
// execute query
$stmt->execute(); 
$stmt->store_result();  
// bind variables to result
$stmt->bind_result($id,$dbUser,$dbPassword,$Type1,$Type2,$Type3,$Type4,$Type5);
//fetch the first result row, this pumps the result values in the bound variables

if($stmt->fetch()){
    echo 'result is ' . $Type1, $Type2,$Type3,$Type4,$Type5;
}


//var_dump($query2);
echo "hi";

echo "debug 2";



echo "debug 2.7";

    if ($Type1 == "empty"){

        echo "debug 3";
        $sql11 = $conn->prepare("UPDATE UserData SET likedOne=? WHERE username=?");
        $sql11->bind_param('ss',$TUsername,$Username);
//      $TUsername = $_POST["TUsername"];
//      $Username = $_POST["username"];
        $TUsername = "test";
        $Username = "netsgets";
        $sql11->execute();



    } 
}

This is what it returns (echos).

Connected successfullydebug 1result is empty empty empty empty empty hidebug 2debug 2.7

As you can see, Variables Type1,Type2,Type3,Type4,Type5 all equal "empty". For some reason, as you can see, the if statment doesn't think it is "empty" for it is not echoing "debug 3". What the..... (also no errors.)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ron Arel
  • 19
  • 5

1 Answers1

1

If this code...

echo 'result is ' . $Type1, $Type2,$Type3,$Type4,$Type5;

literally produces this output...

result is empty empty empty empty empty

with spaces between each "empty", then obviously the Type* values in your database are all "empty " or " empty" or some other combination with leading / trailing whitespace.

You'll want to do the comparison with

trim($Type1) == 'empty'

Also, as mentioned in the comments, never use SELECT * in combination with bind_result. You should always be explicit regarding the columns selected and what order they appear in, eg

SELECT id, dbUser, dbPassword, Type1, Type2, Type3, Type4, Type5 FROM ...
Phil
  • 157,677
  • 23
  • 242
  • 245
  • Sure, until you add or remove a column or your database decides to change the order – Phil Aug 10 '17 at 21:35