嗨,我正在尝试将信息发送到 Sequel pro 中显示的本地 mysql 服务器。我在 html 中有一个如下所示的表单:
<a href="#openRegisterModal" id="main_header_register">register</a>
<div id="openRegisterModal" class="modalRegisterDialog">
<section>
<a href="#close" title="Close" class="close">X</a>
<h1>Register</h1>
<form name="registerform" class="registerform">
<label for="usernamefield">Username: </label>
<br>
<input type="text" id="usernameregisterfield"></input>
<br>
<label for="emailfield">Email: </label>
<br>
<input type="text" name="emailfield" id="emailregisterfield"></input>
<br>
<label for="passwordfield">Password: </label>
<br>
<input type="password" name="passwordfield" id="passwordregisterfield"></input>
<br>
<label for="passwordrepeatfield">Repeat Password: </label>
<br>
<input type="password" name="passwordrepeatfield" id="passwordrepeatregisterfield"></input>
<br>
<!--Check field-->
<br>
<input type="checkbox" name="agreementbox" id="agreementbox"></input>
<label for="agreementbox" id="termslink">I agree to the </label>
<a href="" id="termslink">terms</a>
<br>
<input type="button" id="registerbutton" value="Register" onclick="registerUser()">
</form>
</section>
</div>
当我单击注册按钮时,应该调用此 javascript 函数:
function initiate() {
}
function registerUser()
{
var username = document.getElementById("usernameregisterfield").value;
var email = document.getElementById("emailregisterfield").value;
var password = document.getElementById("passwordregisterfield").value;
console.log("Username: " + username);
console.log("Email: " + email);
console.log("Password: " + password);
if (window.XMLHttpRequest)
{
// Code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// Code for IE6, IE5
xmlhttp = ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",
"RegisterUser.php?username=" + username
+ "&email=" + email
+ "&password=" + password,
true);
xmlhttp.send();
}
initiate('load');
然后应该调用这个 php 文件:
<?php
$username = strval($_GET['username']);
$email = strval($_GET['email']);
$password = strval($_GET['password']);
$connection = mysql_connect('localhost', 'root', '')
or die("Unable to connect to database");
$database = mysql_select_db("myDatabase")
or die("Could not select database");
$sql = "INSERT INTO registered_users VALUES ('$username', '$email', '$password');";
$execute = mysql_query($sql);
?>
但是当我尝试这个时,什么也没有发生。我什至没有收到错误消息。
有人请帮助我!