|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
taking the array for a walk
Hi there. I'm trying to walk an array to add quotes to the elements within it. The insertData function below is called and it calls the AddQuotes function. I keep getting an error saying that the addQuotes function does not exist. Any suggestions about what I'm doing wrong would be great.
Thanks. Code:
function addQuotes(&$item, $key)
{
echo $item;
$item = chr(39) . $item . chr(39);
}
function insertData($inputTable, $inputField, $inputValue)
{
#initialise variables
$fieldList = "";
$valueList = "";
$fieldList = implode(",", $inputField);
array_walk ($inputValue, "addQuotes");
$valueList = implode(",", $inputValue);
$query = "INSERT INTO " . $inputTable . " (" . $fieldList . ") VALUES (" . $valueList . ");";
}
echo $query;
$result = mysql_query($query);
if (!$result)
{
print "Insert failed.n";
}
else
{
#print "Inserted ok.";
}
}
|
|
#2
|
|||
|
|||
|
RE: taking the array for a walk
Hmmm...I don't see anything wrong. It works perfectly on the systems I have tried it on....you are sure that the order in which you have them in the file is as they are posted here? I.e., you don't have addQuotes defined after insertData? The only thing I can think of...
|
|
#3
|
|||
|
|||
|
RE: taking the array for a walk
The only thing that's different is that the posted code is part of a file called database.inc and is part of a database class. The class is instantiated in another page and the insertData function of a database object is called.
|
|
#4
|
|||
|
|||
|
RE: taking the array for a walk
It's the class part that is messing it up...change this line:
array_walk ($inputValue, "addQuotes"); to this: array_walk ($inputValue, array($this,"addQuotes")); and all should be well |
|
#5
|
|||
|
|||
|
RE: taking the array for a walk
truly legendary. Thanks Matt. I had tried $this->addQuotes but I was off the mark.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > taking the array for a walk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|