【发布时间】:2014-01-15 20:32:18
【问题描述】:
<?php
include_once("php_includes/check_login_status.php");
if($user_ok != true){
header("location: login.php");
exit();
}
?>
<?php
$id = "SELECT id FROM users WHERE username='$log_username'";
if(isset($_POST["signupbtn"])) {
if ($log_username) {
/// getting data from submitted form into local variables
$x = preg_replace('#[^a-z 0-9]#i', '', $_POST['xbox']);
$p = preg_replace('#[^a-z 0-9]#i', '', $_POST['psn']);
$s = preg_replace('#[^a-z 0-9]#i', '', $_POST['steam']);
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
// DUPLICATE DATA CHECKS FOR GAMER PROFILES
$sqli = "SELECT username FROM player WHERE xbox='$x' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$x_check = mysqli_num_rows($query);
// -------------------------------------------
if ($x_check > 0){
echo "Xbox Gamer-Tag already linked to a user on this website";
exit();
} else if (is_numeric($x[0])) {
echo 'Xbox Gamer-Tag cannot begin with a number';
exit();
}
$sqli = "SELECT username FROM player WHERE psn='$p' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$p_check = mysqli_num_rows($query);
// -------------------------------------------
if ($p_check > 0){
echo "PSN User already linked to a user on this website";
exit();
} else if (is_numeric($p[0])) {
echo 'PSN User cannot begin with a number';
exit();
}
$sqli = "SELECT username FROM player WHERE steam='$s' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$s_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if ($s_check > 0){
echo "Steam account already linked to a user on this website";
exit();
} else if (is_numeric($s[0])) {
echo 'Steam account cannot begin with a number';
exit();
} else { $sqli = "INSERT INTO player (id, username, xbox, psn, steam, ip, created, lastupdated, notecheck)
VALUES ('$id','$log_username','$x','$p','$s','$ip',NOW(),NOW(),NOW())";
$query = mysqli_query($db_conx, $sqli);
}
echo "Gamer Profiles Updated";
exit();
if (!file_exists("p_player/$log_username")) {
mkdir("p_player/$log_username", 0755);
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="templates/default/style/style.css">
<style type="text/css">
#profiles{
margin-top:24px;
}
#profiles > div {
margin-top: 12px;
}
#profiles > input,select {
width: 200px;
padding: 3px;
background: #F3F9DD;
}
#profiles {
font-size:18px;
padding: 12px;
}
</style>
<script src="js/main.js"></script>
<script src="js/ajax.js"></script>
</head>
<body>
<?php include_once("templates/default/template_pageTop.php"); ?>
<div id="pageMiddle">
<h3>Gamer Profiles</h3>
<form action="player.php" method="POST" name="profiles">
<div>Xbox Gamer-tag: <input type="text" name="xbox"></div>
<div>PSN User: <input type="text" name="psn"></div>
<div>Steam User: <input type="text" name="steam"></div>
<input type="submit" name="signupbtn">
</form>
</div>
<?php include_once("templates/default/template_pageBottom.php"); ?>
</body>
</html>
$log_username 变量来自顶部的 php 脚本,一切都很好,因为我可以回显该变量并返回此页面上的登录用户。
所以在提交按钮时基本上没有任何内容被写入我的数据库,我真的很难过。我在 php 5 中使用 MySQLi 扩展,因为我一直在学习有关事物的教程,并且已经到了教程的结尾,现在我一个人了。我打算在下面添加一张我的数据库的照片,以证明数据库上的名字是好的,但事实上我的代表是 9,我不能添加一个来让你的生活更轻松,因为你需要 b 10。
我有没有在错误的地方得到一个 } 或者在它应该是 MySQLi 时标记了一些 MySQL。 当我提交表单时,mkdir 会在文件夹中创建,然后我会被发送到带有 echo“Gamer Profiles Updated”的页面
感谢任何试图解决这个问题的人。
我已经尝试这样做了好几个小时,从我所做的一切来看,一切都很好,理论上它应该可以工作,但它就是行不通。再次感谢您查看此内容,期待您的回复。
【问题讨论】:
-
尝试将
echo "Gamer Profiles Updated";移动到实际执行插入的块中,以确保正在执行代码。 -
检查
mysqli_query的返回值。如果为 false,则打印mysqli_error($db_conx)以查看错误消息。 -
感谢您的回复。我只是把它放在插入的正下方和 } 中。它仍然可以正常返回并将我发送到回显页面。感谢您的回复
-
您永远不会调用
mysqli_query($id)来获取ID,而是将$idSQL 放入INSERT查询中。这会导致额外的引号和语法错误。 -
感谢大家的帮助,但下面的回复解决了我的问题。