<?php
?>
<?php
$mysql = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASSWORD) or die(mysql_error());
mysql_select_db(MYSQL_DATABASE) or die(mysql_error());
//Code will go here.
mysql_close($mysql);
?>
<?php
$mysql = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASSWORD) or die(mysql_error());
mysql_select_db(MYSQL_DATABASE) or die(mysql_error());
$result = mysql_query("SELECT `Username`,`Money` FROM `MYSQL_TABLE` ORDER BY `Money` DESC LIMIT 0,10"); //Select what you need to select
while($data = mysql_fetch_array($result)) // Make $data an array of the query you just executed.
{
echo "Username: ".$data['Username']" Money: ".$data['Money']."<br>"; // Echo the data and add a line after (<br> is a new line)
}
mysql_free_result($result);
mysql_close($mysql);
?>
<?php
$mysql = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASSWORD) or die(mysql_error());
mysql_select_db(MYSQL_DATABASE) or die(mysql_error());
$result = mysql_query("SELECT `Username`,`Money` FROM `MYSQL_TABLE` ORDER BY `Money` DESC LIMIT 0,10"); //Select from database, order by 'Money' and show 0 through 10 results
//Make the table before the results.
echo '
<table border="1">
<tr>
<th>Username</th>
<th>Money</th>
</tr>
';
while($data = mysql_fetch_array($result)) // Make $data an array of the query you just executed.
{
echo "<tr>
<td>".$data['Username']"</td>
<td>".$data['Money']."</td>
</tr>";
}
echo "</table>";
mysql_free_result($result);
mysql_close($mysql);
?>
<?php
function Escape($string) //Thanks to XFlawless
{
$string = htmlentities($string);
$string = stripslashes($string);
$string = mysql_real_escape_string($string);
return $string;
}
$mysql = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASSWORD) or die(mysql_error());
mysql_select_db(MYSQL_DATABASE) or die(mysql_error());
//Make the table before the results.
if(isset($_GET['User'])) // If the PHPFILE has ?User=<texthere>
{
$_GET['User'] = Escape($_GET['User']); //Prevent any SQL Injections.
$res = mysql_query("SELECT `Username` FROM `MYSQL_TABLE` WHERE `Username` LIKE '".$_GET['User']."'");
if(mysql_num_rows($res) === 1) // Check if there is an account with that username
{
echo 'User Information for : '.$_GET['User'].'<br><br>';
echo '
<table border="1">
<tr>
<th>Username</th>
<th>Money</th>
</tr>
';
$result = mysql_query("SELECT `Username`,`Money` FROM `MYSQL_TABLE` WHERE `Username` LIKE '".$_GET['User']."'"); //Select Money and Username from the database where username is what's inputted
while($data = mysql_fetch_array($result)) // Make $data an array of the query you just executed.
{
echo "<tr>
<td>".$data['Username']"</td>
<td>".$data['Money']."</td>
</tr>";
}
echo "</table>";
mysql_free_result($result);
//I would edit the table a bit and get rid of the Username part.
}
else
{
die("Error: User does not exist.");
}
}
else
{
die("Error: You did not enter a Username.");
}
mysql_close($mysql);
?>
nielsbon, downloading that file will give you the parsed HTML output
|
$_GET['User'] = mysql_real_escape_string($_GET['User']); //Prevent any SQL Injections.
function Escape($string)
{
$string = htmlentities($string);
$string = stripslashes($string);
$string = mysql_real_escape_string($string);
return $string;
}
while($data = mysql_fetch_array($result)) // Make $data an array of the query you just executed.
{
echo "<tr>
<td>".$data['Username']"</td>
<td>".$data['Money']."</td>
</tr>";
}
mysql_free_result($result);//Forgot to free the result ?
Nielsbon1 you've failed to make a correct statement again, If you load from config file, you cannot close the mysql connection, which is insecure as well.
|