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

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'); ");.

Related

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........

How to resolve php eden error

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

adding multiple rows in mysql table based on an array

I have a form which allows people to message each other, a user can select multiple people to message, when i submit a form it gives me the name and id of people selected to message in an array. uptil here i am able to get it to work for a single recipient
I want to be able to use this array and INSERT message for each user in different rows of mysql table
this is the array that i get when i submit a form
Array (
[to_user_id] => Array
(
[0] => 54
[1] => 55
)
[subject] => aaa
[message] => bbb
[send_message] =>
this is the part of code that works for a single recipient but not multiple
$to_user_id_array = ($_POST['to_user_id']);
$params = array(
':to_user_id' => $to_user_id_array,
':subject' => $_POST['subject'],
':message' => $_POST['message'],
':sender_id' => $this->user_id,
':status' => "0",
':type' => "message",
':sender_name' => $sender_name,
':to_user_name' => $to_user_name,
':delete_received' => 'no',
':delete_sent' => 'no',
);
$sql = "INSERT INTO `messages` (`sender_id`,`subject`,`comment`,`to_user_id`,`status`,`type`,`sender_name`,`to_user_name`,`delete_received`,`delete_sent`)
VALUES (:sender_id, :subject, :message, :to_user_id, :status, :type, :sender_name,:to_user_name,:delete_received,:delete_sent);";
parent::query($sql, $params);
$this->error = "<div class='alert alert-success'>" . _('Your message has been sent.') . "</div>";
Will really appreciate any help..
This is what worked for me, i hope this helps someone else in similar position
while ($value = $stmt->fetch(PDO::FETCH_ASSOC)) {
$params = array(
':to_user_id' => $value['user_id'],
':subject' => $_POST['subject'],
':message' => $_POST['message'],
':sender_id' => $this->user_id,
':status' => "0",
':type' => "message",
':sender_name' => $sender_name,
':to_user_name' => $value['name'],
':delete_received' => 'no',
':delete_sent' => 'no',
);
$sql = "INSERT INTO `messages` (`sender_id`,`subject`,`comment`,`to_user_id`,`status`,`type`,`sender_name`,`to_user_name`,`delete_received`,`delete_sent`)
VALUES (:sender_id, :subject, :message, :to_user_id, :status, :type, :sender_name,:to_user_name,:delete_received,:delete_sent);";
parent::query($sql, $params);
}

Trouble with PDO update

I am updating a form using PDO's update function. For some reason it is not going through.
Here is code:
$data = "UPDATE insuranceverificationdisclaimer SET InsCoName =:insur, PhoneNumber = :phone, Policy = :policy, InsuredName = :insurname
, MailingAdrs = :mailingad, EffDate = :effdate, ExpDate = :expdate, Email1 = :email, YrVehicle = :yr, Make = :make
, Model = :model, VIN = :vin, TraineeUserName = :user, EmpName = :empname, EmpCoName = :empcomp, AgencyNumber = :agnum
, SignDate = :signdate, AgentName = :agname, AgentPhone = :agphone, AgentEmail = :agemail, Combinedlimit = :csl, bodyinjur = :body
, bodyinjureachacc = :acc
, propertydmg = :prop WHERE TraineeUsername = :user";
echo"1";
$insertdata = $DBH->prepare($data);
$insertdata->execute(array(':insur' => $compname, ':phone' => $phone , ':policy' => $policynum, ':insurname' => $nameofPolicyholder
, ':mailingad' => $newMailingAdrs, ':effdate' => $Policyeffdate, ':expdate' => $Policyexpdate, ':email' => $newEmployeeEmail
, ':yr' => $YearOfVehicle, ':make' => $MakeOfVehicle, ':model' => $ModelOfVehicle, ':vin' => $Vehicleid, ':user' => $username, ':empname' => $EmployeeName, ':empcomp' => $EmployeeCompanyName, ':agnum' => $Agencynum
, ':signdate' => $TodaysDate, ':agname' => $agentname, ':agphone' => $agentphone, ':agemail' => $agentemail, ':csl' => $singlelimit
, ':body' => $bodyinjur, ':acc' => $eachacc, ':prop' => $propertydmg ));
Where , ':csl' => $singlelimit, ':body' => $bodyinjur, ':acc' => $eachacc, ':prop' => $propertydmg begins this is the function that is not working, these are ints in the database and the values are ints. If I remove from the select and the array it will work but besides that it will not.
Let me know if you need anything else!
UDATED---------------------------
Wont go through once you hit execute page just stays white.
You should turn on your error reporting as suggested by Michael Berkowski. For now I can only assume that the error is cause by params datatypes not being defined. You can try the following:
$insertdata->bindParam(':insur', $compname, PDO::PARAM_STR);
$insertdata->bindParam(':csl', $singlelimit, PDO::PARAM_INT);
//...bind the other params
$insertdata->execute();

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