I have hosted my website on infinityfree.com and I am trying to build a registration forms which stores its data in a database. I am new to PHP so I am having difficulties in debugging this.
I have built my database and table in phpmyadmin, provided by infinityfree.
This is my php code:
<?php
$name = $_POST['name'];
$userid = $_POST['userid'];
$email = $_POST['email'];
$mno = $_POST['mno'];
$rcheck = $_POST['rcheck'];
if(!empty($name) || !empty($userid) || !empty($email) || !empty($mno) || !empty($rcheck)){
$host = "*******";
$dbusername = "*******";
$dbpassword = "******";
$dbname = "*******";
//creating connection
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
if(mysqli_connect_error()){
die('Connect Error('. mysqli_connect_errorno().')'. mysqli_connect_error());
}
else{
$SELECT = "SELECT email from registrations where email = ? limit 1";
$INSERT = "INSERT into registrations (name, userid, email, mno, rcheck) values(?,?,?,?,?)";
//prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if(rnum==0){
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sssis", $name, $userid, $email, $mno, $rcheck);
$stmt->execute();
echo "You have been registered successfully";
}
else{
echo "Someone already registered using this email";
}
$stmt->close();
$conn->close();
}
}
else{
echo "All fields are required";
die();
?>`
And this is my form code:
`<form action="insert.php" method="post">
<!-- Name -->
<div class="form-group">
<input name="name" type="text" id="name-login-1" class="form-control" placeholder="Enter your name" required>
<label for="name-login-1">Full Name</label>
</div>
<!-- Username -->
<div class="form-group">
<input name ="userid" type="text" class="form-control" placeholder="Enter your name" required>
<label for="username-login-1">PUBG Mobile Username</label>
</div>
<!-- EMAIL -->
<div class="form-group">
<input name="email" type="email" class="form-control" placeholder="Enter your email-id" required>
<label for="email-login-1">Email Address</label>
</div>
<!-- Mobile Numer -->
<div class="form-group">
<input name="mno" type="text" class="form-control" placeholder="Enter your mobile number" required>
<label for="mno-login-1">Mobile Number</label>
</div>
<div class="form-group">
<label class="checkbox-inline"> How do you want to be notified for ROOM ID & Password? <br>
<input name="rcheck" type="checkbox" value="e"> Email-ID <br>
<input name="rcheck" type="checkbox" value="w"> Mobile(Whatsapp)<br>
<input name="rcheck" type="checkbox" value="s"> Mobile(SMS)<br>
</label>
</div>
<div class="form-group">
<label> By clicking Pay & Register, you agree to our <a href="instruction.html"> Terms & Conditions </a>
</label>
</div>
<!-- Submit -->
<input type="submit" value="PAY & Register" class="btn">
</form>
The form is on the following link: http://crunched.ml/pages/register_sce.html
Whenever I input data in the form, and click on the submit button, I receive the error: “This page isn’t working. crunched.ml is unable to handle this request. HTTP Error 500.”
Also, when I open my index.php file directly using the link: http://crunched.ml/pages/insert.php, I see the message “All fields are required.” Which means, the php is working, but is not working with the submit button, I think.
How do I proceed forward to remove this error and make this work so that I am able to store data from the registration form to my database?