我正在尝试编写一个页面来检查数据库是否存在用户 IP 地址,如果不存在,它会提供他们以表格形式注册,如果用户确实存在,那么它会提供一个“播放”按钮。
由于某些奇怪的原因它不起作用,我在数据库中有一个帐户,但它仍然不会提供“播放”按钮。我也试过用我制作的表格注册,但是当我点击提交时页面没有做任何事情。
<?php
$con = mysqli_connect("localhost","root","","********");
$ip = $_SERVER['REMOTE_ADDR'];
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Checking DB Connection//
$result = mysqli_query($con,"SELECT * FROM users WHERE ip='$ip'");
while($row = mysqli_fetch_array($result)) {
$rsname = $row['rsname'];
$tokens = $row['tokens'];
}
if (mysqli_num_rows($result) > 0) {
if ($tokens >= 1) {
echo '<h2>Hello '.$rsname.'! Click The Button Below To Play!';
echo '<a href="slots.php"><button>Play!</button></a>';
}
else {
echo '<h2>Your Account "'.$rsname.'" Already Exists, But You Do Not Have Any Tokens.</h2><br />';
echo '<h3>You Can Purchase More Token From "Got Your IP" In Game For 20k/Token.</h3>';
}
}
else if (isset($_POST['rsname'])) {
$sql="INSERT INTO users (rsname, ip)
VALUES
('$_POST[rsname]','$_SERVER[REMOTE_ADDR]')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo '<h2>Your account has been setup! Click the button below to play! </h2>';
echo '<a href="slots.php"><button>Play!</button></a>';
}
else {
echo '<h2>You Need To Register To Play RSLOTTO.</h2>';
echo '<form id="form1" name="form1" method="post" action="play.php">';
echo 'RuneScape Username:';
echo '<input name="rsname" type="text" id="rsname" size="32" maxlength="40" />';
echo '<input name="submit" type="button" value="submit" /></form>';
echo 'We only ask for your username and not a password, because we tie your username to your IP address so you don\'t need to enter a password. Safe as can be! :D';
}
mysqli_close($con);
?>