-3

I am trying to select something in my table for a specific userId. Everything seems to be ok. But he doesn't echo it. This is my php:

<?php
    $con=mysqli_connect(HOST,USER,PASS,DATABASE);
    if (mysqli_connect_errno($con))
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysql_query($con,"SELECT punten FROM users WHERE userId ='1'") or die (mysql_error());
    $row = mysql_fetch_assoc($result);
    $id = $row['punten'];
    echo $id;
?>

Somebody knows how to fix this?

Okay, I am connecting with mysqli and ant to select with mysql, but now it is still not working: <?php $con=mysqli_connect(localhost,moneyzcl_m,AJ22082002,moneyzcl_m); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else{ echo 'connected'; } $sql = "SELECT punten FROM users WHERE userId = 1"; $result = mysqli_query($conn, $sql); echo $result; ?>

But it is saying connected. So, how to fix this?

Aaron jonk
  • 31
  • 1
  • 5
  • look at what mysqli_query actually returns http://php.net/manual/en/mysqli.query.php –  Oct 15 '16 at 21:50
  • `echo $result;` you can't just "echo" that you know and these need to be quoted `(localhost,moneyzcl_m,AJ22082002,moneyzcl_m)`. Please spend the time that's needed to read the manuals and understand them, before coding blindly. – Funk Forty Niner Oct 16 '16 at 02:44

1 Answers1

-1

For query you are using mysql and for connection using mysqli. It doesn't works with that. Use mysqli or PDO, mysql is deprecated.

Kinshuk Lahiri
  • 1,445
  • 9
  • 21