Database Connectivity and phpMyAdmin issue

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?

@kumarsinha said:
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:

`



Full Name




PUBG Mobile Username




Email Address




Mobile Number


How do you want to be notified for ROOM ID & Password?

Email-ID

Mobile(Whatsapp)

Mobile(SMS)



    <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">
`

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?

Hi,
You might have a code that does not work or compatible with the free hosting servers.

@UnknownLolz You have the code right in front of you. Which part isn’t compatible?

@kumarsinha said:
@UnknownLolz You have the code right in front of you. Which part isn’t compatible?

Hi,
I can’t actually tell… Sorry, but I’m not an expert with PHP.

Only thing that I could say is that the server can’t handle your code or some of the lines of your code is broken.

I have got the error message:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘epiz_22560462’@‘192.168.0.38’ (using password: YES) in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php on line 20

Fatal error: Uncaught Error: Call to undefined function mysqli_connect_errorno() in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php:23 Stack trace: #0 {main} thrown in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php on line 23

@kumarsinha said:
I have got the error message:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘epiz_22560462’@‘192.168.0.38’ (using password: YES) in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php on line 20

Fatal error: Uncaught Error: Call to undefined function mysqli_connect_errorno() in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php:23 Stack trace: #0 {main} thrown in /home/vol14_1/epizy.com/epiz_22560462/htdocs/pages/insert.php on line 23

Are you sure of the Server Host information you put?
The MySQL server address is:
sql110.epizy.com

Please make sure all information are correct!

@UnknownLolz I have put the dbhost as sql304.epizy.com. This is what it shows in my cpanel.

  1. I think it’s called mysqli_connect_errno(). CMIIW
  2. Try double check your db username and password
  3. try $stmt = $conn->stmt_init(); at the very beginning of $stmt (initialization) variable, who knows it might be work

@kumarsinha said:
@UnknownLolz I have put the dbhost as sql304.epizy.com. This is what it shows in my cpanel.

I checked your code and the page and the database connection looks OK. When I tried the form, I saw different error messages (most of them caused by variables in the code without the $ prefix).