Code working on wamp server but not on hosted website

Here is my connection and process code. It works in localhost computer.But when hosted,insertion is not happening. WHY ??

<?php
        $servername='localhost';
        $username='Admin';
        $password="root";
        $dbname='dbname';
        //CREATE CONNECTION
        $conn=mysqli_connect($servername,$username,$password); //,$dbname);
        //CHECK SERVER CONENCTION
        if(mysqli_connect_errno($conn))
        {   
            echo"<script>";
            echo"alert('Connection Failed'.$conn->connect_error)";
            echo"</script>";
            
        }
        else 
        {   //CHECK DATABASE CONNECTION
            if(!mysqli_select_db($conn,$dbname))
            { 
                echo"<script>alert('Database not selected'); </script>".die(mysqli_error($conn));
            }
        }

?>

process.php

<?php
     $sqli="INSERT INTO tbl_user(u_fname,u_lname,u_address,u_phone1,u_phone2,u_dob,u_gender,u_usertype,u_created_at) VALUES (?,?,?,?,?,?,?,?,?);";
                    $stmt=mysqli_stmt_init($conn);
                    if(!mysqli_stmt_prepare($stmt,$sqli)){ 
                        header("location:/signup.php?err=sqlError002-ut1-u");
                        exit();
                    } else {  echo "this is showing";
                        mysqli_stmt_bind_param($stmt,"sssiissis",$fname,$lname,$address,$phone1,$phone2,$dob,$gender,$usertype,$created_at);
                        if(mysqli_stmt_execute($stmt)){  echo "this one is not showing";
                            $uid= mysqli_insert_id($conn);
                        }
                  }
?>

Well first of all, dangling braces ahoy batman.

your else and execute if statements both dangle their {.

Define your results a little better. “insertion is not happening”… are you seeing the “inserted to user” message? Is it failing to connect? Failing to prepare?

It is not showing. i just edited,you can have a look.
connection works fine
The same code works in Wamp Server. I hosted in 000webhost, there it doesnt work.

Is it correct that you’re passing phone numbers in as integers? That seems a little strange.

Presumably there’s loads of other code in your process.php that includes the connection code, and gets all those variables from somewhere?

phone numbers and everything works fine. as i said everything works in local server (wamp).
but only here its not working.

So it’s not showing ANYTHING? Then your statement has failed.
mysqli_stmt_execute returned false.
So find out why.

else { echo mysqli_error($conn); }

EDIT: Forgot the conn object.

1 Like

It is standard practise for PHP to have error_reporting and display errors automatically set to true when developing on your localhost and false on the live site.

It is usually possible on the live site to temporarily override the settings while debugging.

Also, if available, check the error log file.

1 Like

It was an error in the database. the default value was set to none instead of null unknowingly. Thanks for the support .