Jump to content

Recommended Posts

<?php
include("include/data.php");
if ($_COOKIE[user] == ($username) && $_COOKIE[pass] == md5($password)) {
include("include/config.php");
$query="SELECT * FROM logs";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
echo "<center><font color='#FFFFFF'><b>Logs</b><p>";

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$username=mysql_result($result,$i,"username");
$password=mysql_result($result,$i,"password");
$logger=mysql_result($result,$i,"logger");

echo "Username: $username<br>Password: $password<br>Logged by: $logger<br>";

$i++;
}

}else{
echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">';
}
?>

 

I want it so that if $logger is equal to the login username then display.

If not do not display anything.

Link to comment
https://forums.phpfreaks.com/topic/138578-solved-help-me-with-php-sql/
Share on other sites

This code is cleaner

 

no point finding a all records if you only want to display some

<?php
include("include/data.php");
if ($_COOKIE['user'] == ($username) && $_COOKIE['pass'] == md5($password))
{
include("include/config.php");
$query="SELECT * FROM logs WHERE username=logger";
$result=mysql_query($query);
$num=mysql_num_rows($result);
echo "<center><font color='#FFFFFF'><b>Logs</b><p>";
$i=0;
while ($i < $num)
{
	$id=mysql_result($result,$i,"id");
	$username=mysql_result($result,$i,"username");
	$password=mysql_result($result,$i,"password");
	$logger=mysql_result($result,$i,"logger");
	echo "Username: $username<br>Password: $password<br>Logged by: $logger<br>";
	$i++;
}
mysql_close();
}else{
echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">';
}
?>

<?php
include("include/data.php");
if ($_COOKIE['user'] == ($username) && $_COOKIE['pass'] == md5($password))
{
   include("include/config.php");
   $query="SELECT * FROM logs WHERE username=logger";
   $result=mysql_query($query);
   $num=mysql_num_rows($result);
   echo "<center><font color='#FFFFFF'><b>Logs</b><p>";
   $i=0;
   while ($i < $num)
   {
      $id=mysql_result($result,$i,"id");
      $username=mysql_result($result,$i,"username");
      $password=mysql_result($result,$i,"password");
      $logger=mysql_result($result,$i,"logger");
      echo "Username: $username<br>Password: $password<br>Logged by: $logger<br>";
      $i++;
   }
   mysql_close();
}else{
   echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">';
}
?>

I need it to display the logs on the database where $logger is equal to the login username.

change

$query="SELECT * FROM logs WHERE username=logger";

to

$query="SELECT * FROM logs WHERE logger='$username' ";

That looks about right, but i get an error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\web\PHISHER-V2\phisher\admin\logs.php on line 8

Help?

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.