Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Function error : pulling user id from username

$
0
0

I am attempting to setup a profile page based on the information that the user signs up with. 

(I am following a video online, the code matches but he is on a local server i am using a hosted server idk if issue)

 

On my profile.php page I am receiving the warning : 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /home/content/80/11355280/html/core/function/users.php on line 88

 

On my profile page I am trying to use function : user_id_from_username. This function is currently working with my login.

However on profile.php 

<?php
include 'include/widgets/tabletop.php';

	if (isset($_GET['username']) === true && empty($_GET['username']) === false)  {
		$username 	= $_GET['username'];
		$user_id	= user_id_from_username($username); 
		
		echo $user_id;

	} else {
	header('Location: index.php');
	exit();
	}

include 'include/widgets/tablebot.php';
?>

On line 14 I am calling the function I created and attempting to echo out the user id. When I attempt this I receive the warning. 

 

The function is held in users.php and is included on the page. 

 

users.php

function user_id_from_username($username)  {
	$username = sanitize($username);
	return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
}

if I would put a or die at the end of the return mysql_result I get the same error but a different index.

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 12 in /home/content/80/11355280/html/core/function/users.php on line 88

 

Would an if ( something > 0 ) fix this and how?


Viewing all articles
Browse latest Browse all 13200

Trending Articles