Jump to content

What's wrong with this script? ...


Zoofu

Recommended Posts

<?php

function profile($uid, $link = FALSE){
$sql1 = "SELECT * FROM `users` WHERE `id`='".$uid."'";
$res1 = mysql_query($sql1) or die(mysql_error());
if(mysql_num_rows($res1) == 0){
	return "Invalid User";
}else {
	$row1 = mysql_fetch_assoc($res);
	if(!$link){

	return $row1['username'];	
	}else {
		return $row1['username'];
	}
}
}


echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"20%\">\n";
echo "<tr align=\"left\"><td class=\"forum_header\">".profile($row1['username'])."</a><br>UserID: ".$uid."</td></tr>\n";
echo "<br>\n";
echo "</table>\n";

?>

 

It's returning invalid users. If this script is wrong, please can someone tell me... I'm making a profile page, and I need it to show the users name.

 

As in like, if the profile id is 2, it'll show User #2's name.

Link to comment
Share on other sites

Don't just return "Invalid user" avoid typo's and use constants.

 

define('PROFILE_ERR_INVALID_USER', 'invalid');

function profile($uid, $link = FALSE) {
    $sql1 = "SELECT * FROM `users` WHERE `id`='".$uid."'";
    $res1 = mysql_query($sql1) or die(mysql_error());
    if(mysql_num_rows($res1) == 0){
        return PROFILE_ERR_INVALID_USER;
    } else {
        $row1 = mysql_fetch_assoc($res1);
        if (!$link) {
            return $row1['username'];   
        } else {
            return $row1['username'];
        }
    }
}

 

Afterwards use:

 

$response = profile(..);
if (PROFILE_ERR_INVALID_USER !== $response) {

 

 

Link to comment
Share on other sites

I will go simple to start.


$username = $_POST['username']; // Get Username via a form

$sql1 = "SELECT * FROM `users` WHERE `username`='$username' ";
    $res1 = mysql_query($sql1) or die(mysql_error());
    if(mysql_num_rows($res1) == 0){
        return PROFILE_ERR_INVALID_USER;
    } else {
        $row1 = mysql_fetch_assoc($res1);
        if (!$link) {
            return $row1['username'];   
        } else {
            return $row1['username'];
        }
    }

 

Try this.

 

If it works we can go a bit more more deeper

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.