Hi,
i have this custom PHP code for saving data into table in a cycle foreach()
but don't work.
If i write this
it's ok.
If i write this
it's ok too.
But if i add "foreach cycle" and "INSERT query" it don't work.
Why?π(((((
P.S.: Sorry for my english
i have this custom PHP code for saving data into table in a cycle foreach()
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb as $a)
{
$db =& JFactory::getDBO();
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','$a['id']','3')";
$db->setQuery($query);
$db->query();
}
?>
but don't work.
If i write this
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb as $a)
{
echo $a['id'];
}
?>
it's ok.
If i write this
<?php
$db =& JFactory::getDBO();
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','2','3')";
$db->setQuery($query);
$db->query();
?>
it's ok too.
But if i add "foreach cycle" and "INSERT query" it don't work.
Why?π(((((
P.S.: Sorry for my english
Hi pierpari,
I think ti is a problem with quotes. Please try
Bob
I think ti is a problem with quotes. Please try
VALUES ('','','','','','{$a['id']}','3')
Bob
Hi Bob,
thank you for answer but the problem it isn't this.
I tried also this and don't work too
thank you for answer but the problem it isn't this.
I tried also this and don't work too
VALUES ('','','','','','3','3')
Hi pierpari,
I would add a line of Debug code to output the query that is being created then test that in PHPMyAdmin to see what the error is.
Bob
I would add a line of Debug code to output the query that is being created then test that in PHPMyAdmin to see what the error is.
Bob
Debugger write only the array
Array
(
[option] => com_chronoforms5
[view] => form
[Itemid] => 127
[chronoform] => Listino_insert
[event] => submit
[prezzo] =>
[button2] => Submit
[SERVIZI] => Array
(
[0] => Array
(
[id] => 2
[uniq_id] =>
[user_id] => 0
[created] => 2014-02-18 14:25:03
[modified] =>
[servizio] => shampoo
)
β¦β¦
$db =& JFactory::getDBO();
$servizio_id = '27';
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','$servizio_id','3')";
$db->setQuery($query);
$db->query();
this workβ¦.
if i add foreach cycle it don't work
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb ad $a)
{
$db =& JFactory::getDBO();
$servizio_id = '27';
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','$servizio_id','3')";
$db->setQuery($query);
$db->query();
}
?>
But this foreach cycle work
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb as $a)
{
echo $a['id'];
}
?>
I don't know how but now it's right
Thanks Bob for your time
<?php
$bb=$form->data['SERVIZI'];
$db =& JFactory::getDBO();
foreach ($bb as $a)
{
$servizio_id = $a['id'];
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','$servizio_id','3')";
$db->setQuery($query);
$db->query();
}
?>
Thanks Bob for your time
This topic is locked and no more replies can be posted.
