I'm adding date of birth validation to my Twilio flow. Format is mm/dd/yyyy. So user would input 01021999 for Date of Birth: 01-02-1999.
I pass the input as a parameter to my validation script (PHP) on my VPS via and http request. The problem is that if I manually set the $dob variable in my script it works, but if I pull that info from twilio there's an issue and the http request sends an error.
I know php treats numbers leading with zeros different and you have to pass them as strings. Tried using strval() to the dob variable to be able to use the input but haven't had any luck.
Works:
$account_number = 1234;
$dob = "01021999";
$dob_length = strlen($dob);
if ($dob_length = 8) {
echo $dob_month = substr($dob, 0, 2);
echo $dob_day = substr($dob, 2,2);
echo $dob_year = substr($dob, 4, 4);
echo $dob_full = $dob_month . "-" . $dob_day . "-" . $dob_year;
$sql1 = "SELECT * FROM accounts WHERE Acct_Nbr = '".$account_number."' AND Guar_DOB LIKE '%".$dob_full."%' ";
$rows = getRows($sql1);
Doesn't work (with or without turning the $dob to a string using strval() :
require_once('logs.php');
require_once('db.php');
require_once('rest.php');
$data = $_REQUEST;
start_log();
$filename = basename(__FILE__);
echo "<pre>".print_r($data,true)."</pre>";
end_log();
header("Content-Type: application/json; charset=UTF-8");
$rfields = explode(",","client_id,account_number,dob");
foreach($rfields as $rf){
if(!isset($data[$rf])){
$message = $rf." is required.";
$status = "error";
echo json_encode(compact('status','message')); die();
}
}
extract($data);
$dob_str = strval($dob);
$dob_length = strlen($dob_string);
if ($dob_length = 8) {
echo $dob_month = substr($dob_str, 0, 2);
echo $dob_day = substr($dob_str, 2,2);
echo $dob_year = substr($dob_str, 4, 4);
echo $dob_full = $dob_month . "-" . $dob_day . "-" . $dob_year;
$sql1 = "SELECT * FROM accounts WHERE Acct_Nbr = '".$account_number."' AND Guar_DOB LIKE '%".$dob_full."%' ";
$rows = getRows($sql1);
}