Error: SQLSTATE[HY093] sending data through HTML/PHP to MySQL - php

I'm trying to send a lot of data from a form to a mysql database, and I'm getting the following error:
Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
I know the error is likely related to the amount of fields I'm sending not matching the number of parameters in the query.
Code below:
$stmt = $conn->prepare("INSERT INTO propuestas_emitidas (fecha_operacion, vendedor_codigo, vendedor_nombre, vigencia, plan, persona_tipo, IVA_cond, auto_marca, auto_modelo, auto_anofab, auto_cerokm, auto_suma, auto_uso, auto_rastreo, auto_cp, auto_tarifa, acc1_cod, acc1_desc, acc1_valor, acc2_cod, acc2_desc, acc2_valor, acc3_cod, acc3_desc, acc3_valor, acc4_cod, acc4_desc, acc4_valor, cobertura_tipo, electronica, tit_tipo_persona, tit_tipodoc, tit_nrodoc, tit_apellido, tit_provincia, tit_localidad, tit_calle, tit_altura, tit_piso, tit_dpto, tit_cp, tit_tel1, tit_tel2, tit_sexo, tit_est_civil, tit_nacionalidad, tit_actividad, tit_cuit, tit_mail, tit_prov_nac, tit_loc_nac, tit_fecha_nac, rep_tipodoc, rep_nrodoc, rep_apellido, rep_nombre, vh_patente, vh_chasis, vh_motor, pago_forma, pago_cuotacero, pago_cbu, pago_tarj_nombre, pago_tarj_nro, pago_tarj_vcto, pago_tarj_titular)
VALUES (:fecha_operacion, :vendedor_codigo, :vendedor_nombre, :vigencia, :plan, :persona_tipo, :IVA_cond, :auto_marca, :auto_modelo, :auto_anofab, :auto_cerokm, :auto_suma, :auto_uso, :auto_rastreo, :auto_cp, :auto_tarifa, :acc1_cod, :acc1_desc, :acc1_valor, :acc2_cod, :acc2_desc, :acc2_valor, :acc3_cod, :acc3_desc, :acc3_valor, :acc4_cod, :acc4_desc, :acc4_valor, :cobertura_tipo, :electronica, :tit_tipo_persona, :tit_tipodoc, :tit_nrodoc, :tit_apellido, :tit_provincia, :tit_localidad, :tit_calle, :tit_altura, :tit_piso, :tit_dpto, :tit_cp, :tit_tel1, :tit_tel2, :tit_sexo, :tit_est_civil, :tit_nacionalidad, :tit_actividad, :tit_cuit, :tit_mail, :tit_prov_nac, :tit_loc_nac, :tit_fecha_nac, :rep_tipodoc, :rep_nrodoc, :rep_apellido, :rep_nombre, :vh_patente, :vh_chasis, :vh_motor, :pago_forma, :pago_cuotacero, :pago_cbu, :pago_tarj_nombre, :pago_tarj_nro, :pago_tarj_vcto, :pago_tarj_titular)");
$fecha_operacion = str_replace("/", "", date("d/m/y"));
$vendedor_codigo = $_POST["vendedor_codigo"];
$vendedor_nombre = $_POST["vendedor_nombre"];
$vigencia = $_POST["vigencia"];
$plan = $_POST["plan"];
$persona_tipo = "F";
$IVA_cond = $_POST["IVA_cond"];
$auto_marca = $_POST["auto_marca"];
$auto_modelo = $_POST["auto_modelo"];
$auto_anofab = $_POST["auto_anofab"];
$auto_cerokm = $_POST["auto_cerokm"];
$auto_suma = NULL;
$auto_uso = $_POST["auto_uso"];
$auto_rastreo = $_POST["auto_rastreo"];
$auto_cp = $_POST["auto_cp"];
$auto_tarifa = $_POST["auto_tarifa"];
if (!(isset($_POST["acc1_cod"]))) {
$acc1_cod = NULL;
$acc1_desc = NULL;
$acc1_valor = NULL;
} else {
$acc1_cod = $_POST["acc1_cod"];
$acc1_desc = $_POST["acc1_desc"];
$acc1_valor = $_POST["acc1_valor"];
}
if (!(isset($_POST["acc2_cod"]))) {
$acc2_cod = NULL;
$acc2_desc = NULL;
$acc2_valor = NULL;
} else {
$acc2_cod = $_POST["acc2_cod"];
$acc2_desc = $_POST["acc2_desc"];
$acc2_valor = $_POST["acc2_valor"];
}
if (!(isset($_POST["acc3_cod"]))) {
$acc3_cod = NULL;
$acc3_desc = NULL;
$acc3_valor = NULL;
} else {
$acc3_cod = $_POST["acc3_cod"];
$acc3_desc = $_POST["acc3_desc"];
$acc3_valor = $_POST["acc3_valor"];
}
if (!(isset($_POST["acc4_cod"]))) {
$acc4_cod = NULL;
$acc4_desc = NULL;
$acc4_valor = NULL;
} else {
$acc4_cod = $_POST["acc4_cod"];
$acc4_desc = $_POST["acc4_desc"];
$acc4_valor = $_POST["acc4_valor"];
}
$cobertura_tipo = NULL;
$electronica = NULL;
$tit_tipo_persona = "F";
$tit_tipodoc = $_POST["tit_tipodoc"];
$tit_nrodoc = $_POST["tit_nrodoc"];
$tit_apellido = $_POST["tit_apellido"];
$tit_provincia = $_POST["tit_provincia"];
$tit_localidad = $_POST["tit_localidad"];
$tit_calle = $_POST["tit_calle"];
$tit_altura = $_POST["tit_altura"];
$tit_piso = $_POST["tit_piso"];
$tit_dpto = $_POST["tit_dpto"];
$tit_cp = $_POST["tit_cp"];
$tit_tel1 = $_POST["tit_tel1"];
$tit_tel2 = $_POST["tit_tel2"];
$tit_sexo = $_POST["tit_sexo"];
$tit_est_civil = $_POST["tit_est_civil"];
$tit_nacionalidad = $_POST["tit_nacionalidad"];
$tit_actividad = NULL;
$tit_cuit = $_POST["tit_nrodoc"];
$tit_mail = $_POST["tit_mail"];
$tit_prov_nac = $_POST["tit_prov_nac"];
$tit_loc_nac = $_POST["tit_loc_nac"];
$tit_fecha_nac = $_POST["tit_fecha_nac"];
$rep_tipodoc = $_POST["tit_tipodoc"];
$rep_nrodoc = $_POST["tit_nrodoc"];
$rep_apellido = $_POST["tit_apellido"];
$rep_nombre = $_POST["tit_apellido"];
$vh_patente = NULL;
$vh_chasis = NULL;
$vh_motor = NULL;
$pago_forma = "CBU";
$pago_cuotacero = $_POST["pago_cuotacero"];
$pago_cbu = $_POST["pago_cbu"];
$pago_tarj_nombre = NULL;
$pago_tarj_nro = NULL;
$pago_tarj_vcto = NULL;
$pago_tarj_titular = NULL;
$stmt->bindParam(':fecha_operacion', $fecha_operacion);
$stmt->bindParam(':vendedor_codigo', $vendedor_codigo);
$stmt->bindParam(':vendedor_nombre', $vendedor_nombre);
$stmt->bindParam(':vigencia', $vigencia);
$stmt->bindParam(':plan', $plan);
$stmt->bindParam(':persona_tipo', $persona_tipo);
$stmt->bindParam(':IVA_cond', $IVA_cond);
$stmt->bindParam(':auto_marca', $auto_marca);
$stmt->bindParam(':auto_modelo', $auto_modelo);
$stmt->bindParam(':auto_anofab', $auto_anofab);
$stmt->bindParam(':auto_cerokm', $auto_cerokm);
$stmt->bindParam(':auto_suma', $auto_suma);
$stmt->bindParam(':auto_uso', $auto_uso);
$stmt->bindParam(':auto_rastreo', $auto_rastreo);
$stmt->bindParam(':auto_cp', $auto_cp);
$stmt->bindParam(':auto_tarifa', $auto_tarifa);
$stmt->bindParam(':acc1_cod', $acc1_cod);
$stmt->bindParam(':acc1_desc', $acc1_desc);
$stmt->bindParam(':acc1_valor', $acc1_valor);
$stmt->bindParam(':acc2_cod', $acc2_cod);
$stmt->bindParam(':acc2_desc', $acc2_desc);
$stmt->bindParam(':acc2_valor', $acc2_valor);
$stmt->bindParam(':acc3_cod', $acc3_cod);
$stmt->bindParam(':acc3_desc', $acc3_desc);
$stmt->bindParam(':acc3_valor', $acc3_valor);
$stmt->bindParam(':acc4_cod', $acc4_cod);
$stmt->bindParam(':acc4_desc', $acc4_desc);
$stmt->bindParam(':acc4_valor', $acc4_valor);
$stmt->bindParam(':cobertura_tipo', $cobertura_tipo);
$stmt->bindParam(':electronica', $electronica);
$stmt->bindParam(':tit_tipo_persona', $tit_tipo_persona);
$stmt->bindParam(':tit_tipodoc', $tit_tipodoc);
$stmt->bindParam(':tit_nrodoc', $tit_nrodoc);
$stmt->bindParam(':tit_apellido', $tit_apellido);
$stmt->bindParam(':tit_provincia', $tit_provincia);
$stmt->bindParam(':tit_localidad', $tit_localidad);
$stmt->bindParam(':tit_calle', $tit_calle);
$stmt->bindParam(':tit_altura', $tit_altura);
$stmt->bindParam(':tit_piso', $tit_piso);
$stmt->bindParam(':tit_dpto', $tit_dpto);
$stmt->bindParam(':tit_cp', $tit_cp);
$stmt->bindParam(':tit_tel1', $tit_tel1);
$stmt->bindParam(':tit_tel2', $tit_tel2);
$stmt->bindParam(':tit_sexo', $tit_sexo);
$stmt->bindParam(':tit_est_civil', $tit_est_civil);
$stmt->bindParam(':tit_nacionalidad', $tit_nacionalidad);
$stmt->bindParam(':tit_actividad', $tit_actividad);
$stmt->bindParam(':tit_cuit', $tit_cuit);
$stmt->bindParam(':tit_mail', $tit_mail);
$stmt->bindParam(':tit_prov_nac', $tit_prov_nac);
$stmt->bindParam(':tit_loc_nac', $tit_loc_nac);
$stmt->bindParam(':tit_fecha_nac', $tit_fecha_nac);
$stmt->bindParam(':rep_tipodoc', $rep_tipodoc);
$stmt->bindParam(':rep_apellido', $rep_apellido);
$stmt->bindParam(':rep_nombre', $rep_nombre);
$stmt->bindParam(':vh_patente', $vh_patente);
$stmt->bindParam(':vh_chasis', $vh_chasis);
$stmt->bindParam(':vh_motor', $vh_motor);
$stmt->bindParam(':pago_forma', $pago_forma);
$stmt->bindParam(':pago_cuotacero', $pago_cuotacero);
$stmt->bindParam(':pago_cbu', $pago_cbu);
$stmt->bindParam(':pago_tarj_nombre', $pago_tarj_nombre);
$stmt->bindParam(':pago_tarj_nro', $pago_tarj_nro);
$stmt->bindParam(':pago_tarj_vcto', $pago_tarj_vcto);
$stmt->bindParam(':pago_tarj_titular', $pago_tarj_titular);
$stmt->execute();
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;

You missed
$stmt->bindParam(':rep_nrodoc', $rep_nrodoc);

Related

Using an If statement in PHP but not working

What I want to do is When I enter all my information (for client ID 199 in the picture) In my account being submit it, it goes into the database. BUT I want it to change to something and so i added an if statement
Here the code im adding to the existing code already at the BOTTOM of the code
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
if the ($vpr_clid = 199)
i want the clname to be "Shelley Madsen And Associates" then what is show in the table below instead of "Nice and White Smiles" (that an example of the results look like)
but when i chcek the database it not changing it and still show "Nice and White Smiles :(
I dont see any error, so it might be the placement of the code i have to put the IF statement in the huge php file? Dont know how to fix this issue
Thanks (the code below is the base code before i added the If statement)
I also insert the if statement before the function were called but still didnt work example
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
<?php
session_start();
if ($_SESSION['company'] != "ACB") {
// redirect to the logout page
$redirect = 'logout.php';
include './includes/redirect.php';
}
class variables_obj {
var $vpr_plan = '';
var $vpr_id = '';
var $vpr_clid = '';
var $vpr_cl_name = '';
var $vpr_cl_phone = '';
var $vpr_call_start_date = '';
var $vpr_db_account = '';
var $vpr_db_fname = '';
var $vpr_db_mname = '';
var $vpr_db_lname = '';
var $vpr_rp_fname = '';
var $vpr_rp_mname = '';
var $vpr_rp_lname = '';
var $vpr_rp_address = '';
var $vpr_rp_city = '';
var $vpr_rp_state = '';
var $vpr_rp_zipcode = '';
var $vpr_rp_phonenum = '';
var $vpr_rp_phonetype = '';
var $vpr_date_entered = '';
var $newrecdt = '';
var $vpl_day_offset = '';
var $vpl_action = '';
var $vpr_promocode = '';
}
function ScrubPhone($old_phone_num) {
$phone_length = strlen($old_phone_num);
$new_phone_num = "";
for($i = 0; $i < $phone_length; $i = $i + 1) {
if(is_numeric($old_phone_num[$i])) {
$new_phone_num .= $old_phone_num[$i];
}
}
return $new_phone_num;
}
function ScheduleCreated($link, $vars) {
$query = "UPDATE v_payreminder SET vpr_schedule_created = '1' WHERE vpr_id='".$vars->vpr_id."'";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateScheduleRow($link, $vars){
// echo "vpl_day_offset: ".$vars->vpl_day_offset."<br>";
// echo "vpl_action: ".$vars->vpl_action."<br>";
$plus_days = " +".$vars->vpl_day_offset." days";
// echo "plus days: ".$plus_days."<br>";
$date_offset = strtotime(date("Y-m-d", strtotime($vars->vpr_date_entered)).$plus_days);
$date_offset = date("Y-m-d", $date_offset);
// echo "date_offset: ".$date_offset."<br>";
// $date_offset = strtotime(date("Y-m-d",strtotime($vars->vpr_date_entered))." +".$vars->vpl_day_offset." days");
// $date_offset = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
// echo "date_offset: ".$date_offset."<br>";
$query = "INSERT INTO v_pr_schedule (
vpr_id,
vsc_plan,
vsc_date_entered,
vsc_action,
vsc_action_date,
vsc_status
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'$vars->vpl_action',
'$date_offset',
'VACT')";
//echo "query: ".$query."<br>";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateSchedule($link, &$vars) {
// CREATE SCHEDULE
$query = " SELECT vpl_day_offset, vpl_action, vpl_condition
FROM v_plan
WHERE vpl_plan = '".$vars->vpr_plan."'";
// echo "query: ".$query."<br>";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
while ($row = mysql_fetch_array($qresult, MYSQL_ASSOC)) {
$vars->vpl_day_offset = $row['vpl_day_offset'];
$vars->vpl_action = $row['vpl_action'];
if ($row['vpl_condition'] == 'OO') {
CreateScheduleRow($link, $vars);
}
}
}
return true;
}
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
//echo "Client Name: ".$vars->vpr_cl_name."<br><br>";
//exit();
$sql="INSERT INTO v_payreminder (
vpr_clid,
vpr_cl_name,
vpr_cl_phone,
vpr_call_start_date,
vpr_db_account,
vpr_db_fname,
vpr_db_mname,
vpr_db_lname,
vpr_rp_fname,
vpr_rp_mname,
vpr_rp_lname,
vpr_rp_phonenum,
vpr_rp_phonetype,
vpr_rp_address,
vpr_rp_city,
vpr_rp_state,
vpr_rp_zipcode,
vpr_promo,
vpr_date_entered) VALUES (
'$vars->vpr_clid',
'$vars->vpr_cl_name',
'$vars->vpr_cl_phone',
'$vars->vpr_call_start_date',
'$vars->vpr_db_account',
'$vars->vpr_db_fname',
'$vars->vpr_db_mname',
'$vars->vpr_db_lname',
'$vars->vpr_rp_fname',
'$vars->vpr_rp_mname',
'$vars->vpr_rp_lname',
'$vars->vpr_rp_phonenum',
'$vars->vpr_rp_phonetype',
'$vars->vpr_rp_address',
'$vars->vpr_rp_city',
'$vars->vpr_rp_state',
'$vars->vpr_rp_zipcode',
'$vars->vpr_promocode',
'$vars->vpr_date_entered')";
if (!mysql_query($sql,$link)) {
die('Error2: ' . mysql_error());
}
return true;
}
function GetVpr_Id($link, &$vars) {
// Find out what vpr_id is
$query = "SELECT vpr_id FROM v_payreminder ";
$query .= "WHERE vpr_clid = '".$vars->vpr_clid."' AND vpr_date_entered = '".$vars->vpr_date_entered."'";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
$row = mysql_fetch_array($qresult, MYSQL_ASSOC);
$vars->vpr_id = $row['vpr_id'];
}
}
function InsertInActivity($link, $vars) {
// ENTER INTO ACTIVITY
$vaction_desc = 'PATIENT ENTERED';
$sql = "INSERT INTO v_pr_activity (
vpr_id,
va_plan,
va_action_dttm,
va_action_code,
va_action_desc,
va_disposition_code,
va_disposition_desc,
va_status_code,
va_status_desc
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'VINIT',
'$vaction_desc',
'SUCCESS',
'SUCCESS',
'VACT',
'ACTIVE'
)";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
}
include './includes/dblogin.php';
$vars = new variables_obj();
$vars->vpr_plan = 'VP01';
$vars->vpr_clid = $_SESSION['userid'];
//-------------------------------------------------------
// No commas can be in client name or they will
// mess up the Global Connect CSV file.
//-------------------------------------------------------
$vpr_cl_name = $_SESSION['username'];
$vpr_cl_name = str_replace(",", " ", $vpr_cl_name);
$vars->vpr_cl_name = $vpr_cl_name;
//-------------------------------------------------------
//-------------------------------------------------------
$vars->vpr_cl_phone = ScrubPhone($_SESSION['uphone']);
$vars->vpr_call_start_date = '0000-00-00';
$vars->vpr_db_account = $_POST['ndaccnum'];
$vars->vpr_db_fname = $_POST['ndfreqname'];
$vars->vpr_db_mname = $_POST['ndmname'];
$vars->vpr_db_lname = $_POST['ndlreqname'];
$vars->vpr_rp_fname = $_POST['ndrfreqname'];
$vars->vpr_rp_mname = $_POST['ndrmname'];
$vars->vpr_rp_lname = $_POST['ndrlreqname'];
$vars->vpr_rp_address = '';
$vars->vpr_rp_city = '';
$vars->vpr_rp_state = $_POST['ndrstatereqname'];
$vars->vpr_rp_zipcode = $_POST['ndrreqzipcode'];
$phonenumber = $_POST['1ndrreqphone'].$_POST['2ndrreqphone'].$_POST['3ndrreqphone'];
$vars->vpr_rp_phonenum = $phonenumber;
$vars->vpr_rp_phonetype = $_POST['treqphone'];
$vars->vpr_date_entered = date('Y-m-d H:i:s');
$vars->newrecdt = date('Ymd');
$vars->vpr_promocode = $_POST['promocode'];
// echo "vpr_plan: ".$vars->vpr_plan."<br>";
// echo "vpr_date_entered: ".$vars->vpr_date_entered."<br>";
// echo "newrecdt: ".$vars->newrecdt."<br>";
// echo "vpr_clid: ".$vars->vpr_clid."<br>";
// echo "vpr_id: ".$vars->vpr_id."<br>";
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
$result = InsertInActivity($link, $vars);
$result = CreateSchedule($link, $vars);
$result = ScheduleCreated($link, $vars);
// echo "vpr_id: ".$vars->vpr_id."<br>";
mysql_close($link);
// redirect
$redirect = 'vpayremind.php';
include './includes/redirect.php';
?>
okay referencing the following lines..
if ( $vpr_clid == 199 ) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
...and then:
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
so on and so forth... }
it doesnt seem as if you are actually setting the value of the class object. You seem to be setting some arbitrary php variable to the name you want, and then passing a totally different ' $vars ' object into the function. I don't see any reason to believe that the ' $vars ' you are passing into the function call contains the name value you want it to contain. You should be assigning the value of ' $vars ' before passing it in.
For instance:
if ( $vpr_clid == 199 ) {
$vars[ 'vpr_cl_name' ] = "Shelley Madsen And Associates";
}
then you can get rid of this line all together:
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");

array or variable loses value when entering if/else statement

here is some of the code where I declared the values for $list.
$list['first_name'] = Request::input("first_name");
$list['last_name'] = Request::input("last_name");
when I use dd($list), it shows the value like in my snipped image
but when it enters this if else statement,
if($existing_customer)
{
$customer_id = $existing_customer->customer_id;
}
else
{
dd($list);
$insert_customer["first_name"] = ($list['first_name'] == "undefined" ? "John" : ucfirst($list['first_name']));
$insert_customer["last_name"] = ($list['last_name'] == "undefined" ? "Doe" : ucfirst($list['last_name']));
}
this is the result.
here is the photo of my function, if it could help.
first
second
public function import_submit()
{
$data = Self::get_initial_settings();
/* INITIALIZE AND CAPTURE DATA */
$shop_id = $this->user_info->shop_id;
$sponsor = Tbl_mlm_slot::where("slot_no", Request::input("sponsor"))->where("shop_id", $shop_id)->value("slot_id");
$placement = Tbl_mlm_slot::where("slot_no", Request::input("placement"))->where("shop_id", $shop_id)->value("slot_id");
/* POSITIONING DATA */
$slot_sponsor = $sponsor;
$slot_placement = $placement;
$slot_position = strtolower(Request::input("position"));
/* SLOT GENERATION */
$membership_package_id = Request::input("package_number");
/* JUST ADD TO SLOT IF EXISTING CUSTOMER */
if(Request::input("date_created") == "undefined")
{
$slot_date_created = date("Y-m-d h:i");
}
else
{
$slot_date_created = date("Y-m-d", strtotime(Request::input("date_created")));
}
$existing_customer = Tbl_customer::where("shop_id", $shop_id)->where("email", Request::input("email"))->first();
$list['first_name'] = Request::input("first_name");
$list['last_name'] = Request::input("last_name");
$list['email'] = Request::input("email");
$list['slot_no'] = Request::input("slot_no");
$list['password'] = Request::input("password");
$list['birthday'] = Request::input("birthday");
$list['contact'] = Request::input("contact_number");
$list['gender'] = Request::input("gender");
dd($list); <---- first run of the function, I put one here
if($existing_customer)
{
$customer_id = $existing_customer->customer_id;
}
else
{
dd($list); <--- for the second run of the function, to check what happens to my $list
$insert_customer["shop_id"] = $shop_id;
$insert_customer["first_name"] = ($list['first_name'] == "undefined" ? "John" : ucfirst($list['first_name']));
$insert_customer["last_name"] = ($list['last_name'] == "undefined" ? "Doe" : ucfirst($list['last_name']));
$insert_customer["email"] = ($list['email'] == "undefined" ? "dummy#gmail.com" : $list['email']);
$insert_customer["ismlm"] = 1;
$insert_customer["mlm_username"] = $list['slot_no'];
$insert_customer["password"] = ($list['password'] == "undefined" ? Crypt::encrypt(randomPassword()) : Crypt::encrypt($list['password']));
$insert_customer["created_date"] = $slot_date_created;
$insert_customer["b_day"] = date("Y-m-d", strtotime($list['birthday']));
$insert_customer["birthday"] = date("Y-m-d", strtotime($list['birthday']));
$insert_customer["contact"] = $list['contact'];
$insert_customer["gender"] = strtolower($list['gender']);
$customer_id = Tbl_customer::insertGetId($insert_customer);
/* Insert Customer Address */
$address_purpose[0] = "permanent";
$address_purpose[1] = "billing";
$address_purpose[2] = "shipping";
foreach ($address_purpose as $key => $value)
{
$insert_customer_address["customer_id"] = $customer_id;
$insert_customer_address["country_id"] = 420;
$insert_customer_address["customer_state"] = "";
$insert_customer_address["customer_city"] = "";
$insert_customer_address["customer_zipcode"] = "";
$insert_customer_address["customer_street"] = Request::input("address");
$insert_customer_address["purpose"] = $value;
$insert_customer_address["archived"] = 0;
$insert_customer_address["created_at"] = Carbon::now();
$insert_customer_address["updated_at"] = Carbon::now();
Tbl_customer_address::insert($insert_customer_address);
}
}
}
I can't really see where I went wrong as the values went null just because they entered that if/else statement.

What is more efficient? Connecting to the DB or having a couple hundred rows in an array?

I'm trying to get the calling code and the country name of my visitors.
Previously, I had a connection to the DB to get the calling code and country name that matches the one we got from CloudFlare, using
$_SERVER["HTTP_CF_IPCOUNTRY"];
and
$country_code=$_SERVER["HTTP_CF_IPCOUNTRY"];
$stmt = $pdo->query('SELECT short_name, calling_code from country WHERE iso2 LIKE "'.$country_code.'"');
$country = $stmt->fetch();
However, when traffic gets heavy, having many connections to the DB can be problematic. So I defined this array:
$countries = array();
$countries['AF'] = array("code"=>"AF","short_name"=>"Afghanistan","calling_code"=>"93");
$countries['AL'] = array("code"=>"AL","short_name"=>"Albania","calling_code"=>"355");
$countries['DZ'] = array("code"=>"DZ","short_name"=>"Algeria","calling_code"=>"213");
$countries['AS'] = array("code"=>"AS","short_name"=>"American Samoa","calling_code"=>"1");
$countries['AD'] = array("code"=>"AD","short_name"=>"Andorra","calling_code"=>"376");
$countries['AO'] = array("code"=>"AO","short_name"=>"Angola","calling_code"=>"244");
$countries['AI'] = array("code"=>"AI","short_name"=>"Anguilla","calling_code"=>"1");
$countries['AG'] = array("code"=>"AG","short_name"=>"Antigua","calling_code"=>"1");
$countries['AR'] = array("code"=>"AR","short_name"=>"Argentina","calling_code"=>"54");
$countries['AM'] = array("code"=>"AM","short_name"=>"Armenia","calling_code"=>"374");
$countries['AW'] = array("code"=>"AW","short_name"=>"Aruba","calling_code"=>"297");
$countries['AU'] = array("code"=>"AU","short_name"=>"Australia","calling_code"=>"61");
$countries['AT'] = array("code"=>"AT","short_name"=>"Austria","calling_code"=>"43");
$countries['AZ'] = array("code"=>"AZ","short_name"=>"Azerbaijan","calling_code"=>"994");
$countries['BH'] = array("code"=>"BH","short_name"=>"Bahrain","calling_code"=>"973");
$countries['BD'] = array("code"=>"BD","short_name"=>"Bangladesh","calling_code"=>"880");
$countries['BB'] = array("code"=>"BB","short_name"=>"Barbados","calling_code"=>"1");
$countries['BY'] = array("code"=>"BY","short_name"=>"Belarus","calling_code"=>"375");
$countries['BE'] = array("code"=>"BE","short_name"=>"Belgium","calling_code"=>"32");
$countries['BZ'] = array("code"=>"BZ","short_name"=>"Belize","calling_code"=>"501");
$countries['BJ'] = array("code"=>"BJ","short_name"=>"Benin","calling_code"=>"229");
$countries['BM'] = array("code"=>"BM","short_name"=>"Bermuda","calling_code"=>"1");
$countries['BT'] = array("code"=>"BT","short_name"=>"Bhutan","calling_code"=>"975");
$countries['BO'] = array("code"=>"BO","short_name"=>"Bolivia","calling_code"=>"591");
$countries['BA'] = array("code"=>"BA","short_name"=>"Bosnia and Herzegovina","calling_code"=>"387");
$countries['BW'] = array("code"=>"BW","short_name"=>"Botswana","calling_code"=>"267");
$countries['BR'] = array("code"=>"BR","short_name"=>"Brazil","calling_code"=>"55");
$countries['IO'] = array("code"=>"IO","short_name"=>"British Indian Ocean Territory","calling_code"=>"246");
$countries['VG'] = array("code"=>"VG","short_name"=>"British Virgin Islands","calling_code"=>"1");
$countries['BN'] = array("code"=>"BN","short_name"=>"Brunei","calling_code"=>"673");
$countries['BG'] = array("code"=>"BG","short_name"=>"Bulgaria","calling_code"=>"359");
$countries['BF'] = array("code"=>"BF","short_name"=>"Burkina Faso","calling_code"=>"226");
$countries['MM'] = array("code"=>"MM","short_name"=>"Burma Myanmar" ,"calling_code"=>"95");
$countries['BI'] = array("code"=>"BI","short_name"=>"Burundi","calling_code"=>"257");
$countries['KH'] = array("code"=>"KH","short_name"=>"Cambodia","calling_code"=>"855");
$countries['CM'] = array("code"=>"CM","short_name"=>"Cameroon","calling_code"=>"237");
$countries['CA'] = array("code"=>"CA","short_name"=>"Canada","calling_code"=>"1");
$countries['CV'] = array("code"=>"CV","short_name"=>"Cape Verde","calling_code"=>"238");
$countries['KY'] = array("code"=>"KY","short_name"=>"Cayman Islands","calling_code"=>"1");
$countries['CF'] = array("code"=>"CF","short_name"=>"Central African Republic","calling_code"=>"236");
$countries['TD'] = array("code"=>"TD","short_name"=>"Chad","calling_code"=>"235");
$countries['CL'] = array("code"=>"CL","short_name"=>"Chile","calling_code"=>"56");
$countries['CN'] = array("code"=>"CN","short_name"=>"China","calling_code"=>"86");
$countries['CO'] = array("code"=>"CO","short_name"=>"Colombia","calling_code"=>"57");
$countries['KM'] = array("code"=>"KM","short_name"=>"Comoros","calling_code"=>"269");
$countries['CK'] = array("code"=>"CK","short_name"=>"Cook Islands","calling_code"=>"682");
$countries['CR'] = array("code"=>"CR","short_name"=>"Costa Rica","calling_code"=>"506");
$countries['CI'] = array("code"=>"CI","short_name"=>"Côte d'Ivoire" ,"calling_code"=>"225");
$countries['HR'] = array("code"=>"HR","short_name"=>"Croatia","calling_code"=>"385");
$countries['CU'] = array("code"=>"CU","short_name"=>"Cuba","calling_code"=>"53");
$countries['CY'] = array("code"=>"CY","short_name"=>"Cyprus","calling_code"=>"357");
$countries['CZ'] = array("code"=>"CZ","short_name"=>"Czech Republic","calling_code"=>"420");
$countries['CD'] = array("code"=>"CD","short_name"=>"Democratic Republic of Congo","calling_code"=>"243");
$countries['DK'] = array("code"=>"DK","short_name"=>"Denmark","calling_code"=>"45");
$countries['DJ'] = array("code"=>"DJ","short_name"=>"Djibouti","calling_code"=>"253");
$countries['DM'] = array("code"=>"DM","short_name"=>"Dominica","calling_code"=>"1");
$countries['DO'] = array("code"=>"DO","short_name"=>"Dominican Republic","calling_code"=>"1");
$countries['EC'] = array("code"=>"EC","short_name"=>"Ecuador","calling_code"=>"593");
$countries['EG'] = array("code"=>"EG","short_name"=>"Egypt","calling_code"=>"20");
$countries['SV'] = array("code"=>"SV","short_name"=>"El Salvador","calling_code"=>"503");
$countries['GQ'] = array("code"=>"GQ","short_name"=>"Equatorial Guinea","calling_code"=>"240");
$countries['ER'] = array("code"=>"ER","short_name"=>"Eritrea","calling_code"=>"291");
$countries['EE'] = array("code"=>"EE","short_name"=>"Estonia","calling_code"=>"372");
$countries['ET'] = array("code"=>"ET","short_name"=>"Ethiopia","calling_code"=>"251");
$countries['FK'] = array("code"=>"FK","short_name"=>"Falkland Islands","calling_code"=>"500");
$countries['FO'] = array("code"=>"FO","short_name"=>"Faroe Islands","calling_code"=>"298");
$countries['FM'] = array("code"=>"FM","short_name"=>"Federated States of Micronesia","calling_code"=>"691");
$countries['FJ'] = array("code"=>"FJ","short_name"=>"Fiji","calling_code"=>"679");
$countries['FI'] = array("code"=>"FI","short_name"=>"Finland","calling_code"=>"358");
$countries['FR'] = array("code"=>"FR","short_name"=>"France","calling_code"=>"33");
$countries['GF'] = array("code"=>"GF","short_name"=>"French Guiana","calling_code"=>"594");
$countries['PF'] = array("code"=>"PF","short_name"=>"French Polynesia","calling_code"=>"689");
$countries['GA'] = array("code"=>"GA","short_name"=>"Gabon","calling_code"=>"241");
$countries['GE'] = array("code"=>"GE","short_name"=>"Georgia","calling_code"=>"995");
$countries['DE'] = array("code"=>"DE","short_name"=>"Germany","calling_code"=>"49");
$countries['GH'] = array("code"=>"GH","short_name"=>"Ghana","calling_code"=>"233");
$countries['GI'] = array("code"=>"GI","short_name"=>"Gibraltar","calling_code"=>"350");
$countries['GR'] = array("code"=>"GR","short_name"=>"Greece","calling_code"=>"30");
$countries['GL'] = array("code"=>"GL","short_name"=>"Greenland","calling_code"=>"299");
$countries['GD'] = array("code"=>"GD","short_name"=>"Grenada","calling_code"=>"1");
$countries['GP'] = array("code"=>"GP","short_name"=>"Guadeloupe","calling_code"=>"590");
$countries['GU'] = array("code"=>"GU","short_name"=>"Guam","calling_code"=>"1");
$countries['GT'] = array("code"=>"GT","short_name"=>"Guatemala","calling_code"=>"502");
$countries['GN'] = array("code"=>"GN","short_name"=>"Guinea","calling_code"=>"224");
$countries['GW'] = array("code"=>"GW","short_name"=>"Guinea-Bissau","calling_code"=>"245");
$countries['GY'] = array("code"=>"GY","short_name"=>"Guyana","calling_code"=>"592");
$countries['HT'] = array("code"=>"HT","short_name"=>"Haiti","calling_code"=>"509");
$countries['HN'] = array("code"=>"HN","short_name"=>"Honduras","calling_code"=>"504");
$countries['HK'] = array("code"=>"HK","short_name"=>"Hong Kong","calling_code"=>"852");
$countries['HU'] = array("code"=>"HU","short_name"=>"Hungary","calling_code"=>"36");
$countries['IS'] = array("code"=>"IS","short_name"=>"Iceland","calling_code"=>"354");
$countries['IN'] = array("code"=>"IN","short_name"=>"India","calling_code"=>"91");
$countries['ID'] = array("code"=>"ID","short_name"=>"Indonesia","calling_code"=>"62");
$countries['IR'] = array("code"=>"IR","short_name"=>"Iran","calling_code"=>"98");
$countries['IQ'] = array("code"=>"IQ","short_name"=>"Iraq","calling_code"=>"964");
$countries['IE'] = array("code"=>"IE","short_name"=>"Ireland","calling_code"=>"353");
$countries['IL'] = array("code"=>"IL","short_name"=>"Israel","calling_code"=>"972");
$countries['IT'] = array("code"=>"IT","short_name"=>"Italy","calling_code"=>"39");
$countries['JM'] = array("code"=>"JM","short_name"=>"Jamaica","calling_code"=>"1");
$countries['JP'] = array("code"=>"JP","short_name"=>"Japan","calling_code"=>"81");
$countries['JO'] = array("code"=>"JO","short_name"=>"Jordan","calling_code"=>"962");
$countries['KZ'] = array("code"=>"KZ","short_name"=>"Kazakhstan","calling_code"=>"7");
$countries['KE'] = array("code"=>"KE","short_name"=>"Kenya","calling_code"=>"254");
$countries['KI'] = array("code"=>"KI","short_name"=>"Kiribati","calling_code"=>"686");
$countries['XK'] = array("code"=>"XK","short_name"=>"Kosovo","calling_code"=>"381");
$countries['KW'] = array("code"=>"KW","short_name"=>"Kuwait","calling_code"=>"965");
$countries['KG'] = array("code"=>"KG","short_name"=>"Kyrgyzstan","calling_code"=>"996");
$countries['LA'] = array("code"=>"LA","short_name"=>"Laos","calling_code"=>"856");
$countries['LV'] = array("code"=>"LV","short_name"=>"Latvia","calling_code"=>"371");
$countries['LB'] = array("code"=>"LB","short_name"=>"Lebanon","calling_code"=>"961");
$countries['LS'] = array("code"=>"LS","short_name"=>"Lesotho","calling_code"=>"266");
$countries['LR'] = array("code"=>"LR","short_name"=>"Liberia","calling_code"=>"231");
$countries['LY'] = array("code"=>"LY","short_name"=>"Libya","calling_code"=>"218");
$countries['LI'] = array("code"=>"LI","short_name"=>"Liechtenstein","calling_code"=>"423");
$countries['LT'] = array("code"=>"LT","short_name"=>"Lithuania","calling_code"=>"370");
$countries['LU'] = array("code"=>"LU","short_name"=>"Luxembourg","calling_code"=>"352");
$countries['MO'] = array("code"=>"MO","short_name"=>"Macau","calling_code"=>"853");
$countries['MK'] = array("code"=>"MK","short_name"=>"Macedonia","calling_code"=>"389");
$countries['MG'] = array("code"=>"MG","short_name"=>"Madagascar","calling_code"=>"261");
$countries['MW'] = array("code"=>"MW","short_name"=>"Malawi","calling_code"=>"265");
$countries['MY'] = array("code"=>"MY","short_name"=>"Malaysia","calling_code"=>"60");
$countries['MV'] = array("code"=>"MV","short_name"=>"Maldives","calling_code"=>"960");
$countries['ML'] = array("code"=>"ML","short_name"=>"Mali","calling_code"=>"223");
$countries['MT'] = array("code"=>"MT","short_name"=>"Malta","calling_code"=>"356");
$countries['MH'] = array("code"=>"MH","short_name"=>"Marshall Islands","calling_code"=>"692");
$countries['MQ'] = array("code"=>"MQ","short_name"=>"Martinique","calling_code"=>"596");
$countries['MR'] = array("code"=>"MR","short_name"=>"Mauritania","calling_code"=>"222");
$countries['MU'] = array("code"=>"MU","short_name"=>"Mauritius","calling_code"=>"230");
$countries['YT'] = array("code"=>"YT","short_name"=>"Mayotte","calling_code"=>"262");
$countries['MX'] = array("code"=>"MX","short_name"=>"Mexico","calling_code"=>"52");
$countries['MD'] = array("code"=>"MD","short_name"=>"Moldova","calling_code"=>"373");
$countries['MC'] = array("code"=>"MC","short_name"=>"Monaco","calling_code"=>"377");
$countries['MN'] = array("code"=>"MN","short_name"=>"Mongolia","calling_code"=>"976");
$countries['ME'] = array("code"=>"ME","short_name"=>"Montenegro","calling_code"=>"382");
$countries['MS'] = array("code"=>"MS","short_name"=>"Montserrat","calling_code"=>"1");
$countries['MA'] = array("code"=>"MA","short_name"=>"Morocco","calling_code"=>"212");
$countries['MZ'] = array("code"=>"MZ","short_name"=>"Mozambique","calling_code"=>"258");
$countries['NA'] = array("code"=>"NA","short_name"=>"Namibia","calling_code"=>"264");
$countries['NR'] = array("code"=>"NR","short_name"=>"Nauru","calling_code"=>"674");
$countries['NP'] = array("code"=>"NP","short_name"=>"Nepal","calling_code"=>"977");
$countries['NL'] = array("code"=>"NL","short_name"=>"Netherlands","calling_code"=>"31");
$countries['AN'] = array("code"=>"AN","short_name"=>"Netherlands Antilles","calling_code"=>"599");
$countries['NC'] = array("code"=>"NC","short_name"=>"New Caledonia","calling_code"=>"687");
$countries['NZ'] = array("code"=>"NZ","short_name"=>"New Zealand","calling_code"=>"64");
$countries['NI'] = array("code"=>"NI","short_name"=>"Nicaragua","calling_code"=>"505");
$countries['NE'] = array("code"=>"NE","short_name"=>"Niger","calling_code"=>"227");
$countries['NG'] = array("code"=>"NG","short_name"=>"Nigeria","calling_code"=>"234");
$countries['NU'] = array("code"=>"NU","short_name"=>"Niue","calling_code"=>"683");
$countries['NF'] = array("code"=>"NF","short_name"=>"Norfolk Island","calling_code"=>"672");
$countries['KP'] = array("code"=>"KP","short_name"=>"North Korea","calling_code"=>"850");
$countries['MP'] = array("code"=>"MP","short_name"=>"Northern Mariana Islands","calling_code"=>"1");
$countries['NO'] = array("code"=>"NO","short_name"=>"Norway","calling_code"=>"47");
$countries['OM'] = array("code"=>"OM","short_name"=>"Oman","calling_code"=>"968");
$countries['PK'] = array("code"=>"PK","short_name"=>"Pakistan","calling_code"=>"92");
$countries['PW'] = array("code"=>"PW","short_name"=>"Palau","calling_code"=>"680");
$countries['PS'] = array("code"=>"PS","short_name"=>"Palestine","calling_code"=>"970");
$countries['PA'] = array("code"=>"PA","short_name"=>"Panama","calling_code"=>"507");
$countries['PG'] = array("code"=>"PG","short_name"=>"Papua New Guinea","calling_code"=>"675");
$countries['PY'] = array("code"=>"PY","short_name"=>"Paraguay","calling_code"=>"595");
$countries['PE'] = array("code"=>"PE","short_name"=>"Peru","calling_code"=>"51");
$countries['PH'] = array("code"=>"PH","short_name"=>"Philippines","calling_code"=>"63");
$countries['PL'] = array("code"=>"PL","short_name"=>"Poland","calling_code"=>"48");
$countries['PT'] = array("code"=>"PT","short_name"=>"Portugal","calling_code"=>"351");
$countries['PR'] = array("code"=>"PR","short_name"=>"Puerto Rico","calling_code"=>"1");
$countries['QA'] = array("code"=>"QA","short_name"=>"Qatar","calling_code"=>"974");
$countries['CG'] = array("code"=>"CG","short_name"=>"Republic of the Congo","calling_code"=>"242");
$countries['RE'] = array("code"=>"RE","short_name"=>"Réunion" ,"calling_code"=>"262");
$countries['RO'] = array("code"=>"RO","short_name"=>"Romania","calling_code"=>"40");
$countries['RU'] = array("code"=>"RU","short_name"=>"Russia","calling_code"=>"7");
$countries['RW'] = array("code"=>"RW","short_name"=>"Rwanda","calling_code"=>"250");
$countries['BL'] = array("code"=>"BL","short_name"=>"Saint Barthélemy" ,"calling_code"=>"590");
$countries['SH'] = array("code"=>"SH","short_name"=>"Saint Helena","calling_code"=>"290");
$countries['KN'] = array("code"=>"KN","short_name"=>"Saint Kitts and Nevis","calling_code"=>"1");
$countries['MF'] = array("code"=>"MF","short_name"=>"Saint Martin","calling_code"=>"590");
$countries['PM'] = array("code"=>"PM","short_name"=>"Saint Pierre and Miquelon","calling_code"=>"508");
$countries['VC'] = array("code"=>"VC","short_name"=>"Saint Vincent and the Grenadines","calling_code"=>"1");
$countries['WS'] = array("code"=>"WS","short_name"=>"Samoa","calling_code"=>"685");
$countries['SM'] = array("code"=>"SM","short_name"=>"San Marino","calling_code"=>"378");
$countries['ST'] = array("code"=>"ST","short_name"=>"São Tomé and Príncipe" ,"calling_code"=>"239");
$countries['SA'] = array("code"=>"SA","short_name"=>"Saudi Arabia","calling_code"=>"966");
$countries['SN'] = array("code"=>"SN","short_name"=>"Senegal","calling_code"=>"221");
$countries['RS'] = array("code"=>"RS","short_name"=>"Serbia","calling_code"=>"381");
$countries['SC'] = array("code"=>"SC","short_name"=>"Seychelles","calling_code"=>"248");
$countries['SL'] = array("code"=>"SL","short_name"=>"Sierra Leone","calling_code"=>"232");
$countries['SG'] = array("code"=>"SG","short_name"=>"Singapore","calling_code"=>"65");
$countries['SK'] = array("code"=>"SK","short_name"=>"Slovakia","calling_code"=>"421");
$countries['SI'] = array("code"=>"SI","short_name"=>"Slovenia","calling_code"=>"386");
$countries['SB'] = array("code"=>"SB","short_name"=>"Solomon Islands","calling_code"=>"677");
$countries['SO'] = array("code"=>"SO","short_name"=>"Somalia","calling_code"=>"252");
$countries['ZA'] = array("code"=>"ZA","short_name"=>"South Africa","calling_code"=>"27");
$countries['KR'] = array("code"=>"KR","short_name"=>"South Korea","calling_code"=>"82");
$countries['ES'] = array("code"=>"ES","short_name"=>"Spain","calling_code"=>"34");
$countries['LK'] = array("code"=>"LK","short_name"=>"Sri Lanka","calling_code"=>"94");
$countries['LC'] = array("code"=>"LC","short_name"=>"St. Lucia","calling_code"=>"1");
$countries['SD'] = array("code"=>"SD","short_name"=>"Sudan","calling_code"=>"249");
$countries['SR'] = array("code"=>"SR","short_name"=>"Surishort_name","calling_code"=>"597");
$countries['SZ'] = array("code"=>"SZ","short_name"=>"Swaziland","calling_code"=>"268");
$countries['SE'] = array("code"=>"SE","short_name"=>"Sweden","calling_code"=>"46");
$countries['CH'] = array("code"=>"CH","short_name"=>"Switzerland","calling_code"=>"41");
$countries['SY'] = array("code"=>"SY","short_name"=>"Syria","calling_code"=>"963");
$countries['TW'] = array("code"=>"TW","short_name"=>"Taiwan","calling_code"=>"886");
$countries['TJ'] = array("code"=>"TJ","short_name"=>"Tajikistan","calling_code"=>"992");
$countries['TZ'] = array("code"=>"TZ","short_name"=>"Tanzania","calling_code"=>"255");
$countries['TH'] = array("code"=>"TH","short_name"=>"Thailand","calling_code"=>"66");
$countries['BS'] = array("code"=>"BS","short_name"=>"The Bahamas","calling_code"=>"1");
$countries['GM'] = array("code"=>"GM","short_name"=>"The Gambia","calling_code"=>"220");
$countries['TL'] = array("code"=>"TL","short_name"=>"Timor-Leste","calling_code"=>"670");
$countries['TG'] = array("code"=>"TG","short_name"=>"Togo","calling_code"=>"228");
$countries['TK'] = array("code"=>"TK","short_name"=>"Tokelau","calling_code"=>"690");
$countries['TO'] = array("code"=>"TO","short_name"=>"Tonga","calling_code"=>"676");
$countries['TT'] = array("code"=>"TT","short_name"=>"Trinidad and Tobago","calling_code"=>"1");
$countries['TN'] = array("code"=>"TN","short_name"=>"Tunisia","calling_code"=>"216");
$countries['TR'] = array("code"=>"TR","short_name"=>"Turkey","calling_code"=>"90");
$countries['TM'] = array("code"=>"TM","short_name"=>"Turkmenistan","calling_code"=>"993");
$countries['TC'] = array("code"=>"TC","short_name"=>"Turks and Caicos Islands","calling_code"=>"1");
$countries['TV'] = array("code"=>"TV","short_name"=>"Tuvalu","calling_code"=>"688");
$countries['UG'] = array("code"=>"UG","short_name"=>"Uganda","calling_code"=>"256");
$countries['UA'] = array("code"=>"UA","short_name"=>"Ukraine","calling_code"=>"380");
$countries['AE'] = array("code"=>"AE","short_name"=>"United Arab Emirates","calling_code"=>"971");
$countries['GB'] = array("code"=>"GB","short_name"=>"United Kingdom","calling_code"=>"44");
$countries['US'] = array("code"=>"US","short_name"=>"United States","calling_code"=>"1");
$countries['UY'] = array("code"=>"UY","short_name"=>"Uruguay","calling_code"=>"598");
$countries['VI'] = array("code"=>"VI","short_name"=>"US Virgin Islands","calling_code"=>"1");
$countries['UZ'] = array("code"=>"UZ","short_name"=>"Uzbekistan","calling_code"=>"998");
$countries['VU'] = array("code"=>"VU","short_name"=>"Vanuatu","calling_code"=>"678");
$countries['VA'] = array("code"=>"VA","short_name"=>"Vatican City","calling_code"=>"39");
$countries['VE'] = array("code"=>"VE","short_name"=>"Venezuela","calling_code"=>"58");
$countries['VN'] = array("code"=>"VN","short_name"=>"Vietnam","calling_code"=>"84");
$countries['WF'] = array("code"=>"WF","short_name"=>"Wallis and Futuna","calling_code"=>"681");
$countries['YE'] = array("code"=>"YE","short_name"=>"Yemen","calling_code"=>"967");
$countries['ZM'] = array("code"=>"ZM","short_name"=>"Zambia","calling_code"=>"260");
$countries['ZW'] = array("code"=>"ZW","short_name"=>"Zimbabwe","calling_code"=>"263");
and I simply fetch the values I want using:
$country_code=$_SERVER["HTTP_CF_IPCOUNTRY"];
$country=$countries[''.$country_code.''];
Thus eliminating the need to connect to the DB and use MYSQL.
My question is, is it bad to have this array loaded several times a second? Will it impact performance a lot? Should I simply have a connection to the DB like I previously did?
The server has 16GB of RAM and 8 cores. We're talking about 40-50 thousand visits per day.
Thanks!
First: $country=$countries[''.$country_code.'']; can be replaced with this $country=$countries[$country_code];
This array is definitly the better choice over a Database. Each connection needs some time and arrays can be accessed way faster.
If you want to know exactly how the difference is, you could use this "mini test suite" t determine the runtime difference.
$start1 = microtime(true);
for($i = 0; $i < 10000; $i++)
{
//With database
}
$end1 = microtime(true);
unset(); // The variables which might have been set the section above
$start2 = microtime(true);
for($i = 0; $i < 10000; $i++)
{
//code with array
}
$end2 = microtime(true);
echo $end1-$start1."<br />";
echo $end2-$start2."<br />";
I hope this helps you, if not please let me know.

Invalid parameter number: parameter was not defined, parameters are mapped?

Pretty sure I mapped the parameters right but still getting this error. I've tried matching up the parameters with the query and they match fine. I've also tried several other things but nothing is solving the issue. Any ideas?
$stmt = $conn->prepare("UPDATE stores SET Name = :Name, Legal_Entity__c = :Legal_Entity__c, Opening_Date__c = :Opening_Date__c, Owner_Type__c = :Owner_Type__c, Yumtracker_Status__c = :Yumtracker_Status__c, Hypercare_Status__c = :Hypercare_Status__c,BOH_Type__c = :BOH_Type__c,Store_Type__c = :Store_Type__c,Address_Line_1__c = :Address_Line_1__c,Address_Line_2__c = :Address_Line_2__c,City__c = :City__c,State__c = :State__c,Zip__c = :Zip__c,Store_Email_Address__c = :Store_Email_Address__c,Time_Zone__c = :Time_Zone__c,Area_Coach__c = :Area_Coach__c,RGM__c = :RGM__c,RTO_Date__c = :RTO_Date__c,Ground_Break_Date__c = :Ground_Break_Date__c,BOH_Install_Date__c = :BOH_Install_Date__c,Primary_BB_Install_Date__c = :Primary_BB_Install_Date__c,TTO_Install_Date__c = :TTO_Install_Date__c,Pre_Cable_Date__c = :Pre_Cable_Date__c,HME_Install_Date__c = :HME_Install_Date__c,Install_Date__c = :Install_Date__c,POS_Install_Date__c = :POS_Install_Date__c,Backup_BB_Install_Date__c = :Backup_BB_Install_Date__c,Telco_Install_Date__c = :Telco_Install_Date__c,Site_Survey_Date__c = :Site_Survey_Date__c,Opening_Support_Date__c = :Opening_Support_Date__c,Sea_Trial__c = :Sea_Trial__c,Mobile__c = :Mobile__c,OCB__c = :OCB__c,BOH__c = :BOH__c,KDS__c = :KDS__c,POS__c = :POS__c,HME__c = :HME__c,Airtight__c = :Airtight__c,LZ__c = :LZ__c,HZ__c = :HZ__c,Technology_Check_Last_Update__c = :Technology_Check_Last_Update__c,Verify_Store_is_in_EDM__c = :Verify_Store_is_in_EDM__c,Verify_AC_RGM_have_INIT_checklist__c = :Verify_AC_RGM_have_INIT_checklist__c,Verify_TACO_eRes_is_INIT__c = :Verify_TACO_eRes_is_INIT__c,Verify_no_issues_with_Tech__c = :Verify_no_issues_with_Tech__c,Verify_Store_Opened__c = :Verify_Store_Opened__c,Verify_store_shows_open_in_Remedy__c = :Verify_store_shows_open_in_Remedy__c,Verify_Gift_Cards_are_active__c = :Verify_Gift_Cards_are_active__c,Days_in_Implementation__c = :Days_in_Implementation__c,Days_in_Hypercare__c = :Days_in_Hypercare__c,Days_to_Stability__c = :Days_to_Stability__c,Verify_Store_can_access_LZ_HZ__c = :Verify_Store_can_access_LZ_HZ__c,Verify_Mobile_MIDs_sent_to_Tillster__c = :Verify_Mobile_MIDs_sent_to_Tillster__c,Verify_store_has_no_issues__c = :Verify_store_has_no_issues__c,Verify_Mobile_and_Gift_Card_setup_start__c = :Verify_Mobile_and_Gift_Card_setup_start__c WHERE Id = '$recordID'");
$stmt->bindParam(':Name', $updatedRecord->Name);
$stmt->bindParam(':Legal_Entity__c', $updatedRecord->Legal_Entity__c);
$stmt->bindParam(':Opening_Date__c', $updatedRecord->Opening_Date__c);
$stmt->bindParam(':Owner_Type__c', $updatedRecord->Owner_Type__c);
$stmt->bindParam(':YumTracker_Status__c', $updatedRecord->YumTracker_Status__c);
$stmt->bindParam(':Hypercare_Status__c', $updatedRecord->Hypercare_Status__c);
$stmt->bindParam(':BOH_Type__c', $updatedRecord->BOH_Type__c);
$stmt->bindParam(':Store_Type__c', $updatedRecord->Store_Type__c);
$stmt->bindParam(':Address_Line_1__c', $updatedRecord->Address_Line_1__c);
$stmt->bindParam(':Address_Line_2__c', $updatedRecord->Address_Line_2__c);
$stmt->bindParam(':City__c', $updatedRecord->City__c);
$stmt->bindParam(':State__c', $updatedRecord->State__c);
$stmt->bindParam(':Zip__c', $updatedRecord->Zip__c);
$stmt->bindParam(':Store_Email_Address__c', $updatedRecord->Store_Email_Address__c);
$stmt->bindParam(':Time_Zone__c', $updatedRecord->Time_Zone__c);
$stmt->bindParam(':Area_Coach__c', $updatedRecord->Area_Coach__c);
$stmt->bindParam(':RGM__c', $updatedRecord->RGM__c);
$stmt->bindParam(':RTO_Date__c', $updatedRecord->RTO_Date__c);
$stmt->bindParam(':Ground_Break_Date__c', $updatedRecord->Ground_Break_Date__c);
$stmt->bindParam(':BOH_Install_Date__c', $updatedRecord->BOH_Install_Date__c);
$stmt->bindParam(':Primary_BB_Install_Date__c', $updatedRecord->Primary_BB_Install_Date__c);
$stmt->bindParam(':TTO_Install_Date__c', $updatedRecord->TTO_Install_Date__c);
$stmt->bindParam(':Pre_Cable_Date__c', $updatedRecord->Pre_Cable_Date__c);
$stmt->bindParam(':HME_Install_Date__c', $updatedRecord->HME_Install_Date__c);
$stmt->bindParam(':Install_Date__c', $updatedRecord->Install_Date__c);
$stmt->bindParam(':POS_Install_Date__c', $updatedRecord->POS_Install_Date__c);
$stmt->bindParam(':Backup_BB_Install_Date__c', $updatedRecord->Backup_BB_Install_Date__c);
$stmt->bindParam(':Telco_Install_Date__c', $updatedRecord->Telco_Install_Date__c);
$stmt->bindParam(':Site_Survey_Date__c', $updatedRecord->Site_Survey_Date__c);
$stmt->bindParam(':Opening_Support_Date__c', $updatedRecord->Opening_Support_Date__c);
$stmt->bindParam(':Sea_Trial__c', $updatedRecord->Sea_Trial__c);
$stmt->bindParam(':Mobile__c', $updatedRecord->Mobile__c);
$stmt->bindParam(':OCB__c', $updatedRecord->OCB__c);
$stmt->bindParam(':BOH__c', $updatedRecord->BOH__c);
$stmt->bindParam(':KDS__c', $updatedRecord->KDS__c);
$stmt->bindParam(':POS__c', $updatedRecord->POS__c);
$stmt->bindParam(':HME__c', $updatedRecord->HME__c);
$stmt->bindParam(':Airtight__c', $updatedRecord->Airtight__c);
$stmt->bindParam(':LZ__c', $updatedRecord->LZ__c);
$stmt->bindParam(':HZ__c', $updatedRecord->HZ__c);
$stmt->bindParam(':Technology_Check_Last_Update__c', $updatedRecord->Technology_Check_Last_Update__c);
$stmt->bindParam(':Verify_Store_is_in_EDM__c', $updatedRecord->Verify_Store_is_in_EDM__c);
$stmt->bindParam(':Verify_AC_RGM_have_INIT_checklist__c', $updatedRecord->Verify_AC_RGM_have_INIT_checklist__c);
$stmt->bindParam(':Verify_TACO_eRes_is_INIT__c', $updatedRecord->Verify_TACO_eRes_is_INIT__c);
$stmt->bindParam(':Verify_no_issues_with_Tech__c', $updatedRecord->Verify_no_issues_with_Tech__c);
$stmt->bindParam(':Verify_Store_Opened__c', $updatedRecord->Verify_Store_Opened__c);
$stmt->bindParam(':Verify_store_shows_open_in_Remedy__c', $updatedRecord->Verify_store_shows_open_in_Remedy__c);
$stmt->bindParam(':Verify_Gift_Cards_are_active__c', $updatedRecord->Verify_Gift_Cards_are_active__c);
$stmt->bindParam(':Days_in_Implementation__c', $updatedRecord->Days_in_Implementation__c);
$stmt->bindParam(':Days_in_Hypercare__c', $updatedRecord->Days_in_Hypercare__c);
$stmt->bindParam(':Days_to_Stability__c', $updatedRecord->Days_to_Stability__c);
$stmt->bindParam(':Verify_Store_can_access_LZ_HZ__c', $updatedRecord->Verify_Store_can_access_LZ_HZ__c);
$stmt->bindParam(':Verify_Mobile_MIDs_sent_to_Tillster__c', $updatedRecord->Verify_Mobile_MIDs_sent_to_Tillster__c);
$stmt->bindParam(':Verify_store_has_no_issues__c', $updatedRecord->Verify_store_has_no_issues__c);
$stmt->bindParam(':Verify_Mobile_and_Gift_Card_setup_start__c', $updatedRecord->Verify_Mobile_and_Gift_Card_setup_start__c);
$stmt->execute();

Values of an array showing wrong values

I'm trying to use files to set the language.
$_LANG[000] = 'Inicío';
$_LANG[001] = 'Principal';
$_LANG[002] = 'Procurar';
$_LANG[003] = 'Estatísticas';
$_LANG[004] = 'Calendário';
$_LANG[005] = 'Pagamentos';
$_LANG[006] = 'Finanças';
$_LANG[007] = 'Gestão';
$_LANG[008] = 'Administração';
$_LANG[009] = 'Boleto Bancário';
$_LANG[010] = 'Cartão de Crédito';
$_LANG[011] = 'Boleto';
$_LANG[012] = 'Visa';
$_LANG[013] = 'MasterCard';
$_LANG[014] = 'HiperCard';
$_LANG[015] = 'Diners Club';
$_LANG[016] = 'American Express';
$_LANG[017] = 'Itaú';
$_LANG[018] = 'Caixa';
$_LANG[019] = 'Bradesco';
$_LANG[020] = 'Banrisul';
$_LANG[021] = 'Visan Eletron';
$_LANG[022] = 'Débido';
$_LANG[023] = 'Crédito';
$_LANG[024] = 'Check In';
$_LANG[025] = 'Check Out';
$_LANG[026] = 'Verificar';
$_LANG[027] = 'Verificando';
$_LANG[028] = 'Fatura';
$_LANG[029] = 'Módulos';
$_LANG[030] = 'Notas Escolares';
$_LANG[031] = 'Faltas';
$_LANG[032] = 'Ano Létivo';
$_LANG[033] = 'Desempenho Escolar';
$_LANG[034] = 'Sumário';
$_LANG[035] = 'Cadastrar Usuário';
$_LANG[036] = 'Novo Usuário';
$_LANG[037] = 'Erro 404';
$_LANG[038] = 'Página Não Dísponivel';
$_LANG[039] = 'Página Não Encontrada';
$_LANG[040] = 'Galeria';
$_LANG[041] = 'Perfil';
$_LANG[042] = 'Configuração';
$_LANG[043] = 'Configurações';
$_LANG[044] = 'Mudar Senha';
$_LANG[045] = 'Sair';
$_LANG[046] = 'Encerrar';
$_LANG[047] = 'Sessão';
$_LANG[048] = 'Mensagens';
$_LANG[049] = 'Notificações';
$_LANG[050] = 'Ver todas notificações';
$_LANG[051] = 'Ver todas mensagens';
$_LANG[052] = 'Ver notificações';
$_LANG[053] = 'Ver mensagem';
$_LANG[054] = 'Aprovado';
$_LANG[055] = 'Reprovado';
$_LANG[056] = 'Recuperação';
$_LANG[057] = '1ª';
$_LANG[058] = '2ª';
$_LANG[059] = '3ª';
$_LANG[060] = '4ª';
$_LANG[061] = '5ª';
$_LANG[062] = '6ª';
$_LANG[063] = '1º';
$_LANG[064] = '2º';
$_LANG[065] = '3º';
$_LANG[066] = '4º';
$_LANG[067] = '5º';
$_LANG[068] = '6º';
$_LANG[069] = 'Chamada';
$_LANG[070] = 'Declaração';
$_LANG[071] = 'Escolar';
$_LANG[072] = 'Transfêrencia';
$_LANG[073] = 'Notícia';
$_LANG[074] = 'Notícias';
$_LANG[075] = 'Acadêmico';
$_LANG[076] = 'Ideias';
$_LANG[077] = 'Ajuda';
$_LANG[078] = 'Suporte Técnico';
$_LANG[079] = 'Relatório';
$_LANG[080] = 'Horários';
$_LANG[081] = 'Quadro de Horários';
$_LANG[082] = 'Notas / Faltas';
$_LANG[083] = 'Plano Ensino';
$_LANG[084] = 'Imprimir';
$_LANG[085] = 'Financeira';
$_LANG[086] = 'Word';
$_LANG[087] = 'Exel';
$_LANG[088] = 'PowerPoint';
$_LANG[089] = 'Skype';
$_LANG[090] = 'Outlook';
$_LANG[091] = 'E-mail';
$_LANG[092] = 'Dúvidas';
$_LANG[093] = 'Bimestre';
$_LANG[094] = 'Semestre';
then I want showing "Inicío" for that I need to insert print $ _LANG [000];
the problem is that it shows the right value
only starting from 010
I do not know why
You're prefixing the keys with 0, so they're being treated as octal numbers.
e.g.
$_LANG[027(octal)] is actually $_LANG[23(decimal)
$_LANG[010(octal)] is actually $_LANG[8(decimal)]
Either use strings:
$_LANG['027']
or normal decimals:
$_LANG[27]

Categories