我已经阅读了很多这方面的教程,但似乎无法实现这一点 - 我在服务器上有以下PHP文件:
<?php
$host_name = "";
$database = "";
$user_name = "";
$password = "";
$connect = mysqli_connect($host_name, $user_name, $password, $database);
$user = $_POST['user'];
$sports = $_POST['sports'];
$location = $_POST['location'];
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "UPDATE `userActivityLocation` WHERE user='$user' SET sports='$sports', location='$location'";
$result=mysql_query($sql);
?>
我尝试了几种方法无济于事,不确定我做错了什么!非常感谢任何建议,谢谢!
修改 : 我按照morgunder的建议尝试了以下内容,但我仍然无法在数据库中看到任何记录。
以下是提交按钮的点击监听器:
$('#register').click(function () {
console.log("Ready! Getting the user details.");
username = document.getElementById('login').value;
password = document.getElementById('password').value;
email = document.getElementById('email').value;
window.localStorage.setItem("user", username);
console.log("Username: ", username);
console.log("Password: ", password);
console.log("E-Mail: ", email);
var params, connection;
params = {
login: username,
password: password,
email: email
};
//console.log("Params: ", params);
console.log("Creating new user");
QB.users.create(params, function (err, result) {
console.log("Result: ", result.toString());
// callback function
alert(username.toString());
var usernamePost = username.toString();
$.post("http://www.baseurl.co.uk/API/users.php", { user: usernamePost }, function (data) {
console.log(data);
console.log("HERE");
});
window.location = "sportsSelector.html"
});
});
答案 0 :(得分:1)
您已经说过,您希望插入记录,但是您使用UPDATE
SQL命令。这就是为什么没有创建记录的原因。
试试这个:
$sql = "INSERT INTO `userActivityLocation`(user,sports,location) VALUES ('$user', '$sports', '$location')";
还有一些事情需要考虑:
.htaccess
like here 答案 1 :(得分:0)
解决了!在你可爱的人的帮助下,但最终的答案是一个完全独立的不太明显的问题。事件被解雇,帖子开始了,服务器端代码很好,修复后javascript很好,但是后来被window.location调用粗暴地打断了!这就是破坏交易的原因。