PHP代码提交按钮仅刷新页面

时间:2016-08-21 20:52:25

标签: php html mysql

我正在使用PHP和SQL服务器,在我进一步解释之前,数据库连接是用 <?php session_start(); $message = ""; require 'databaseconnect.php'; if($_POST['register']): if(!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['confirmPassword']) && !empty($_POST['pin']) && !empty($_POST['preferredName'])): if($_POST['password'] == $_POST['confirmPassword']): $sql = "INSERT INTO Users (Email, Password, FirstName, LastName, Type) VALUES (:email, :password, :firstname, :lastname, :type)"; If($_POST['pin'] == "123456"): $stmt = $conn->prepare($sql); $stmt->bindParam(':email', $_POST['email']); $stmt->bindParam(':password', md5($_POST['password'])); $stmt->bindParam(':firstname', $_POST['firstname']); $stmt->bindParam(':lastname', $_POST['firstname']); $stmt->bindParam(':type', $_POST['AcctType']); if( $stmt->execute() ): $message = ('<div class="inputlogin alert alert-success" role="alert"><b>You are Registered!</b> You have been registered as a member! <a href = portal.php>Log In!</a></div>'); else: $message = ('<div class="inputlogin alert alert-danger" role="alert"><b>There has been an issue...</b> While attempting to register you, there was an error with the server,try again later.</a></div>'); endif; else: $message = ('<div class="inputlogin alert alert-danger alert-dissmissable" role="alert"><b>Oops!</b> Authentication pin not recognized!</div>'); endif; else: $message = ('<div class="inputlogin alert alert-danger alert-dissmissable" role="alert"><b>Uh Oh!</b> Passwords Do not Match!</div>'); endif; endif; endif; $conn = null; ?> <html> <head> </head> <body> <div class = "container_main"> <a name="top"></a> <br><br> <div class = "mainHeader"> <i class = "fa fa-bars fa-2x mobile_menu" height="100px" widht="100px"></i> </div> <div class = "containerDEF"> <center><img class = "fixed loginImg" src = "CSS/images/TroopLogo.png" alt = "DesignLogo" width = "300" height="300px"></center> <form action = "register.php" method ="POST"> <div class="input-group inputLogIn" id = "FirstName"> <span class="input-group-addon" id="basic-addon1">First Name:</span> <input type="text" class="form-control" placeholder="ex. Clara" aria-describedby="basic-addon1" name="firstname"> </div> <div class="input-group inputLogIn" id = "LastName"> <span class="input-group-addon" id="basic-addon1">Last Name:</span> <input type="text" class="form-control" placeholder="ex. Oswald" aria-describedby="basic-addon1" name="lastname"> </div> <div class="input-group inputLogIn" id = "Email"> <span class="input-group-addon" id="basic-addon1">Email:</span> <input type="text" class="form-control" placeholder="ex. cOswald@kyzlet.net" aria-describedby="basic-addon1" name="email"> </div> <div class="input-group inputLogIn" id = "ConfirmEmail"> <span class="input-group-addon" id="basic-addon1">Confirm Email:</span> <input type="text" class="form-control" placeholder="ex. cOswald@kyzlet.net" aria-describedby="basic-addon1" name="confirmemail"> </div> <div class="input-group inputLogin" id = "Pass"> <span class="input-group-addon" id="basic-addon1">Password:</span> <input type="password" class="form-control" placeholder="ex. RunYouCleverBoy" aria-describedby="basic-addon1" name="password"> </div> <div class="input-group inputLogin" id = "ConfirmPass"> <span class="input-group-addon" id="basic-addon1">Confirm Password:</span> <input type="password" class="form-control" placeholder="ex. RunYouCleverBoy" aria-describedby="basic-addon1" name="confirmpassword"> </div> <div class="input-group inputLogin" id = "RegistrationPin"> <span class="input-group-addon" id="basic-addon1">Registration Pin:</span> <input type="password" class="form-control" placeholder="******" aria-describedby="basic-addon1" name="pin"> </div> <div class="input-group inputLogin" id = "RegistrationPin"> <span class="input-group-addon" id="basic-addon1">Account Type:</span> <select type = "select" name="AcctType" class = "form-control" > <option value="Scout">Scout</option> <option value="Parent">Parent</option> <option value="Leader">Leader</option> </select> </div> <?php if (!empty($message)): echo ($message); endif; ?> <center><input type = "submit" class = "submitButton" name = "register" value = "Register"></center> </form> <center><p>Just want to login? <a href = "portal.php" class = "lightLink" >Login Here</a>. </p> </center> </div> <br><br> <a href = "#top"><i class = "fa fa-arrow-up up_button fa-2x"></i></a> </div> </div> </div> <script src = "Scripts/Script_Main.js"></script> </body> </html> 实现的。代码用于注册用户。目前,运行代码只刷新页面,花了几个小时尝试进行故障排除后,我仍然无法找到错误。任何帮助将非常感激。我不知道我是否正确编程,所以这也可能是问题的根源。我的代码如下:

IEnemy[] Enemy = new IEnemy[2];
Enemy Goblin = new Enemy("Goblins", "Looks dirty and not so friendly", 100);
Enemy[0] = Goblin;

1 个答案:

答案 0 :(得分:0)

$_POST['register']是否真的回归?我相信你需要这样设置:

if(isset($_POST['register')){
 //do your thing
}

首先应该是这种情况,以防止出现任何警告,因为首次加载时不会存在$_POST['register']

此外,您没有这个可能意味着您关闭了错误和警告? 要试一试,请将ini_set('error_reporting', E_ALL);放在脚本之上。如果您有任何错误,这应该说清楚。

另外,请确保在if语句中回显一些内容!您不知道该页面是否只是刷新,因为如果在数据库代码中出现问题,可能永远不会设置$message

希望这有帮助!

另外,我注意到你的表单操作设置为静态页面(将其保留为空将自动使用当前页面) - 当我是初学者时,我有时会犯一个使用新文件来测试某些内容的错误,只是忘了改变动作网址。这有时导致我加载旧的(备份)文件而不是新的测试功能。只是说。