0

unable to insert values into mysql table, only showing blank page. but after commenting mysql query code it's displaying echo $success part and not throwing any error message.

code:

if(!empty($_POST)) {
// keep track validation errors
$first_nameError = null;
$last_nameError = null;
$mobile_number1Error = null; 
$addressError = null;
$magent_cityError = null;

  // collect all input and trim to remove leading and trailing whitespaces
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $mobile_number1 = $_POST['mobile_number1'];
  $mobile_number2 = $_POST['mobile_number2'];  
  $address = $_POST['address'];
  $magent_city = $_POST['magent_city'];

        // validate input
        $valid = true;
        if (empty($first_name)) {
            $first_nameError = 'Please enter First Name';
            $valid = false;
        }

        if (empty($last_name)) {
            $last_nameError = 'Please enter Last name';
            $valid = false;
                }

        if (empty($mobile_number1)) {
            $mobile_number1Error = 'Please enter Mobile Number 1';
            $valid = false;
        }

        if (empty($address)) {
            $addressError = 'Please enter Address';
            $valid = false;
                }

        if (empty($magent_city)) {
            $magent_cityError = 'Please enter City Name';
            $valid = false;
        }                

        // insert data
        if($valid){


         include 'include/db.php'; // include the library for database connection
                  $pdo = Database::connect();

                 $sql = "INSERT INTO agentreg(firstname,lastname,mobno1,mobno2,address,city) values(?, ?, ?, ?, ?, ?)";
         $q = $pdo->prepare($sql);
         $q->execute(array($first_name,$last_name,$mobile_number1,$mobile_number2,$address,$magent_city));
         Database::disconnect();
         $success = 'Successfully Inserted';
                 }
    }
2
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by blueguy777
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.