-1

I can't insert the registration form data into my localhost database.

I am using xampp server, running mysql 5, php 7 and apache2. I've provided the code that can insert the form data into the database. The database is connected. I have also restarted the xampp server but it shows the same problem.

<?php 

    $active='Account';
    include("includes/header.php");

?>
 //html form with correct name values
<?php 

if(isset($_POST['register'])){

    $c_name = $_POST['c_name'];

    $c_email = $_POST['c_email'];

    $c_pass = $_POST['c_pass'];

    $c_country = $_POST['c_country'];

    $c_city = $_POST['c_city'];

    $c_contact = $_POST['c_contact'];

    $c_address = $_POST['c_address'];

    $c_image = $_FILES['c_image']['name'];

    $c_image_tmp = $_FILES['c_image']['tmp_name'];

    move_uploaded_file($c_image_tmp,"customer/customer_images/$c_image");

    $insert_customer = "insert into customers (customer_name,customer_email,customer_pass,customer_country,customer_city,customer_contact,customer_address,customer_image,customer_ip) values ('$c_name','$c_email','$c_pass','$c_country','$c_city','$c_contact','$c_address','$c_image','$c_ip')";

    $result = mysqli_query($con,$insert_customer);

    $sel_cart = "select * from cart where ip_add='$c_ip'";

    $run_cart = mysqli_query($con,$sel_cart);

    $check_cart = mysqli_num_rows($run_cart);

    if($check_cart>0){

        $_SESSION['customer_email']=$c_email;

        echo "<script>alert('User is already present');</script>";

        echo "<script>window.open('checkout.php','_self')</script>";

    }else{  

        $_SESSION['customer_email']=$c_email;

        echo "<script>alert('You have been Registered Sucessfully')</script>";

        echo "<script>window.open('index.php','_self')</script>";

    }

}

?>

The data should be inserted into the db when I refresh the phpmyadmin page.

  • You are wide open for SQL injection. Since you're using mysqli, take advantage of [prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [bind_param](http://php.net/manual/en/mysqli-stmt.bind-param.php). **This will take care of any pesky quoting issues that may occur.** – aynber Nov 11 '19 at 15:43
  • When a query does not work as you expect, you need to explicitly check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) to find out why. – aynber Nov 11 '19 at 15:44
  • why is this tagged as "ajax"? – Funk Forty Niner Nov 11 '19 at 15:45
  • Where is the HTML for this? – Funk Forty Niner Nov 11 '19 at 15:46

1 Answers1

-1

Check $con variable where you define. Connection variable should be define on page and call with mysqli function.

$result = mysqli_query($con,$insert_customer);