Advertisement:

Author Topic: Get a user name from simple portal page.  (Read 3252 times)

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Get a user name from simple portal page.
« on: June 17, 2012, 07:42:48 PM »
So i want to be able to get a person's username from within a simple portal php page. What would i do to do so?

TheListener

  • Guest
Re: Get a user name from simple portal page.
« Reply #1 on: June 17, 2012, 07:43:47 PM »
What exactly are you trying to do?

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Re: Get a user name from simple portal page.
« Reply #2 on: June 17, 2012, 07:57:16 PM »
i want to retrivve the current user on the page its self. to pass on as a variable to a sql query

TheListener

  • Guest
Re: Get a user name from simple portal page.
« Reply #3 on: June 17, 2012, 07:59:28 PM »
As this is mod related you would be better to use the mods support topic or www.simpleportal.net

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,122
    • StoryBB/StoryBB on GitHub
Re: Get a user name from simple portal page.
« Reply #4 on: June 17, 2012, 08:00:24 PM »
i want to retrivve the current user on the page its self. to pass on as a variable to a sql query

Why, exactly?

Depending on what you're trying to use that query for 1) it might not even work and 2) odds are the user id is better to be used anyway (more reliable, faster for most things)

Let us know what you're trying to use it for and maybe we can provide you with better information on how to do it.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Re: Get a user name from simple portal page.
« Reply #5 on: June 17, 2012, 08:11:30 PM »
i want to retrivve the current user on the page its self. to pass on as a variable to a sql query

Why, exactly?

Depending on what you're trying to use that query for 1) it might not even work and 2) odds are the user id is better to be used anyway (more reliable, faster for most things)

Let us know what you're trying to use it for and maybe we can provide you with better information on how to do it.
I want to display the names of the persons who entered info. and so far with me passing it thru a text field it works fine for the query

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,122
    • StoryBB/StoryBB on GitHub
Re: Get a user name from simple portal page.
« Reply #6 on: June 17, 2012, 08:17:37 PM »
What query, exactly? (This is important. It has security implications.)
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Re: Get a user name from simple portal page.
« Reply #7 on: June 17, 2012, 08:50:00 PM »
What query, exactly? (This is important. It has security implications.)
This one:
Code: [Select]
$AddQuery = "INSERT INTO `melon`.`".$SQLTable."` (`name`, `adder`, `reason`) VALUES ('".mysql_real_escape_string($_POST['McUserToAdd'])."', '".mysql_real_escape_string($_POST['McUserAdder'])."', '".mysql_real_escape_string($Reason)."');";


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,122
    • StoryBB/StoryBB on GitHub
Re: Get a user name from simple portal page.
« Reply #8 on: June 17, 2012, 09:04:07 PM »
If it's inside either the forum or SSI, $context['user']['name'] will contain the user's display name (not their internal name)

You don't need to push it through $_POST, just grab it from that variable.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Re: Get a user name from simple portal page.
« Reply #9 on: June 18, 2012, 01:37:08 AM »
When i use it, nothing its self comes up.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,122
    • StoryBB/StoryBB on GitHub
Re: Get a user name from simple portal page.
« Reply #10 on: June 18, 2012, 09:48:19 AM »
Did you declare $context as global before trying to use it?

You're asking me to help you and I have no information to do so.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline andreblue2u

  • Newbie
  • *
  • Posts: 6
Re: Get a user name from simple portal page.
« Reply #11 on: June 18, 2012, 11:19:21 AM »
Code: [Select]
<?php
//require_once('/home/andreblu/public_html/melon/forum/SSI.php');
//Define as needed.
$SQLHost 'localhost';
$SQLDatabase '';
$SQLUser '';
$SQLPassword '';
$SQLTable 'whitelist';
$col "";
$User =  $context['user']['name'];
//Connect here
mysql_connect($SQLHost$SQLUser$SQLPassword);
mysql_select_db($SQLDatabase);
//Function for current url
function my_url(){

    
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

    return 
$url;

}
//Check if set and isset($_POST['McUserAdder'])
if(isset($_POST['McUserToAdd'])  and isset($_POST['Submit'])){
//Assagin some thing if none
if(empty($_POST['Reason'])){
$Reason 'Reason';
}else{
$Reason $_POST['Reason'];
}
//Meh
echo 'Trying to add player : '.$_POST['McUserToAdd'].'<br />';
//Add to here
$AddQuery "INSERT INTO `".$SQLDatabase."`.`".$SQLTable."` (`name`, `adder`, `reason`) VALUES ('".mysql_real_escape_string($_POST['McUserToAdd'])."', '".mysql_real_escape_string($User)."', '".mysql_real_escape_string($Reason)."');";
//Errors
if(mysql_query($AddQuery)){
echo '<br />User Added<br />';
} else {
print(mysql_error());
echo '<br />';
echo $AddQuery;
echo '<br />';
}
}
echo 
my_url();
//Form for name and their name. Also reason and such
//Remove will be a 2nd page to reducce mistakes

?>

<form action="<?echo my_url(); ?>" method="POST">
<p>WhiteList: <input type="text" name="McUserToAdd" /></p>
<p>Your Name: <input type="text" name="McUserAdder" /></p>   
<p>Reason: <input type="text" name="Reason" /></p> 
<input type="hidden" name="Submit" />
<p><input type="submit" value="Submit" /></p>
</form>
<?
//Listing
//Query
$query = "SELECT * FROM `" . $SQLTable . "`;";
$Result = mysql_query($query);

echo "<table width=70% border=1 cellpadding=5 cellspacing=0>";

echo "<tr style=\"font-weight:bold\">
<td>Name</td>
<td>Added By</td>
<td>Reason</td>
</tr>";
$col = "";
while($row = mysql_fetch_assoc($Result)){

if($col == "#00CC33"){
$col = "#00FF33";
}else{
$col = "#00CC33";
}
echo "<tr bgcolor=$col>";

echo "<td>".htmlentities($row['name'])."</td>";
echo "<td>".htmlentities($row['adder'])."</td>";
echo "<td>".htmlentities($row['reason'])."</td>";

echo "</tr>";
}

?>

Thats how i have it set

EDIT: Got it working. Thanks foe helping me with this.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,122
    • StoryBB/StoryBB on GitHub
Re: Get a user name from simple portal page.
« Reply #12 on: June 18, 2012, 11:44:24 AM »
Yes, commenting out SSI will break it >_<
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.