-1

I have some codes for account registration based on mysql database & php. but the data doesn't upload to database.The code didn't show any errors. I can't understand the problem.How can I fix thiss problem? I attached the database table image and my codes with this post. How to fix it????? Can anyone help me?????

Database table

<form class="login100-form validate-form" action="customer_register.php" method="post" enctype="multipart/form-data">
                    <span class="login100-form-title p-b-55">
                        Sign Up
                    </span>

                    <div class="avatar-wrapper">
                        <img class="profile-pic" src="" />
                        <div class="upload-button">
                        <i class="fa fa-arrow-circle-up" aria-hidden="true"></i>
                        </div>
                        <input class="file-upload" type="file" name="c_image" accept="image/*"/>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <input class="input100" type="text" name="c_name" placeholder="Your Name" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-user"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16" data-validate = "Valid email is required: ex@abc.xyz">
                        <input class="input100" type="email" name="c_email" placeholder="Your Email" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-envelope"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16" data-validate = "Password is required">
                    <input class="input100" type="password" id="psw" name="c_pass" placeholder="Enter Password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-lock"></span>
                        </span>
                    </div>

                    <div id="message">
  <h5>Password must contain the following:</h5>
  <p id="letter" class="invalid">A <b>lowercase</b> letter</p>
  <p id="capital" class="invalid">A <b>capital (uppercase)</b> letter</p>
  <p id="number" class="invalid">A <b>number</b></p>
  <p id="length" class="invalid">Minimum <b>8 characters</b></p>
</div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <select class="input100" name="c_country" style="border:none;" required>
                        <option value="" disabled selected>Select Your Country</option>
                        <option value="india">India</option>
                        </select>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-earth"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                    <select class="input100" name="c_state" style="border:none;" required>
                        <option value="" disabled selected>Select Your State</option>
                        <option value="kerala">Kerala</option>
                    </select>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-location"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                    <select class="input100" name="c_district" style="border:none;" required>
                        <option value="" disabled selected>Select Your District</option>
                        <option value="alappuzha">Alappuzha</option>
                        <option value="ernakulam">Ernakulam</option>
                        <option value="idukki">Idukki</option>
                        <option value="kannur">Kannur</option>
                        <option value="Kasaragod">Kasaragod</option>
                        <option value="kollam">Kollam</option>
                        <option value="kottayam">Kottayam</option>
                        <option value="kozhikode">Kozhikode</option>
                        <option value="malappuram">Malappuram</option>
                        <option value="palakkad">Palakkad</option>
                        <option value="pathanamthitta">Pathanamthitta</option>
                        <option value="thiruvananthapuram">Thiruvananthapuram</option>
                        <option value="thrissur">Thrissur</option>
                        <option value="wayanadu">Wayanadu</option>
                        </select>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-location"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <input class="input100" type="text" name="c_city" placeholder="Your City" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-map-marker"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <input class="input100" type="number" name="c_pincode" placeholder="Your Pincode" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-menu"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <input class="input100" type="number" name="c_contact" title="10 digits" placeholder="Your Mobile Number" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-smartphone"></span>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-16">
                        <input class="input100" type="textarea" name="c_address" placeholder="Your Address" required>
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <span class="lnr lnr-home"></span>
                        </span>
                    </div>


                    <div class="container-login100-form-btn p-t-25" >
                        <button class="login100-form-btn" type="submit" name="register">
                            Sign Up
                        </button>
                    </div>

                    <div class="text-center w-full p-t-115">
                        <span class="txt1">
                            Already have an account?
                        </span>

                        <a class="txt1 bo1 hov1" href="#">
                            Login now                           
                        </a>
                    </div>
                </form>
$con = mysqli_connect("localhost","root","","tees");

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_state = $_POST['c_state'];
    $c_district = $_POST['c_district'];
    $c_city = $_POST['c_city'];
    $c_pincode = $_POST['c_pincode'];
    $c_contact = $_POST['c_contact'];
    $c_address = $_POST['c_address'];
    $c_image = $_FILES['c_image']['name'];
    $c_image_tmp = $_FILES['c_image']['tmp_name'];

    $c_ip = getRealIpAddr();


        $insert_customer = "insert into customers (customer_name,customer_email,customer_pass,customer_country,customer_state,customer_district,customer_city,customer_pincode,customer_contact,customer_address,customer_image,customer_ip) values ('$c_name','$c_email','$c_pass','$c_country','$c_state','$c_district','$c_city','$c_pincode','$c_contact','$c_address','$c_image','$c_ip')";
        $run_customer = mysqli_query($con, $insert_customer);

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

        $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==1){

            $_SESSION['customer_email']=$c_email;

            echo "<script>alert('Account registered successfully, Thank You!')</script";
            echo "<script>window.open('checkout.php', '_self')</script>";

        } else {

            echo "<script>alert('Account registered successfully, Thank You!')</script";
            echo "<script>window.open('index.php', '_self')</script>";

        }

}
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 3
    Please learn to use prepared statements to protect against SQL injection. – Barmar Sep 18 '19 at 20:13
  • 3
    **The code doesn't show any errors** You're not checking for errors. See https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments – Barmar Sep 18 '19 at 20:15
  • 1
    I don't see where you are checking for errors. There are no else blocks to show is something is not as you expected. For example what if isset($_POST['register']) is false? What if mysqli_query is returning false? there is no error handling on your PHP or mySQLi code. – Nawed Khan Sep 18 '19 at 20:40
  • Add `echo mysqli_error ($con);` after the insert query. There should be mysql errors. Some of your table columns are `int` but you are passing a string. You should remove the single quote around the values. – Kubwimana Adrien Sep 18 '19 at 20:48

1 Answers1

-1

I would try to make some stage debugging. Start with putting some echo outputs in your php, to see where the PHP is not running.

I would start with

if(isset($_POST['register'])) {
  echo "Output 1";

to see if it ever enters that if-statement. I would also try to check the connection to the database.

Check the connection to the database with the following code

if ($con->connect_error) {
  echo "Connection failed";
} 

If your insert query is wrong, php should show a error message,starting from it ever runs this line.

davidev
  • 7,694
  • 5
  • 21
  • 56