I am trying to insert data from a form to mySQL DB, no connection error, but no data is inserted into my database. Any idea? Here's my HTML form:
<div class="tab-pane" id="Registration">
<b><em>Listen to the voice of Soul</em></b>
<form class="form" role="form" method="POST" action="signup.php" accept-charset="UTF-8"id="signup-nav">
<div class="form-group">
<label class="sr-only" for="email2">Email address</label>
<input type="email" class="form-control"id="email2" name="signup_email" placeholder="Email address" required>
</div>
<div class="form-group">
<label class="sr-only" for="password2">Password</label>
<input type="password" class="form-control" id="pwd2" name="signup_pwd" placeholder="Password" required>
</div>
<div class="form-group">
<label class="sr-only" for="password3">Confirm Password</label>
<input type="password" class="form-control" id="pwdcon" name="signup_pwdcon" placeholder="Confirm Password" required>
</div>
<div class="form-group">
<input type="submit" name="signUpBtn" value="Sign Up" class="btn btn-primary btn-block"></button>
</div>
</form>
</div>
My database name is coldplay, table is userdata and im using local host with ID=root, no password
PHP:
<?php
include ("dbh.php");
if(isset($_POST["signUpBtn"])){
$signup_email = $_POST ['signup_email'];
$signup_pwd = $_POST ['signup_pwd'];
$signup_pwdcon = $_POST ['signup_pwdcon'];
$sql_signup = "insert into userdata (email, pwd, pwdcon)
values ('$signup_email', '$signup_pwd', '$signup_pwdcon')";
mysqli_query($conn, $sql_signup);
mysqli_close($conn);
header("Location: testing.html");
}
?>
PHP database handler:
<? php
$conn = mysqli_connect("localhost", "root", "", "coldplay");
if (!$conn){
die("Connection failed: ".mysqli_connect_error());
}
?>
Please first read about password hashing and how to bind parameters to prepared statements in mysqli. Your script is vulnerable to sql injection if you leave it like this.
There is a problem in your dbh.php file with the opening php tag. It should read <?php
insteat of <? php
(notice the space).
If that was not the problem you should check the result of your mysqli_query
method like this:
if (!mysqli_query($conn, $sql_signup)) {
echo "Error: " . mysqli_error($conn);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments