0

我正在尝试使用 jQuery 和 PHP 将用户插入数据库。PHP 文件本身已经过单独测试并且工作正常,ajax 请求之前的 javascript 变量也工作正常。

任何帮助是极大的赞赏!

ajax.js

$(document).ready(function(){

$("#add-user-btn").click(function() {

var email = $("#email").val();
var name = $("#name").val();
var password = $("#password").val();
var pass = hex_sha512(password);
var random_number = Math.floor((Math.random()*1000)+1);
var salt = hex_sha512(random_number);
var p = hex_sha512(pass+random_number);
var action = "adduser";

$(function () 
{
$.ajax({          
  url: '../actions.php',                  
  type: 'POST',          
  data: {
      action:action,
      email:email,
      name:name,
      password:p,
      salt:salt,
      authorization:authorization
      },                        
  dataType: 'json',               
  success: function(data)         
  {
      $(".close-reveal-modal").click();
  }
});
});
});
});

动作.php

if($_POST['action'] == "adduser"){
$email = $_POST['email'];
$name = $_POST['name'];
$password = $_POST['password'];
$salt = $_POST['salt'];
$domain = "level";
$authorization = $_POST['authorization'];

$query = "INSERT INTO users (email, username, password, salt, domain, level) VALUES ('$email', '$name', '$password', '$salt', '$domain', '$authorization')"; 
$mysqli->query($query);
}

还尝试在 PHP 文件末尾添加以下内容,但无济于事。

$resp = new stdClass();
$resp->success = false;
if($result) {
    $resp->success = true;
}

print json_encode($resp);
4

0 回答 0