简体   繁体   中英

page doesn't run the mysqli_stmt_execute

I have a simple create user page that goes like this:

 <div id="Add_user_admin" class="tab-content "> <h2>ADD</h2> <div class="container"> <div class="row"> <div class="col-3"></div> <div class="col-6"> <form action="includes/signup.php" method="POST"> <input type="text" name="username" placeholder="Username"> <br> <input type="password" name="pwd" placeholder="Password"> <br> <input type="text" name="email" placeholder="E-mail"> <br> <input type="text" name="status" placeholder="Status"> <br> <button type="submit" name="submit_reg"class="btn btn-primary">Submit</button> </form> </div> <div class="col-3"></div> </div> </div> </div> 

the signup.php that is called on submit goes like this:

 <?php //check if submit clicked if (isset($_POST['submit_reg'])){ include_once 'dbh.inc.php'; //gather data $user = mysqli_real_escape_string($conn, $_POST['username']); $password = mysqli_real_escape_string($conn, $_POST['pwd']); $email = mysqli_real_escape_string($conn, $_POST['email']); $status = mysqli_real_escape_string($conn, $_POST['status']); //check if empty if (empty($user) || empty($password) || empty($email) || empty($status) ){ header("Location:../admin-cms.html?signup-empty-field"); exit(); }else{ //valid e-mail if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ header ("Location:../admin-cms.html?signup-inc-email"); exit(); }else{ //user taken $sql = "SELECT * FROM users WHERE username='$user' "; $result = mysqli_query($conn, $sql); $result_check=mysqli_num_rows($result); if($result_check>0){ header ("Location:../admin-cms.html?signup-user-taken"); exit(); }else{ //hash pass $hash_pass= password_hash($password, PASSWORD_DEFAULT); //insert stmt $sql = "INSERT INTO users (username, password , status , e-mail) VALUES (?,?,?,?);"; $stmt = mysqli_stmt_init ($conn); //check conn if(!mysqli_stmt_prepare($stmt,$sql)){ echo "SQL ERROR CONNECT"; //execute }else{ mysqli_stmt_bind_param($stmt ,"ssss" , $user , $hash_pass , $status ,$email); mysqli_stmt_execute($stmt); header("Location: ../admin-cms.html?signup=succes"); exit(); } //just to check if it ran the code...it didnt header("Location: ../admin-cms.html?signup=succes_not"); exit(); } } } } else { header ("Location:../admin-cms.html?signup-no-submit"); exit(); } 

and here is the dbh.inc.php

 <?php $dbServername= "localhost"; $dbUsername= "root"; $dbPassword=""; $dbName="testcms"; $conn= mysqli_connect($dbServername,$dbUsername,$dbPassword,$dbName); 

what happens is: it runs the code all the way to the header("Location: ../admin-cms.html?signup=succes_not"); exit(); while it should come to the part where it executes the insert and then goes back to the admin-cms.html with a return : ?signup=succes

I assume the problem is within the following:
mysqli_stmt_bind_param($stmt ,"ssss" , $user , $hash_pass , $status ,$email); mysqli_stmt_execute($stmt);

However, still kind of new so I do not know why. I have spent 2 hours looking up possible problems but am unable to find anything.

I have added a screenshot of the DB for reference: 在此处输入图片说明

我犯了一个错误,那就是在数据库行的名称中放置一个“-”,这是SQL所不允许的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM