The following code unable to insert null or blank value into table called custreg i.e. $sagentid and $sagentname.

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

$reg_no=$_POST['reg_no']; 
$firstname=strtoupper(str_replace(',', '' , $_POST['firstname']));
$lastname=strtoupper(str_replace(',', '' , $_POST['lastname'])); 
$mobno1=$_POST['mobno1']; 
$mobno2=$_POST['mobno2']; 
$address=strtoupper($_POST['address']); 
$city=strtoupper($_POST['city']); 
$dateofjoin=$_POST['dateofjoin']; 
$regfee=$_POST['regfee'];
$magentid=$_POST['magentid']; 
$sagentid=$_POST['sagentid']; 
$skimcity=$_POST['skimcity']; 
$skimyear=$_POST['skimyear']; 
$skimname=$_POST['skimname']; 

$cust_fullname = $firstname.' '.$lastname;

        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT id,firstname,lastname FROM agentreg where agentid= ?";
        $q = $pdo->prepare($sql);
        $q->execute(array($magentid));
        $data = $q->fetchALL(PDO::FETCH_ASSOC);

foreach($data as $row)
{               
$magentname=$row['firstname'].' '.$row['lastname'];
}

        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT id,firstname,lastname FROM agentreg where agentid= ?";
        $q = $pdo->prepare($sql);
        $q->execute(array($sagentid));
        $data = $q->fetchALL(PDO::FETCH_ASSOC);

foreach($data as $row)
{               
$sagentname=$row['firstname'].' '.$row['lastname'];
}

if($reg_no == "") {
$error= "error : Enter Card Number.";
$code= "1";
}


//check if the number field is numeric
elseif(is_numeric(trim($_POST["reg_no"])) == false ) {
$error= "error : Please enter numeric value.";
$code= "1";
}

elseif($firstname == "" ) {
$error= "error : Please enter First Name.";
$code= "2";
}

elseif($lastname == "" ) {
$error= "error : Please enter Last Name.";
$code= "3";
}

elseif($city == "" ) {
$error= "error : Please enter City.";
$code= "5";
}

elseif($mobno1 == "" ) {
$error= "error : Please enter Mobile Number 1.";
$code= "6";
}

// validate a phone number
elseif(!preg_match("/^\d{10}$/", $mobno1) ) { 
$error= "error : Please enter 10 digit Mobile Number 1";
$code= "5";
}

//check if the number field is numeric
elseif(is_numeric(trim($_POST["mobno1"])) == false ) {
$error= "error : Please enter numeric value for Mobile Number 1.";
$code= "5";
}

elseif($dateofjoin == "" ) {
$error= "error : Please select Date of Joining.";
$code= "8";
} 

elseif($magentid == "" ) {
$error= "error : Please select Main Agent.";
$code= "9";
}

else{
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO custreg (reg_no,firstname,lastname,address,city,mobno1,mobno2,dateofjoin,magentid,magentname,sagentid,sagentname,skimcity,skimyear,skimname) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $q = $pdo->prepare($sql);
            $q->execute(array($reg_no,$firstname,$lastname,$address,$city,$mobno1,$mobno2,$dateofjoin,$magentid,$magentname,$sagentid,$sagentname,$skimcity,$skimyear,$skimname));
            Database::disconnect();
$i=0;
$zerodate = '0000-00-00';
$zeroamount = '000000';
for($i=1;$i<=12;$i++)
{
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO slabpay (magentid,magentname,sagentid,sagentname,install_date,ac_no,cust_name,install_no,install_amt) values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $q = $pdo->prepare($sql);
            $q->execute(array($magentid,$magentname,$sagentid,$sagentname,$zerodate,$reg_no,$cust_fullname,$i,$zeroamount));


}
Database::disconnect();

Thanks in advance

Member Avatar for diafol

So have you tried...

 $pdo = Database::connect();
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $sql = "INSERT INTO custreg (reg_no,firstname,lastname,address,city,mobno1,mobno2,dateofjoin,magentid,magentname,sagentid,sagentname,skimcity,skimyear,skimname) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 $q = $pdo->prepare($sql);
 $q->execute(array($reg_no,$firstname,$lastname,$address,$city,$mobno1,$mobno2,$dateofjoin,$magentid,$magentname,$sagentid,$sagentname,$skimcity,$skimyear,$skimname));
 Database::disconnect();

with static values, e.g.

 $sql = "INSERT INTO custreg (reg_no,firstname,lastname,address,city,mobno1,mobno2,dateofjoin,magentid,magentname,sagentid,sagentname,skimcity,skimyear,skimname) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?)";

Remember to take out the $sagentid,$sagentname, from the execute list.
Does it still fail?

Sorry diafol for late reply, i've changed my program according to your suggestion still it's displaying blank page, it's fail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.