-2

我对 php 很陌生,现在我正在尝试制作一个积分系统。每当人们做一些好事时,他们都会得到一个点,我可以访问并且可以远程访问数据库。但现在唯一的问题是,人们无法确定自己的观点。我有一个名为“login”的数据库和一个名为“users”的数据库。

我知道如何设置“Welcome dude123(username)”,但我不知道如何举例:你得了 4 分

当用户登录时,我希望向用户显示的用户点:http://i48.tinypic.com/343q8ex.jpg

我的数据库:http: //i50.tinypic.com/33kygqd.jpg

当我输入代码时,它会向用户显示位于顶部的点。每个人都可以看到它!我只希望特定用户拥有自己的。

当我使用此代码时,我收到此错误:http: //i46.tinypic.com/jzcoea.jpg

<?php
require("dbc.php"); 

$sql = "SELECT * from `users` WHERE `username` = " . $_POST['username']; 
$result = mysql_query ($sql);

$query = "SELECT * FROM `users` WHERE `username` = '$username'";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
   $points = $row['points'];


}
echo 'You have ' . $points . 'points.<br />';
?>

登录.php:

<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{

    $connect = mysql_connect("localhost","root","") or die ("Couldent connect to database");
    mysql_select_db("login") or die ("Couldent find database"); 

    $query = mysql_query("SELECT * FROM users WHERE username='$username'");

    $numrows = mysql_num_rows($query);

    if($numrows !=0)

    {

    while ($row = mysql_fetch_assoc($query))
    {
         $dbusername =  $row['username'];
         $dbpassword =  $row['password'];

    }
       if ($username==$dbusername&&$password==$dbpassword)
       {
           echo "Login successful. <a href='membersarea.php'>CLick here to enter the members area</a> ";
           $_SESSION['username']=$dbusername; 

$handle = fopen("logs/logins.txt", "a");
foreach($_POST as $variable => $value) {
   fwrite($handle, $variable);
   fwrite($handle, "=");
   fwrite($handle, $value);
   fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);

$ip = $_SERVER['REMOTE_ADDR'];
$pagina = $_SERVER['REQUEST_URI'];
$datum = date("d-m-y / H:i:s");
$invoegen = $datum . " - " . $ip . " - " . $pagina . "<br />";
$fopen = fopen("logs/ips.txt", "a");
fwrite($fopen, $invoegen);
fclose($fopen);


exit;

       }
       else 
           echo "Incorrect password";
   }
   else 
      die ("That username doesnt exist");

}
else
   die ("Please enter a username and password");


?> 

和我想要显示点的 membersarea.php:

--><br />
  <br />

</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><br />
</p>

<div align="center">
  <p><font size="8">Potten:</font>
  <?php 
mysql_connect ("localhost","root",""); 
mysql_select_db ("login"); 

$sql = "select * from info"; 
       $result = mysql_query ($sql); 

       while ($row = mysql_fetch_array($result)) 
              { 
              $potten= $row["potten"]; 
echo "$potten<br>";
      } 
?>
  </p>

  <p>&nbsp;</p>



</div>
</p>
<div id='cssmenu'>
<ul>
   <li class='has-sub '><a href='#'><span>Points</span></a>
      <ul>
         <li><a href='#'><span>Sell points</span></a></li>
         <li><a href='#'><span>Shop with points</span></a></li>
      </ul>
   </li>

   <li><a href='#'><span>Store</span></a> 
    </li>

   <li><a href='#'><span>Contact</span></a></li>
</ul>
</div>
<div id="highscore" align="center">
</blockquote>
<div class="gradientbuttons blacktheme" align="center">

</div>
<div align="center" >
<div style="width:99%; height:100px; border:3px solid black; font-size: 14px; font-style: italic;" align="center">
  <p>Highscore top 5   </p>

</div>

<div id="cboxdiv" style="text-align: center; line-height: 0">
<div><iframe frameborder="0" width="200" height="305" src="http://www7.cbox.ws/box/?boxid=655854&amp;boxtag=7j5vas&amp;sec=main" marginheight="2" marginwidth="2" scrolling="auto" allowtransparency="yes" name="cboxmain7-655854" style="border:#FFFFFF 1px solid;" id="cboxmain7-655854"></iframe></div>
<div><iframe frameborder="0" width="200" height="75" src="http://www7.cbox.ws/box/?boxid=655854&amp;boxtag=7j5vas&amp;sec=form" marginheight="2" marginwidth="2" scrolling="no" allowtransparency="yes" name="cboxform7-655854" style="border:#FFFFFF 1px solid;border-top:0px" id="cboxform7-655854"></iframe></div>
</div>
<div id="info" align="left">
<div id="text" align="bot">
<p>Totalt kj&oslash;pte lodd:  
    <?php
mysql_connect ("localhost","root",""); 
mysql_select_db ("login"); 

$sql = "select * from info"; 
       $result = mysql_query ($sql); 

       while ($row = mysql_fetch_array($result)) 
              { 
              $totallodd= $row["totallodd"];  

echo "$totallodd<br>"; 

              } 
?>
</p>
<p> <span class="sd">Dine poeng</span>:</p>
<p>Dine lodd:
  <?php

mysql_connect("localhost","root","");
mysql_select_db("login");


$sql = mysql_query("SELECT * FROM users ORDER BY id ASC"); 

$id ='id';
$buy = 'buy';

$rows =mysql_fetch_assoc($sql);

echo  '' . $rows[$buy];

?>
</p>

<center><script type="text/javascript" src="http://widget.supercounters.com/online_t.js"></script><script type="text/javascript">sc_online_t(395328,"Users Online","0");</script><br><noscript><a href="http://www.supercounters.com/">Free Tumblr Users Online Counter</a></noscript>
</center>
</div>
<?php

     echo "<a href='logout.php'>logge ut!</a>";

?>
</div>
</div>
</div>
<div class="gradientbuttons orangetheme"> </div></div><p>&nbsp;</p>
  </blockquote>
</blockquote>
<div id="fb-root" align="center">
<p style="color:#FF0000" >Du har fortsatt ikke aktivert poeng! <a href="activate.php">klikke her</a> for å få tilgang til poengene dine</p>
</div>

</body>
</html>
<!-- lappserver18 -->

<!-- [SB] PageID 250995577-->
<!-- null -->
4

2 回答 2

0

在显示积分之前,Yu 需要对查看页面的用户进行登录检查。目前您的查询$sql = "select * from info";正在$sql = "select * from info"; 选择这些表中的所有数据。* = 一切。您将需要使用您的$_SESSION['username']变量来仅查询和显示分配给该用户的点。

就像是:

$sql = "SELECT * FROM info WHERE username = " . $_SESSION['username'];

从表中提取与用户名匹配的所有表信息,或者:

$sql = "SELECT points FROM info WHERE username = " . $_SESSION['username'];

这只会从数据库表中提取并显示登录用户信息。

于 2012-12-05T21:11:06.717 回答
0

我认为您的问题可能在 membersarea.php 中:

$sql = "select * from info";

你的info桌子的结构是什么?你能限制搜索,只搜索登录的用户吗?就像是:

$sql = "SELECT * from `info` WHERE `username` = " . $_POST['username']; 

我认为您正在为所有用户返回所有积分。做这个:

$num_rows = mysql_num_rows($sql);
echo $num_rows;

也许这个免费的视频教程会有所帮助:
https ://phpacademy.org/course/php-register-and-login-tutorial

于 2012-12-05T22:49:31.843 回答