好吧,我不得不改變我的問題,我的JavaScript代碼不能進入下一步isset ['submit']它只是卡在那裏。即時通訊真的希望在這裏有人可以幫助我正確的我的JavaScript代碼,以便它將成功調用isset並運行我的PHP代碼將其添加到數據庫。JavaScript驗證無法插入數據庫
我的PHP代碼
if(isset($_POST['submit'])){
$firstname = mysql_escape_string($_POST['fname']);
$lastname = mysql_escape_string($_POST['lname']);
$age = mysql_escape_string($_POST['age']);
$gender = mysql_escape_string($_POST['gender']);
$email = mysql_escape_string($_POST['email']);
$password = mysql_escape_string($_POST['password']);
$nickname = mysql_escape_string($_POST['nickname']);
$regflag = 0;
$sql = "SELECT * FROM accounts";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query))
{
if($row['email'] == $email)
{
echo '<b> The email is already taken!</b>';
$regflag = 0;
}
if($row['nickname'] == $nickname)
{
echo ' <b>The nickname is already taken!</b>';
$regflag = 0;
}
}
if($regflag == 1)
{
$regsql = "INSERT INTO accounts VALUES('','$firstname','$lastname','$age','$gender','$email','$password','$nickname','MEMBER',now())";
$query = mysql_query($regsql);
echo '<body onLoad = "regsucess()"> </body>';
}
}
我的javascript代碼
<script type = "text/javascript">
function validator(){
if(!document.register.fname.value)
{
alert('You need to supply your first name.');
document.register.fname.focus();
return false;
}
if(!document.register.lname.value)
{
alert('You need to supply your last name.');
document.register.lname.focus();
return false;
}
if(!document.register.age.value)
{
alert('You need to supply your age.');
document.register.age.focus();
return false;
}
if(!document.register.email.value)
{
alert('You need to supply your email.');
document.register.email.focus();
return false;
}
if(!document.register.password.value)
{
alert('You need to supply your password.');
document.register.password.focus();
return false;
}
if(!document.register.nickname.value)
{
alert('You need to supply your nickname.');
document.register.nickname.focus();
return false;
}
register.action = "register.php"
document.register.submit();
//alert("Congrats!");
}
提供您正在使用的html代碼... – 2012-03-30 16:59:57
使用Web控制檯在Firefox中運行它。它給了什麼錯誤? – qitch 2012-03-30 17:01:43
另外,你的數據庫連接在哪裏?你應該使用'mysql_real_escape_string',除非你使用4.3以下版本的mysql? 'mysql_escape_string'已被棄用。當然,大多數人會告訴你使用準備好的陳述,這些陳述更好用。 – qitch 2012-03-30 17:06:19