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 ??

        $conn=mysqli_connect($servername,$username,$password); //,$dbname);
            echo"alert('Connection Failed'.$conn->connect_error)";
                echo"<script>alert('Database not selected'); </script>".die(mysqli_error($conn));



     $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 (?,?,?,?,?,?,?,?,?);";
                    } else {  echo "this is showing";
                        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 .

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.