PHP Tutorials: Register & Login (Part 5): User Login (Part 2)

Codecourse · 108K views · 2012 · 9:42

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when they are debugging code copied from the tutorial, especially user_exists failures and attempts to convert its mysql_* calls to mysqli.

Recommended by 0 people across 0 different months, 2013 to 2019.

What it is

A 2012 Codecourse tutorial, part 5 of a PHP register and login series, that continues building the user login system. It walks through a user_exists function using the old mysql_* functions and a sanitize helper, with the instructor coding along on screen.

What people said

Cites user2595470 · 2013-07 · Stack Overflow · on “php mysql user login show user exists”

I'm going through a vid tutorial on creating a user reg & login form in php and mysql. The following script should echo 'exists' on the login.php form, however just shows a blank (indicating the user does not exist, when it does and s in fact the only username on the DB) <?php function user_exists($username) { $username = sanitize($username); $query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'"); return (mysql_result($query, 0) == 1) ? true : false; } ?> The login form portion of code goes as follows: if (user_exists('andy') === true) { echo 'exists'; } die(); Am I missing some syntax or something obvious?? here is a link to the vid tutorial if it helps [this video]

Cites user3000310 · 2013-11 · Stack Overflow · on “Converting from MySQL to MySQLi, how can I pass a connection to MySQLi inside of a function?”

I'm pretty new to PHP, and I'm following this PHP academy tutorial on a register-login system. [this video] In the tutorial, he uses MySQL functions, like mysql_connect , mysql_query , and mysql_real_escape_string etc. As recommended, I'm working on a new project and want to use mysqli to accomplish the same user login system. I have two functions so far that require some database connectivity. Below is the example of my sanitize function: <?php include ('connect.php'); function sanitize($data){ return mysqli_real_escape_string($data); } ?> When I try to run this, I'll get an error like below: Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given So, I can add the connection

Cites Ignas Karpušenkovas · 2015-10 · Stack Overflow · on “Register & Login code does not work”

I've been working on a login/register system like in this video: [this video] , but the problem is that it is using Mysql rather than Mysqli functions which makes it almost impossible to understand to me as a beginner. Basically, I`m stuck at database checking if "user_exists" function. Would anyone be able to point me to the right direction? <?php function user_exists($username) { include 'core/database/connect.php'; $username = sanitize($username); $sql = "SELECT COUNT(user_id) FROM `users` WHERE username = '$username'"; $query = mysqli_query($db, $sql); return (mysqli_result($query, 0) == 1) ? true : false; } function mysqli_result($res,$row=0,$col=0) { $numrows = mysqli_num_rows($res); if ($n

Cites Koessien · 2016-05 · Stack Overflow · on “PHP database connecting error”

I am building the login script from this tutorial: [this video] As seen in the comments, I have the same error with the user_exist function. Can anyone help me find out what I did wrong or what I should do to fix the problem? The problem is: when i execute this code, I am seeing a blank page. I should see the text: exists. function user_exists($username) { $username = sanitize($username); $query = mysql_query("SELECT id FROM gebruikers WHERE username = '$username'"); return (mysql_result($query, 0) == 1) ? true : false; }

Cites Ricardo Ramirez · 2019-05 · Stack Overflow · on “Login page "mysqli_query"”

I am setting up a web server with sql database been watching a video on it everything looked like it was working up until this issues <?php function user_exists($username) { $username = sanitize($username); $con = mysqli_connect('localhost', 'root', ''); $query = mysqli_query("SELECT COUNT (`id`) FROM users WHERE username = '$con,$username'"); return (mysqli_result($query, 0) == 1) ? true : false; } ?> Recoverable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\login\core\functions\users.php on line 5 Note :- I have taken reference from this Video, but i have changed mysql_* to mysqli_* [ [this video]