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?
What exactly are you trying to do?
i want to retrivve the current user on the page its self. to pass on as a variable to a sql query
As this is mod related you would be better to use the mods support topic or www.simpleportal.net
Quote from: andreblue2u 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
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.
Quote from: Arantor on June 17, 2012, 08:00:24 PM
Quote from: andreblue2u 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
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
What query, exactly? (This is important. It has security implications.)
Quote from: Arantor on June 17, 2012, 08:17:37 PM
What query, exactly? (This is important. It has security implications.)
This one:
$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)."');";
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.
When i use it, nothing its self comes up.
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.
<?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.
Yes, commenting out SSI will break it >_<