0

I need to echo the number 1 or 0 whatever the database has in that cell. I cant seem to get it to work. What am I doing wrong people of the internet?

Picture of the database

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testfp";
$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
$bob = mysql_query($sql);
echo $bob;
?>
chris85
  • 23,846
  • 7
  • 34
  • 51
Riley Mclaughlin
  • 45
  • 1
  • 1
  • 3
  • `$bob = mysql_result(mysql_query("SELECT hookup FROM testfp WHERE name = 100100"),0);` Remember, `mysql_` extensions are deprecated – Thamilhan Jun 05 '16 at 17:33
  • `mysqli` != `mysql_`. Use all `mysqli` functions. – chris85 Jun 05 '16 at 17:37
  • Additionally after `mysql_query` you need to fetch the result object, `$bob` still won't have the value when you use the correct function. – chris85 Jun 05 '16 at 17:40

1 Answers1

0

You can not use mysql and mysqli together. So you can try the following code (using mysqli only, since mysql is deprecated) :

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testfp";
$conn = new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
$result = $conn->query($sql);
if($result->num_rows>0)
{
    while($row = $result->fetch_assoc()) {
        echo $row["hookup"];
    }
}
else
{
    echo "No results found!";
}
?>
Manikiran
  • 2,618
  • 1
  • 23
  • 39