PHP PDO:强制转换规范的字符值无效



我正试图通过传递表单中的信息来执行带有输出变量的存储过程,但在提交表单时收到以下错误。

1:integer
2:string
3:string
4:string
5:string
6:string
7:string
8:string
9:string
10:string
11:string
12:string
13:string
14:string
15:string
16:string
17:string
18:string
19:string
20:string
21:string
22:integer
PDOException: SQLSTATE[22018]: [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification in C:xampphtdocsBusinessSolutionclassessignup.classes.php:33 Stack trace: #0 C:xampphtdocsBusinessSolutionclassessignup.classes.php(33): PDOStatement->execute() #1 C:xampphtdocsBusinessSolutionclassesclasses.signupContr.php(73): Signup->setUser('WimpieN', 'Wimpie', 'Norman', 'wimpie.norman@g...', '9806225052084', 'asdffawdsd', '1998-06-22', '1', '0737878209', '1', 'asdawdasd', 'awdasdawd', 'asawf', 'asawdas', '197', '12123', '1124123', 'EBsphere', 'IT Department', 1) #2 C:xampphtdocsBusinessSolutionincludessignup.inc.php(37): SignupContr->signupUser() #3 {main}

我所需要的只是一双新的眼睛,如果你能在下面的代码中识别出这一点。

我真的为混乱的代码道歉,因为我已经改变了很多试图解决这个问题,但我现在没有看到它。

signupinc.php

if(isset($_POST["signup-submit"]))
{
// Grabbing the data
$uid = $_POST["signup-username"];
$firstName = $_POST["signup-firstName"];
$lastName = $_POST["signup-lastName"];
$email = $_POST["signup-email"];
$idNumber = $_POST["signup-id"];
$passport = $_POST["signup-passport"];
$DOB = $_POST["signup-dob"];
$gender = $_POST["signup-gender"];
$contact = $_POST["signup-contact"];
$contactType = $_POST["signup-ContactType"];
$addressline1 = $_POST["signup-address1"];
$addressline2 = $_POST["signup-address2"];
$city = $_POST["signup-city"];
$province = $_POST["signup-province"];
$country = $_POST["signup-country"];
$postalCode = $_POST["signup-postalCode"];
$extension = $_POST["signup-extension"];
$company = $_POST["signup-company"];
$division = $_POST["signup-division"];
$userID = 1;
// Instantite SignupContr class
include "../classes/dbh.classes.php";
include "../classes/signup.classes.php";
include "../classes/classes.signupContr.php";

$signup = new SignupContr($uid,$firstName,$lastName,$email,$idNumber,$passport,$DOB,$gender,$contact,$contactType,$addressline1,$addressline2,$city,$province,$country,$postalCode,$extension,$company,$division,$userID);
// Running error hadnlers and user signupUser
try {
$signup->signupUser();
}
catch (PDOException $e) {
$e->getMessage();
echo $e;
}
// Head back to index.php
header("location: ../index.php?error=none");
}
?>

singup.classes.php

class Signup extends Dbh {
protected function setUser($uid,$firstName,$lastName,$email,$idNumber,$passport,$DOB,$gender,$contact,$contactType,$addressline1,$addressline2,$city,$province,$country,$postalCode,$extension,$company,$division, $userID) {
$proc = '{CALL sp_SYS_AddUser (:token, :uid, :fName, :lName, :email, :id, :pass, :dob, :gender, :contact, :contactType, :address1, :address2, :city, :province, :country:, :postalCode, :extension, :company, :division, :userID, :retval) }';
$stmt = $this->connect()->prepare($proc);
$token = $this->generateRandomString(8) . " - " . $this->generateRandomString(5) . " - " . $this->generateRandomString(5);
$stmt->bindParam(':retval',$ReturnValue ,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,4);
$stmt->bindParam(':token', $token, PDO::PARAM_STR);
$stmt->bindParam(':uid', $uid, PDO::PARAM_STR);
$stmt->bindParam(':fName', $firstName, PDO::PARAM_STR);
$stmt->bindParam(':lName', $lastName, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':id', $idNumber, PDO::PARAM_STR);
$stmt->bindParam(':pass', $passport, PDO::PARAM_STR);
$stmt->bindParam(':dob', $DOB);
$stmt->bindParam(':gender', $gender, PDO::PARAM_STR);
$stmt->bindParam(':contact', $contact, PDO::PARAM_STR);
$stmt->bindParam(':contactType', $contactType, PDO::PARAM_STR);
$stmt->bindParam(':address1', $addressline1, PDO::PARAM_STR);
$stmt->bindParam(':address2', $addressline2, PDO::PARAM_STR);
$stmt->bindParam(':city', $city, PDO::PARAM_STR);
$stmt->bindParam(':province', $province, PDO::PARAM_STR);
$stmt->bindParam(':country', $country, PDO::PARAM_STR);
$stmt->bindParam(':postalCode', $postalCode, PDO::PARAM_STR);
$stmt->bindParam(':extension', $extension, PDO::PARAM_STR);
$stmt->bindParam(':company', $company, PDO::PARAM_STR);
$stmt->bindParam(':division', $division, PDO::PARAM_STR);
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
try {
$stmt->execute();
}
catch (PDOException $e) {
$e->getMessage();
$location = 'file->signup.classes.php | function->setUser()';
$line = '33';
$stmt = null;
echo "1:".gettype($ReturnValue)."</br>";
echo "2:".gettype($token)."</br>";
echo "3:".gettype($uid)."</br>";
echo "4:".gettype($firstName)."</br>";
echo "5:".gettype($lastName)."</br>";
echo "6:".gettype($email)."</br>";
echo "7:".gettype($idNumber)."</br>";
echo "8:".gettype($passport)."</br>";
echo "9:".gettype($DOB)."</br>";
echo "10:".gettype($gender)."</br>";
echo "11:".gettype($contact)."</br>";
echo "12:".gettype($contactType)."</br>";
echo "13:".gettype($addressline1)."</br>";
echo "14:".gettype($addressline2)."</br>";
echo "15:".gettype($city)."</br>";
echo "16:".gettype($province)."</br>";
echo "17:".gettype($country)."</br>";
echo "18:".gettype($postalCode)."</br>";
echo "19:".gettype($extension)."</br>";
echo "20:".gettype($company)."</br>";
echo "21:".gettype($division)."</br>";
echo "22:".gettype($userID)."</br>";
$proc = '{CALL sp_SystemErrorGenerator (:token, :message, :location, :line, :userID, :retval) }';
$stmt = $this->connect()->prepare($proc);
$stmt->bindParam(':retval',$ReturnValue ,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,4);
$stmt->bindParam(':token', $token, PDO::PARAM_STR);
$stmt->bindParam(':message', $e, PDO::PARAM_STR);
$stmt->bindParam(':location', $location, PDO::PARAM_STR);
$stmt->bindParam(':line', $line, PDO::PARAM_STR);
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
try {
$stmt->execute();
echo $e;
exit();
//header("location: ../admin.user.add.php?error=stmtfailed?id=".$ReturnValue);
}
catch (PDOException $e) {
echo 'Execute #2 failed: ' . $e->getMessage();
die();
}
}
if(!$stmt->execute()) {
$stmt = null;
header("location: ../index.php?error=stmtfailed?id=".$ReturnValue);
exit();
}
$stmt = null;
}

class.signupContr.php

class SignupContr extends Signup {
private $uid;
private $firstName;
private $lastName;
private $email;
private $idNumber;
private $passport;
private $DOB;
private $gender;
private $contact;
private $contactType;
private $addressline1;
private $addressline2;
private $city;
private $province;
private $country;
private $postalCode;
private $extension;
private $company;
private $division;
private $userID;
public function __construct($uid,$firstName,$lastName,$email,$idNumber,$passport,$DOB,$gender,$contact,$contactType,$addressline1,$addressline2,$city,$province,$country,$postalCode,$extension,$company,$division,$userID) {
$this->uid = $uid;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->idNumber = $idNumber;
$this->passport = $passport;
$this->DOB = $DOB;
$this->gender = $gender;
$this->contact = $contact;
$this->contactType = $contactType;
$this->addressline1 = $addressline1;
$this->addressline2 = $addressline2;
$this->city = $city;
$this->province = $province;
$this->country = $country;
$this->postalCode = $postalCode;
$this->extension = $extension;
$this->company = $company;
$this->division = $division;
$this->userID = $userID;
}
public function signupUser() {
if($this->invalidUid() == false) {
// echo "Invalid Username!";
header("location: ../index.php?error=invaliduid");
exit();
}
if($this->invalidEmail() == false) {
// echo "Invalid Email!";
header("location: ../index.php?error=invalidemail");
exit();
}
if($this->invalidText() == false) {
// echo "Invalid Text!";
header("location: ../index.php?error=invalidtext");
exit();
}
if($this->validateUser() == false) {
// echo "User Exists";
header("location: ../index.php?error=userexists");
exit();
}
$this->setUser($this->uid,$this->firstName,$this->lastName,$this->email,$this->idNumber,$this->passport,$this->DOB,$this->gender,$this->contact,$this->contactType,$this->addressline1,$this->addressline2,$this->city,$this->province,$this->country,$this->postalCode,$this->extension,$this->company,$this->division,$this->userID);
}

SQL SP:SP_SYS_AddUser

CREATE PROCEDURE sp_SYS_AddUser
(
@token NVARCHAR(MAX),
@username VARCHAR(255),
@firstName VARCHAR(255),
@lastName VARCHAR(255),
@email VARCHAR(255),
@idNumber VARCHAR(255),
@passport VARCHAR(255), 
@DOB DATE,
@gender VARCHAR(10),
@contact VARCHAR(255),
@contactType VARCHAR(255),
@addressLine1 VARCHAR(255),
@addressline2 VARCHAR(255),
@city VARCHAR(255),
@province VARCHAR(255),
@country VARCHAR(255),
@postalCode VARCHAR(255),
@extension VARCHAR(255),
@company VARCHAR(255),
@division VARCHAR(255),
@userID INT,
@status INT OUTPUT
)

我发现了这个问题,你可能会嘲笑这个问题,嘿。当把你的位置放在洞里时,我有一个额外的":"例如一位持有者的值是":国家:";

最新更新