-2

I tried to build a query to select data from the database, which I can use for the future login form to determine if a user is activated or not.

So in my attempt at this, I did the following:

$con = mysql_connect("localhost","steven","PASSWORD!","leercentrum");

echo("This Works");

$query = "SELECT activated FROM users WHERE username = 'steven' ";
$result = mysql_query($con, $query);
print_var($result);

The query works on my database via SQL Workbench.

I also attached a screenshot of my Mysql database (Table users).

https://i.stack.imgur.com/uef3g.jpg

The only thing I want is create an boolean-returning function to determine if a user is activated (return value 1) or not activated (return value 0).

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Bellino
  • 1
  • 1
  • `mysql_query($con, $query)` you didn't RT\*M on this or on `mysql_connect("localhost","steven","PASSWORD!","leercentrum")` – Funk Forty Niner Nov 13 '16 at 16:55
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Nov 13 '16 at 16:56
  • 2
    all that is mysqli_ syntax, not mysql_ - `mysql_connect()` does not use 4 arguments, not for the 4th one anyway – Funk Forty Niner Nov 13 '16 at 16:56
  • @chris85 In that case can we throw in some PDO syntax for good measure – RiggsFolly Nov 13 '16 at 16:57
  • 1
    `print_var($result);` ? Do we have a new PHP print function as well? – RiggsFolly Nov 13 '16 at 16:59
  • http://php.net/manual/en/function.mysql-connect.php – Jeff Merlin Nov 13 '16 at 16:59
  • @RiggsFolly nope http://php.net/manual-lookup.php?pattern=print_var&scope=quickref ;-) – Funk Forty Niner Nov 13 '16 at 17:07

1 Answers1

1

Posting as a community wiki.

As I outlined in comments....... you can read those.

Here is your fixed code:

<?php

$con = mysqli_connect("localhost","steven","PASSWORD!","leercentrum");

echo("This Works");

$query = "SELECT activated FROM users WHERE username = 'steven' ";
$result = mysqli_query($con, $query);
// print_var($result); Not a core PHP function.

RTMs:

Since I suspect you were used to using mysql_ and thought the same was the same, well...... it isn't.

Btw, print_var() isn't a core PHP function.

See for yourself http://php.net/manual-lookup.php?pattern=print_var&scope=quickref

Why you want to print that, is unknown.

You need to fetch over successful results.

Read the manual http://php.net/manual/en/mysqli.query.php

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Thanx everyone for the comments I just have used print_r ($result); and now I got as result: This Worksmysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 1 [type] => 0 ). I expected that would be just 1 because in the field activated the value is 1 nothing more. Or do I see it wrong ? – Bellino Nov 13 '16 at 18:23