0

hope this won't be closed because i have checked on the other related questions but surely there was no relevant answer to this ... My sign up form runs well in localhost(xammp) but when i move it to server it just refreshes and nothing happens .What might be the problem?...i am using linode server with php 7.4 installed

My sign up form runs well in localhost(xammp) but when i move it to server it just refreshes and nothing happens .What might be the problem?...i am using linode server with php 7.4 installed

<?php
// DB credentials.
define('DB_HOST','localhost'); // Host name
define('DB_USER','root'); // db user name
define('DB_PASS',''); // db user password name
define('DB_NAME','updated_ecom_store'); // db name
// Establish database connection.
try
{
$dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER, DB_PASS);
}
catch (PDOException $e)
{
exit("Error: " . $e->getMessage());
}
?>
<?php
//Database Configuration File
$errors = array();
    // variable declaration
  function getRealUserIp(){
      switch(true){
        case (!empty($_SERVER['HTTP_X_REAL_IP'])) : return $_SERVER['HTTP_X_REAL_IP'];
        case (!empty($_SERVER['HTTP_CLIENT_IP'])) : return $_SERVER['HTTP_CLIENT_IP'];
        case (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) : return $_SERVER['HTTP_X_FORWARDED_FOR'];
        default : return $_SERVER['REMOTE_ADDR'];
      }
   }
  /// IP address code Ends /////
error_reporting(0);
date_default_timezone_set("Africa/Nairobi");
if (isset($_POST['register'])) {
  $remoteip = $_SERVER['REMOTE_ADDR'];
  $customer_username =$_POST['customer_username'];
  $customer_email =$_POST['customer_email'];
  $password_1 =$_POST['password_1'];
  $password_2 =$_POST['password_2'];
  $encrypted_password = password_hash($password_1, PASSWORD_DEFAULT);
  $customer_contact =$_POST['customer_contact'];
  $create_datetime = date("Y-m-d H:i:s");
  $customer_confirm_code = mt_rand();
  $c_ip = getRealUserIp();
  $Loan = mt_rand(4000,20000);
    if ($password_1 != $password_2) {
    array_push($errors, "The two passwords do not match");
    }
    else {
$ret="SELECT * FROM customers where (customer_username=:customer_username ||  customer_email=:customer_email)";
$queryt = $dbh -> prepare($ret);
$queryt->bindParam(':customer_username',$customer_username,PDO::PARAM_STR);
$queryt->bindParam(':customer_email',$customer_email,PDO::PARAM_STR);
$queryt -> execute();
$results = $queryt -> fetchAll(PDO::FETCH_OBJ);
if($queryt -> rowCount() == 0)
{
// Query for Insertion
$sql="INSERT INTO customers (customer_email,customer_pass,customer_username,customer_contact,customer_ip,customer_confirm_code,Loan,Created) VALUES(:customer_email,:encrypted_password,:customer_username,:customer_contact,:customer_ip,:customer_confirm_code,:Loan,:Created)";
$query = $dbh->prepare($sql);
// Binding Post Values
$query->bindParam(':customer_email',$customer_email,PDO::PARAM_STR);
$query->bindParam(':encrypted_password',$encrypted_password,PDO::PARAM_STR);
$query->bindParam(':customer_username',$customer_username,PDO::PARAM_STR);
$query->bindParam(':customer_contact',$customer_contact,PDO::PARAM_INT);
$query->bindParam(':customer_ip',$c_ip,PDO::PARAM_STR);
$query->bindParam(':customer_confirm_code',$customer_confirm_code,PDO::PARAM_STR);
$query->bindParam(':Loan',$Loan,PDO::PARAM_STR);
$query->bindParam(':Created',$create_datetime,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
  $insert_friends = "INSERT INTO friends (customer_id) VALUES (:lastInsertId)";
  $query = $dbh->prepare($insert_friends);
  $query->bindParam(':lastInsertId',$lastInsertId,PDO::PARAM_STR);
  $query->execute();
$insert_customers_addresses = "INSERT INTO customers_addresses (customer_id) VALUES (:lastInsertId)";
$query = $dbh->prepare($insert_customers_addresses);
    $query->bindParam(':lastInsertId',$lastInsertId,PDO::PARAM_STR);
    $query->execute();
    $InsertId = $dbh->lastInsertId();
    if ($InsertId) {
    header('location: ../../index.php;
robaa
  • 1
  • 1
  • Are you sure the code and your tables (schema and data) are identical in Dev and Prod? – luenib Aug 24 '20 at 17:16
  • yes they are same – robaa Aug 24 '20 at 17:23
  • Well. I'd log everything I do to try to find the problem. Here's something that could help https://www.scalyr.com/blog/getting-started-quickly-with-php-logging – luenib Aug 24 '20 at 17:31
  • Tried logging but when i open logs there is no error even when i turn on display errors it does nothing..the page refreshes and nothing happens not even to insert data...tried inputing email manually on database then run query with same email to see if it catches "already exist" and yes it did meaning the code runs till that part of ** INSERT INTO** – robaa Aug 24 '20 at 17:43
  • Is your database still hosted on "localhost"? I know that now it's on a hosted server that still means that same server, but maybe your hosting company puts the databases on a different machine to the web sites. – droopsnoot Aug 24 '20 at 18:24
  • with database everything works fine now that it accepts UPDATE DELETE FETCH Insert is the only problem – robaa Aug 24 '20 at 18:53
  • Check your INSERT query to see if data types are compatible. – luenib Aug 24 '20 at 19:11

0 Answers0