How to read a multible array in the controller

Permalink 1 user found helpful
Dear all,

I have a problem with a single page controller.

I give the controller (via POST) a multivle array (credentials). I can see this array if I make a var_dump in the log.

I split this array with foreach and get x new arrays ($credential). This arrays I can also see in the log if I make a var_dump.

In my database I allways have NULL in the fields.

Here is the code of my save function
public function save(){
      if ($this->post('submit')){
         $date = new DateTime();
         $date = $date->format('Y-m-d H:i:s');
         $u = new User();
         $domainId = $this->post("domainId");
         $credentials = $_POST["credentials"];
         ob_start();
         var_dump($credentials);
         Log::addEntry(ob_get_clean());
         $this->render(var_dump($credentials));
         $db = \Database::get();
         $prepped = $db->Prepare("DELETE FROM spbasfahdprojects WHERE domain = ?");
         $db->Execute($prepped, array($domainId));   
         foreach($_POST["credentials"] as $key => $credential){


And here are some var_damps from the log

CREDENTIALS

C:\wamp64\www\concrete57basf\packages\basf_ahd\controllers\single_page\help\ahd\edit.php:48:
array (size=3)
0 =>
array (size=4)
''domain'' => string '9' (length=1)
''project'' => string 'aaaa' (length=4)
''incident_area'' => string 'aaaaa' (length=5)
''ci'' => string 'aaaaaa' (length=6)
3 =>
array (size=4)
'"domain"' => string '' (length=0)
'"project"' => string 'cccc' (length=4)
'"incident_area"' => string 'ccccc' (length=5)
'"ci"' => string 'cccccc' (length=6)
2 =>
array (size=4)
'"domain"' => string '' (length=0)
'"project"' => string 'bbbb' (length=4)
'"incident_area"' => string 'bbbbb' (length=5)
'"ci"' => string 'bbbbbb' (length=6)

CREDENTIAL

C:\wamp64\www\concrete57basf\packages\basf_ahd\controllers\single_page\help\ahd\edit.php:57:
array (size=4)
''domain'' => string '9' (length=1)
''project'' => string 'aaaa' (length=4)
''incident_area'' => string 'aaaaa' (length=5)
''ci'' => string 'aaaaaa' (length=6)

Thank you in advance

GunterSchmitt
 
hutman replied on at Permalink Best Answer Reply
hutman
I don't see anything glaring, but what happens if you change your query calls to look like this? Looking at the docs it looks like execute is lowercase, not mixed.

$db->execute("INSERT INTO spbasfahdprojects (domain, project, incident_area, ci) VALUES (?, ?, ?, ?)", array(intval($domainId), $credential[project], $credential[incident_area], $credential[ci]));
GunterSchmitt replied on at Permalink Reply 1 Attachment
GunterSchmitt
I changed the function call from "Execute" to "execute" - nothing changed.

I think the problem is that the array has values but if I want to get an value I get NULL.

In the log I can see that the array has values. If I extrakt the values into seperate variables the it turns to NULL.

Log::addEntry(ob_get_clean());
            Log::addEntry("c1 " . $item["project"]);
            Log::addEntry("c2 " . $item[incident_area]);
            Log::addEntry("c3 " . $item["ci"]);


l added the log as png-file.
hutman replied on at Permalink Reply
hutman
It could also be because there are no quotes in the query see $credential[project] needs to be $credential['project']
GunterSchmitt replied on at Permalink Reply
GunterSchmitt
Hi hutman,

as you can see I tied both with the variables C1, C2 and C3.

I'm very confused
hutman replied on at Permalink Reply
hutman
No, I guess I don't see that, because I can't see your log entries, I only see what you output, which looks perfectly fine, but the query looks wrong.
GunterSchmitt replied on at Permalink Reply
GunterSchmitt
Hi hutman,

thank you for all. I found my failure.

In the logfile I've seen that the names of the items has one ' and one " ('"domain"'). This was a failure in the form.

Best Regards
Gunter