我对 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> </p>
<p> </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> </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&boxtag=7j5vas&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&boxtag=7j5vas&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ø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> </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 -->