提交角表

时间:2016-09-09 08:32:18

标签: javascript php angularjs forms

目前正在尝试构建注册表单我遇到了一个问题,注册工作正常,直到我添加代码来检查字段是否设置正确。



if( !$username12 or !$password12 or !$email or !$habbo ) {

                        echo "
<div class=\"alert alert-danger\">
  <strong>Error!!</strong> Please Try again
</div>" 

                    } else {

$db->query( "INSERT INTO `users`(`id`, `username`, `password`, `email`, `habbo`, `skype`, `location`, `displaygroup`, `usergroups`) VALUES (NULL, '{$username12}', '{$password_enc}', '{$email}', '{$habbo}', '{$skype}', '{$location}', '1', '1')");
echo "
<div class=\"alert alert-success\">
  <strong>Success!</strong> Our intern Steven recieved your request! 
</div>" 
}
?>
&#13;
&#13;
&#13; 这是我的JS文件
&#13;
&#13;
function SubmitFormRegister() {
    var username12 = $("#username12").val();
    var password12 = $("#password12").val();
    var email = $("#email").val();
    var habbo = $("#habbo").val();
    var skype = $("#skype").val();
    var location = $("#location").val();
    $.post("pages/register_submit.php", { username12: username12, password12: password12, email: email, habbo: habbo, skype: skype, location: location },
    function(data) {
	 $('#results').html(data);
	 $('#myForm')[0].reset();
    });
}
&#13;
<!-- register.php -->
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="pages/_js/register.js"></script>
</head>

            <span class="underhandle"><i class="fa fa-arrows" aria-hidden="true"></i></span>         <span class="handle"></span>
            <div class="boxhead">Register!
            </div>
<!-- Selecting Event Data -->
                         <div style="height:auto !important;">
                
 
                <form class="form-horizontal" id="myForm" method="post">
<fieldset>

<!-- Form Name -->
<br>
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="username">Username</label>  
  <div class="col-md-4">
  <input id="username12" name="username12" type="text" placeholder="Username" class="form-control input-md" required="true">
    
  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="password">Password</label>  
  <div class="col-md-4">
  <input id="password12" name="password12" type="password" placeholder="Password" class="form-control input-md" required="true">
    
  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="email">Email</label>  
  <div class="col-md-4">
  <input id="email" name="email" type="email" placeholder="Email" class="form-control input-md" required="true">
    
  </div>
</div>
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="habbo">Habbo</label>  
  <div class="col-md-4">
  <input id="habbo" name="habbo" type="text" placeholder="Habbo" class="form-control input-md" required="true">
    
  </div>
</div>
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="Skype">Skype</label>  
  <div class="col-md-4">
  <input id="skype" name="skype" type="text" placeholder="Skype" class="form-control input-md" required="false">
    
  </div>
</div>
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="location">location</label>  
  <div class="col-md-4">
      <select class="form-control input-md" id="location" name="location" placeholder="Location">
        <option>Afghanistan</option>
        <option>Albania</option>
        <option>Australia</option>
        <option>Add all these fuckers later</option>
      </select>
        </div>
</div>
<div class="form-group">
  <label class="col-md-4 control-label" for="submit"></label>
  <div class="col-md-4">
    <button  name="submit" id="submitFormData" onclick="SubmitFormRegister();" class="btn btn-success">Submit</button>
  </div>
</div>
    

</fieldset>
</form>

                </div>      


</html>
&#13;
&#13;
&#13;

这是register_submit.php的代码

<?php
require_once( "../staff/staff/_inc/glob.php" );
$password12 = $_POST['password12'];
$username12 = $_POST['username12'];
$password_enc = $core->encrypt( $password12 );
$email = $_POST['email'];
$habbo = $_POST['habbo'];
$skype = $_POST['skype'];
$location = $_POST['location'];

$query3 = $db->query( "SELECT * FROM users WHERE username = '{$username12}'" );
$array3 = $db->assoc( $query3 );

$query4 = $db->query( "SELECT * FROM users WHERE email = '{$email}'" );
$array4 = $db->assoc( $query4 );

$query5 = $db->query( "SELECT * FROM users WHERE habbo = '{$habbo}'" );
$array5 = $db->assoc( $query5 );

if( !$username12 or !$password12 or !$email or !$habbo ) {
echo "<div class=\"alert alert-danger\"><strong>Error!!</strong> Please Try again</div>" 

                } else {

$db->query( "INSERT INTO `users`(`id`, `username`, `password`, `email`, `habbo`, `skype`, `location`, `displaygroup`, `usergroups`) VALUES (NULL, '{$username12}', '{$password_enc}', '{$email}', '{$habbo}', '{$skype}', '{$location}', '1', '1')");
echo "<div class=\"alert alert-success\"><strong>Success!</strong> Message! </div>" }?>

如果我删除了If和else标签,则提交工作完全正常,但是在那里,表单将不会提交。不确定我的语法是否有问题,或者是否有其他问题。

先谢谢

2 个答案:

答案 0 :(得分:0)

我可能错了,但请尝试更换&#34;或&#34;与||

答案 1 :(得分:-1)

你没有“;”在echo语句的if块中。

为了消除由引号(“)和转义序列创建的混淆,请使用:

echo