How to resolve php eden error - php

I have just used the simple query to insert record
$q = "INSERT INTO jobform
(`full_name`,
`father_name`,
`date_of_birth`,
`gender`,
`cnic`,
`city`,
`country`,
`region`,
`contact_number`,
`email_address`,
`degree_title`,
`university`,
`gpa`,
`division`,
`banking_experience`,
`current_organization`,
`job_title`,
`non_banking_experience`,
`non_current_organization`,
`non_job_title`)
VALUES (:full_name,
:father_name,
:date_of_birth,
:gender,
:cnic,
:city,
:country,
:region,
:contact_number,
:email_address,
:degree_title,
:university,
:gpa,
:division,
:banking_experience,
:current_organization,
:job_title,
:non_banking_experience,
:non_current_organization,
:non_job_title)";
$bind = array(
":full_name"=>$full_name,
":father_name"=>$father_name,
":date_of_birth"=>$date_of_birth,
":gender"=>$gender,
":cnic"=>$cnic,
":city"=>$city,
":country"=>$country,
":region"=>$region,
":contact_number"=>$contact_number,
":email_address"=>$email_address,
":degree_title"=>$degree_title,
":university"=>$university,
":gpa"=>$gpa,
":division"=>$division,
":banking_experience"=>$banking_experience,
":current_organization"=>$current_organization,
":job_title"=>$job_title,
":non_banking_experience"=>$non_banking_experience,
":non_current_organization"=>$non_current_organization,
":non_job_title"=>$non_job_title
);
$r = $database->query($q,$bind);
and getting this error, there is no documentation for inserting rows too
Fatal error: Uncaught exception 'Eden_Sql_Error' with message 'INSERT INTO jobform (`full_name`, `father_name`, `date_of_birth`, `gender`, `cnic`, `city`, `country`, `region`, `contact_number`, `email_address`, `degree_title`, `university`, `gpa`, `division`, `banking_experience`, `current_organization`, `job_title`, `non_banking_experience`, `non_current_organization`, `non_job_title`) VALUES ('najm', 'zain', '01-01-2000', 'male', '923092032094209', 'karachi', 'Pakistan', 'sindh', '029320329', 'najm#najm.com', 'Bachelor', 'College Of digital science', '16', 'First', '3 Year', 'BAS', 'Account Manager', '2 Year', in /save.php on line 115

You should use $database->insertRow instead.
Try this.
$data = array(
'full_name' => $full_name,
'date_of_birth' => $date_of_birth ,
'gender' => $gender ,
'cnic' => $cnic ,
'city' => $city ,
'country' => $country ,
'region' => $region ,
'contact_number' => $contact_number ,
'email_address' => $email_address ,
'degree_title' => $degree_title ,
'university' => $university ,
'gpa' => $gpa ,
'division' => $division ,
'banking_experience' => $banking_experience ,
'current_organization' => $current_organization ,
'job_title' => $job_title ,
'non_banking_experience' => $non_banking_experience ,
'non_current_organization' => $non_current_organization ,
'non_job_title' => $non_job_title
);
$result = $database->insertRow('jobform', $data);
Please see official documentation

Related

Woocommerce add Local pickup information to order programmatically

I am creating an order with php. I have successfully created the order, however, cannot add local picup information.
I am using WooCommerce Local Pickup Plus plugin.
I want to add below fields to the order:
Shipping method: Local pickup (already added to woocommerce)
Pickup location: North Miami Beach (already added to woocommerce)
Pickup Date (user selected)
Items to Pickup (all items in cart)
My code till now:
<?php
$woocommerce->cart->empty_cart();
$product_id=358;
$quantity=3;
$variationID=766;
$attr_array=array(
'choose-a-flavor' => 'Red Velvet'
);
$address = array(
'first_name' => 'Arka',
'last_name' => 'Debnath',
'company' => 'Arkas',
'email' => 'my.email#mail.com',
'phone' => '123-456-780',
'address_1' => '123 Main st.',
'address_2' => '104',
'city' => 'San Diego',
'state' => 'Ca',
'postcode' => '92121',
'country' => 'US'
);
$woocommerce->cart->add_to_cart($product_id, $quantity, $variationID, $attr_array);
$order_data = array(
'status' => apply_filters('woocommerce_default_order_status', 'processing')
);
$new_order = wc_create_order($order_data);
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$item_id = $new_order->add_product(
$values['data'], $values['quantity'], array(
'variation' => $values['variation'],
'totals' => array(
'subtotal' => $values['line_subtotal'],
'subtotal_tax' => $values['line_subtotal_tax'],
'total' => $values['line_total'],
'tax' => $values['line_tax'],
'tax_data' => $values['line_tax_data']
)
)
);
}
$new_order->set_address($address, 'billing');
$new_order->set_address($address, 'shipping');
$new_order->calculate_totals();
// The below part does not work
$woocommerce->shipping->load_shipping_methods();
$shipping_methods = $woocommerce->shipping->get_shipping_methods();
$selected_shipping_method = $shipping_methods['local_pickup'];
$shippingMethod = new \WC_Shipping_Rate($selected_shipping_method->id,$selected_shipping_method->title, 0);
$new_order->add_shipping($shippingMethod);
?>
OK no help sp far. I didn't find and wordpress hook anywhere to do this safely. So I went the bad way this time. Added line items in the database directly.
INSERT INTO `wp_woocommerce_order_items` (`order_item_id`, `order_item_name`, `order_item_type`, `order_id`) values (null, 'Local Pickup', 'shipping', '$OrderID')
INSERT INTO `wp_woocommerce_order_itemmeta` (`meta_id`, `order_item_id`, `meta_key`, `meta_value`) VALUES
(null, $OrdeItemID, 'method_id', 'local_pickup_plus'),
(null, $OrdeItemID, 'instance_id', '0'),
(null, $OrdeItemID, 'cost', '0.00'),
(null, $OrdeItemID, 'total_tax', '0'),
(null, $OrdeItemID, 'taxes', 'a:1:{s:5:\"total\";a:0:{}}'),
(null, $OrdeItemID, '_pickup_location_id', '$PickupPostal'),
(null, $OrdeItemID, '_pickup_location_name', 'PickupName'),
(null, $OrdeItemID, '_pickup_location_address', '$PickupLocationArray'),
(null, $OrdeItemID, '_pickup_location_phone', ''),
(null, $OrdeItemID, '_pickup_date', '$DateOfPickup'),
(null, $OrdeItemID, '_pickup_minimum_hours', '$PickupTimeMin'),
(null, $OrdeItemID, '_pickup_items', '$Pickupitem')
I know this is not good, but I don't have a better choice yet. If someone has a solution I will be happy to implement.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter

I have a table (q) have 30 colmns, I wrote it in code correct, but I don't know where it's wrong.
Here I check wrongs:
$formErrors = array();
if(empty($fullname)){$formErrors[] = '<div class="alert alert-danger" > هناك خطأ ما<strong> الاسم</strong></div>'; }
if(empty($email)){$formErrors[] = '<div class="alert alert-danger" >هناك خطأ ما <strong>الايميل</strong></div>'; }
//loop errors
foreach($formErrors as $error){redirecthome("$error");}
// check if not errors procces update
if(empty($formErrors)){
here the wrong code sql ..
$stmt = $con->prepare("INSERT INTO `u926512753_u`.`q` (`username`, `email`, `skill`, `info`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`, `q17`, `q18`, `q19`, `q20`, `q21`, `q22`, `q23`, `q24`, `q25`, `q26`) VALUES (:username, :email, :skill, :info, :q1, :q2, :q3, :q4, :q5, :q6, :q7, :q8, :q9, :q10, :q11, :q12, :q13, :q14, :q15, :q16, :q17, :q18, :q19, :q20, :q21, :q22, :q23, :q24, :q25, ':q26'); ");
$stmt->execute(array(':username' => $fullname, ':email' => $email, ':skill' => $skill, ':info' => $info, ':q1' => $q1, ':q2' => $q2, ':q3' => $q3, ':q4' => $q4, ':q5' => $q5, ':q6' => $q6, ':q7' => $q7, ':q8' => $q8, ':q9' => $q9, ':q10' => $q10, ':q11' => $q11, ':q12' => $q12, ':q13' => $q13, ':q14' => $q14, ':q15' => $q15, ':q16' => $q16, ':q17' => $q17, ':q18' => $q18, ':q19' => $q19, ':q20' => $q20, ':q21' => $q21, ':q22' => $q22, ':q23' => $q23, ':q24' => $q24, ':q25' => $q25, ':q26' => $q26 ));
Like said in a comment above. There is a syntax error due to a quote placed in the VALUES part.
:q25, ':q26'); "); should become :q25, :q26'); ");.

I am trying to save the record in PDO, it does not shows any error and query execute sucessfully, But my record does not save

I am trying to save the record, but when I run this code it execute without any error, but in database it does not show my record inserted.....
This is my Code for saving the records:-
$qre = $conn->prepare("INSERT INTO student_master (`StudentId`, `AddmissionNo`, `AddmissionDate`, `AddmissionYear`, `AddmissionClass`, `StudentCode`, `RegistrationNo`, `EnquiryNo`, `StudentName`, `FatherName`, `MotherName`, `Address`, `City`, `State`, `ClassId`, `SectionId`, `GroupId`, `ClassRollNo`, `Gender`, `BloodGroup`, `DOB`, `DateOfJoining`, `GameId`, `PersonIdMark`, `Caste`, `Religion`, `ConcessionId`, `BoardAddmissionNoIXAndX`, `BoardAddmissionNoXIAndXII`, `BoardRollNoIXAndX`, `BoardRollNoXIAndXII`, `Nationality`, `FatherProfessionId`, `FatherDeptId`, `FatherDesgId`, `FatherBussiness`, `FatherWorkSpace`, `FatherAnnualIncome`, `MotherProfessionId`, `MotherDeptId`, `MotherDesgId`, `MotherBussiness`, `MotherWorkSpace`, `MotherAnnualIncome`, `ResidentPhone`, `FatherCellNo`, `MotherCellNo`, `FatherEmail`, `MotherEmail`, `EmergencyPhone`, `EmergencyCellNo`, `EmergencyContactPerson`, `EmergencyContactRelation`, `BusRateId`, `RouteNo`, `Height`, `Weight`, `VisionLeft`, `VisionRight`, `Teeth`, `OralHygine`, `BrotherSisterDetail`, `SiblingId`, `SessionId`) VALUES (:StudentId, :addmission_no, STR_TO_DATE(:ad_date', '%m/%d/%Y'), :addmission_yr, :addmission_cls, :student_code, :registration_no, :enquiry_no, :student_name, :father_name, :mother_name, :address, :city, :state, :class, :section, :group, :rollno, :gender, :bloodgroup, STR_TO_DATE(:dob', '%m/%d/%Y'), STR_TO_DATE(:doj', '%m/%d/%Y'), :game, :pidmark, :caste, :religion, :concession_cat, :board_addmission_noIX_X, :board_addmission_noXI_XII, :board_roll_noIX_X, :board_roll_noXI_XII, :nationality, :father_prof, :father_dept, :father_desg, :father_bussiness, :father_workplace, :father_annual_income, :mother_prof, :mother_dept, :mother_desg, :mother_bussiness, :mother_workplace, :mother_annual_income, :resident_phone, :father_cell, :mother_cell, :father_email, :mother_email, :emergency_phone, :emergency_cell, :contact_person_emergency, :emergency_contact_relation, :bus_rate, :route_no, :height, :weight, :vision_left, :vision_right, :teeth, :oral_hygiene, :brother_sister_detail,:sibling_id, :session_id)");
$res = $qre->execute(array(
':StudentId' => $StudentId,
':addmission_no' => $addmission_no,
':ad_date' => $addmission_date,
':addmission_yr' => $addmission_yr,
':addmission_cls' => $addmission_cls,
':student_code' => $student_code,
':registration_no' => $registration_no,
':enquiry_no' => $enquiry_no,
':student_name' => $student_name,
':father_name' => $father_name,
':mother_name' => $mother_name,
':address' => $address,
':city' => $city,
':state' => $state,
':class' => $class,
':section' => $section,
':group' => $group,
':rollno' => $rollno,
':gender' => $gender,
':bloodgroup' => $bloodgroup,
':dob' => $dob,
':doj' => $doj,
':game' => $game,
':pidmark' => $pidmark,
':caste' => $caste,
':religion' => $religion,
':concession_cat' => $concession_cat,
':board_addmission_noIX_X' => $board_addmission_noIX_X,
':board_addmission_noXI_XII' => $board_addmission_noXI_XII,
':board_roll_noIX_X' => $board_roll_noIX_X,
':board_roll_noXI_XII' => $board_roll_noXI_XII,
':nationality' => $nationality,
':father_prof' => $father_prof,
':father_dept' => $father_dept,
':father_desg' => $father_desg,
':father_bussiness' => $father_bussiness,
':father_workplace' => $father_workplace,
':father_annual_income' => $father_annual_income,
':mother_prof' => $mother_prof,
':mother_dept' => $mother_dept,
':mother_desg' => $mother_desg,
':mother_bussiness' => $mother_bussiness,
':mother_workplace' => $mother_workplace,
':mother_annual_income' => $mother_annual_income,
':resident_phone' => $resident_phone,
':father_cell' => $father_cell,
':mother_cell' => $mother_cell,
':father_email' => $father_email,
':mother_email' => $mother_email,
':emergency_phone' => $emergency_phone,
':emergency_cell' => $emergency_cell,
':contact_person_emergency' => $contact_person_emergency,
':emergency_contact_relation' => $emergency_contact_relation,
':bus_rate' => $bus_rate,
':route_no' => $route_no,
':height' => $height,
':weight' => $weight,
':vision_left' => $vision_left,
':vision_right' => $vision_right,
':teeth' => $teeth,
':oral_hygiene' => $oral_hygiene,
':brother_sister_detail' => $brother_sister_detail,
':sibling_id' => $sibling_id,
':session_id' => $session_id
));
var_dump($qre->errorInfo());
var_dump($qre->errorCode());
Thanks in advance........

Failed to add user to database, mismatch error? '{"errorInfo":["HY093",0]}'

I cant figure out why this is still giving me a PDO error. I am relatively new to php so any help would be nice.
$query = "INSERT INTO users (userID, email, password, fName, lName, dob,
online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass, :fn, :ln,
dob, :online, :verified, :lli, :gender )";
$queryParams = array(
':id' => 0,
':email' => $_POST['email'],
':pass' => $_POST['password'],
':fn' => $_POST['firstName'],
':ln' => $_POST[':lastName'],
':dob' => $_POST[':dob'],
':online' => $online,
':verified' => $verified,
':lli' => $lli,
':gender' => $gender
);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($queryParams);
var_dump($result->errorCode());
}catch(PDOException $ex){
$response["success"] = 0;
$response["message"] = "Database Error. failed to add user to database";
echo '<pre>';
print_r($result);
echo '</pre>';
die(json_encode($ex));
}
My code keeps popping out this error, I know it means there's a mismatch in the query and the database but i cant figure out where.
you have omit : in dob, change to:
$query = "INSERT INTO users (userID, email, password, fName, lName, dob, online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass, :fn, :ln, :dob, :online, :verified, :lli, :gender )";
You forgot the colon for the dob parameter.
(:id ,:email, :pass, :fn, :ln, :dob, :online, :verified, :lli, :gender
^
Missing : before dob
"INSERT INTO users (userID, email, password, fName, lName, dob,
online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass,
:fn, :ln, :dob, :online, :verified, :lli, :gender )";
^^
$queryParams = array(
':id' => 0,
':email' => $_POST['email'],
':pass' => $_POST['password'],
':fn' => $_POST['firstName'],
':ln' => $_POST[':lastName'],//might be typo
':dob' => $_POST[':dob'],// might be typo
':online' => $online,
':verified' => $verified,
':lli' => $lli,
':gender' => $gender
);
Your variable might need to be as
$_POST[':lastName'] ===> $_POST['lastName']
$_POST[':dob'] ===> $_POST['dob']
Removed those extra colons

phpmyadmin and mysql pdo lastInsertId()

i have this
$query = "INSERT INTO players VALUES (
UUID(),
:firstname,
:lastname,
:age,
:birthplace,
:height,
:weight,
:bats,
:throws,
:position,
:jersey,
:status,
:team,
:image_path
)";
$sth = $db->prepare($query);
$sth->execute(array(
':firstname' => $firstname,
':lastname' => $lastname,
':age' => $age,
':birthplace' => $birthplace,
':height' => $height,
':weight' => $weight,
':bats' => $bats,
':throws' => $throws,
':position' => $position,
':jersey' => $jersey,
':status' => $status,
':team' => $team,
':image_path' => $image_path
));
$id = $db->lastInsertId();
return $id;
and i'm trying to return the last ID that was inserted, and all i'm getting is a 0 returned.
any help is greatly appreciated
thanks
LAST_INSERT_ID() and friends will work only for integer IDs that are created via an AUTO_INCREMENT column. You need to run two queries - first
SELECT UUID() AS newuuid;
then fetch and store this result (e.g. in $uuid), then
"INSERT INTO players VALUES (
:uuid,
:firstname,
:lastname,
...
execute(array(
':uuid' => $uuid,
':firstname' => $firstname,
':lastname' => $lastname,
':age' => $age,
leaving you with the $uuid still valid.

Categories