2014-03-30 114 views
-1

我得到錯誤「數組到字符串轉換」在mysql(「插入」)行,我有var_dump ed每個正在使用的變量。這裏是完整的錯誤:我沒有陣列,但我得到「陣列到字符串轉換」在PHP

Array to string conversion in C:\xampp\htdocs\newresident.php on line 33

但是,我沒有看到任何數組,只看到字符串。這可能是電子郵件變量中有@的問題嗎?

<?php 
include 'dbinfo.php'; 
include 'updateinsert.php'; 

$escapedPost = array_map('mysql_real_escape_string', $_POST); 

    $firstname  = $escapedPost['fName']; 
    $lastname  = $escapedPost['lName']; 
    $password1  = sha1($escapedPost['password1']); 
    $gender   = $escapedPost['gender']; 
    $address1  = $escapedPost['address1']; 
    $address2  = $escapedPost['address2']; 
    $city   = $escapedPost['city']; 
    $state   = $escapedPost['state']; 
    $zip    = $escapedPost['zip']; 
    $hPhone   = $escapedPost['hPhone']; 
    $cPhone   = $escapedPost['cPhone']; 
    $wPhone   = $escapedPost['wPhone']; 
    $email   = $escapedPost['email']; 
    $pEmail   = $escapedPost['pEmail']; 

echo $password1; 
var_dump($firstname); 
var_dump($lastname); 
var_dump($password1); 
var_dump($gender); 
var_dump($address1); 
var_dump($address2); 
var_dump($city); 
var_dump($state); 
var_dump($zip); 
var_dump($hPhone); 
var_dump($cPhone); 
var_dump($wPhone); 
var_dump($email); 
var_dump($pEmail); 

mysql_query("CALL sp_User('$email', '$pEmail','$password1', 'Resident')"); 
//uiUser($hospitalemail,$personalemail,$password,"Resident"); 
$userid = getUserByEmail($_POST['email']); 

mysql_query("INSERT INTO ResidentInfo(UserId, NameFirst, NameLast, NameMiddle, Gender, Photo, Address1, Address2, City, State, ZipCode, PhoneNumberHome, PhoneNumberWork, PhoneNumberCell) VALUES ('$userid', '$firstname', '$lastname', NULL,'$gender', NULL, '$address1','$address2','$city','$state','$zip','$hPhone','$wPhone','$cPhone')"); 

?> 

輸出:

string(6) "Fname" 
string(4) "Lname" 
string(40) "cd889c90136db988312a7953bbbbac980de23b03" 
string(1) "M" 
string(14) "24 Olive Ln." 
string(0) "" 
string(10) "Kearny" 
string(10) "New Jersey" 
string(10) "0710907109" 
string(15) "e73879728812345" 
string(15) "e73879728812345" 
string(15) "e73879728812345" 
string(15) "[email protected]" 
string(12) "[email protected]" 
+0

什麼是html元素的性別? –

+1

你'var_dumped'除'$ userid'之外的所有東西... – deceze

+0

哇,你是對的,$ userid是一個內部有另一個數組的數組。上次時間我相信我的朋友的功能在面值。 – Garvin

回答

1
$firstname  = (string)$escapedPost['fName']; 
$lastname  = (string)$escapedPost['lName']; 
... 
... 

使用串分析器,以確保你逝去的字符串。同時使用is_string()進行檢查。

+0

鑄造字符串在這裏做什麼?如果這意味着替代'mysql_real_escape_string',它將無法工作 - 字符串中的任何惡意輸入都將在轉換完成後生存下來! – halfer