The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INSERT TO MULTIPLE DB
#1
Hy, I need some help for multiple insert to DB, I can't find where is the problem. Here is the script, can you help me pleasee.

I will like to insert to DB in the same time but the the second tabele to take information and the last id from the first tabele.

https://pastebin.com/LNVhcxcf

Thanks
  Reply
#2
i could be wrong but your using a foreach for the second insert ? remove that foreach and where you entered the $value variables change them to the variables you declared, i believe you have already declared the last id and used it on pro_id, as i say i could be wrong but worh a look
  Reply
#3
thanks for the help.

I have some problems in insert to the second tabele2
all information:

$pro_alte_detalii = Input::get('pro_alte_detalii');
$pro_pachet_mini = Input::get('pro_pachet_mini');
$pro_pachet_mediu = Input::get('pro_pachet_mediu');
$pro_pachet_maxi = Input::get('pro_pachet_maxi');
$pro_tuns = Input::get('pro_tuns');
$pro_spalat = Input::get('pro_spalat');
$pro_uscat = Input::get('pro_uscat');
$pro_taiat_ungi = Input::get('pro_taiat_ungi');
$pro_curatat_urechi = Input::get('pro_curatat_urechi');
$pro_vidat = Input::get('pro_vidat');
$pro_pernute = Input::get('pro_pernute');
$pro_periat = Input::get('pro_periat');
$pro_parfumat = Input::get('pro_parfumat');
$pro_fundita = Input::get('pro_fundita');

is not in the first tabele, I like just to add to the tabele2 in the same submit.

and if I neet for update ? what I need to insert ? I need to updete first tabele and add all information add to the ferst tabele I like to insert in the tabele 2.
  Reply
#4
What is and is not working? Your insert query to table 1 is put your query to table 2 isn't? Is it just missing some of the columns? You could set all of your columns to default of NULL so the insert won't fail and you can find out possibly where the query is going wrong.

If your table 2 query is not working, I am wondering if this is the issue: $pro_id = Input::get('newProId');

You've already defined a variable as newProId, and then you are doing it again, personally I would bypass this as you are just making more work for your script.

And updating - is this separate page, same? Is everything going to be inserted already? If so - check out the DB Class documentation in the update section:
https://userspice.com/documentation-db-class/

Best of luck and let me know if you need anything else, I will do the best I can to help!
  Reply
#5
Hi, thank for helping me.

First your idea from the up post is good you fix some problem but, I will like to add to tabele2 some more information but will not insert from tabele1 is separate from tabele1.

I will post video:
https://www.youtube.com/watch?v=S37fS2Kt...e=youtu.be

  Reply
#6
Thanks for the video, makes it much easier to see how your script works!

One thing I noticed right away but ignored because of your foreach is you have
Code:
$fields
twice - this very well could be your issue. I would change the second array from
Code:
$fields = array(------
to
Code:
$fields2 = array(----------
and change this in your insert statement. This might fix it!

If not I'll dig deeper.
  Reply
#7
is not good, I change but same problem
  Reply
#8
Can you post a new paste or haste?
  Reply
#9
if(!empty($_POST['submit'])){
//Create an array of fields for your insert query
$fields = array(
'pr_nume_username' => Input::get('pr_nume_username'),
'pr_nume' => Input::get('pr_nume'),
'pr_telefon' => Input::get('pr_telefon') ,
'pr_animal_nume' => Input::get('pr_animal_nume'),
'pr_adaugat' => Input::get('pr_adaugat'),
'pr_data' => Input::get('pr_data'),
'pr_ora' => Input::get('pr_ora'),
'pr_kilograme' => Input::get('pr_kilograme'),
'pr_varsta' => Input::get('pr_varsta'),
'pr_sex' => Input::get('pr_sex'),
'pr_vacinat' => Input::get('pr_vacinat'),
'pr_detalii' => Input::get('pr_detalii')
);
$db->insert('propietar',$fields);
$newProId = $db->lastId();

// prepare sql and bind parameters
//Now they are being sanitized too!
//You really don't need to create a variable for each one unless
//you want to use it somewhere else on the page. You could just
//use Input::get down in the array below
$pro_id = Input::get('newProId');
$pro_nume = Input::get('pr_nume');
$pro_telefon = Input::get('pr_telefon');
$pro_animal_nume = Input::get('pr_animal_nume');
$pro_adaugat = Input::get('pr_adaugat');
$pro_data = Input::get('pr_data');
$pro_ora = Input::get('pr_ora');
$pro_vacinat = Input::get('pr_vacinat');
$pro_varsta = Input::get('pr_varsta');
$pro_kilograme = Input::get('pr_kilograme');
$pro_sex = Input::get('pr_sex');
$pro_alte_detalii = Input::get('pr_detalii');
$pro_pachet_mini = Input::get('pro_pachet_mini');
$pro_pachet_mediu = Input::get('pro_pachet_mediu');
$pro_pachet_maxi = Input::get('pro_pachet_maxi');
$pro_tuns = Input::get('pro_tuns');
$pro_spalat = Input::get('pro_spalat');
$pro_uscat = Input::get('pro_uscat');
$pro_taiat_ungi = Input::get('pro_taiat_ungi');
$pro_curatat_urechi = Input::get('pro_curatat_urechi');
$pro_vidat = Input::get('pro_vidat');
$pro_pernute = Input::get('pro_pernute');
$pro_periat = Input::get('pro_periat');
$pro_parfumat = Input::get('pro_parfumat');
$pro_fundita = Input::get('pro_fundita');
$pro_stele = Input::get('pro_stele');
$utilizatorr = Input::get('pr_nume_username');



>----------------THE PROBLEM IS HERE<-----------------

//Create an array of fields for your insert query
$fields2 = array(
'pro_id' => $newProId,
'pro_nume' => $pro_nume,
'pro_telefon' => $pro_telefon ,
'pro_animal_nume' => $pro_animal_nume,
'pro_adaugat' => $pro_adaugat,
'pro_data' => $pro_data,
'pro_ora' => $pro_ora,
'pro_vacinat' => $pro_vacinat,
'pro_varsta' => $pro_varsta,
'pro_kilograme' => $pro_kilograme,
'pro_sex' => $pro_sex,
'pro_alte_detalii' => $pro_alte_detalii,
'pro_pachet_mini' => $pro_pachet_mini, <-------------------
'pro_pachet_mediu' => $pro_pachet_mediu, <-------------------
'pro_pachet_maxi' => $pro_pachet_maxi, <-------------------
'pro_tuns' => $pro_tuns, <-------------------
'pro_spalat' => $pro_spalat, <-------------------
'pro_uscat' => $pro_uscat,<-------------------
'pro_taiat_ungi' => $pro_taiat_ungi,<-------------------
'pro_curatat_urechi' => $pro_curatat_urechi,<-------------------
'pro_vidat' => $pro_vidat,<-------------------
'pro_pernute' => $pro_pernute,<-------------------
'pro_periat' => $pro_periat,<-------------------
'pro_parfumat' => $pro_parfumat,<-------------------
'pro_fundita' => $pro_fundita,<-------------------
'pro_stele' => $pro_stele,
'id_key_sub' => $key,
'utilizatorr' => $utilizatorr
);
//Run the insert.
//to do an insert query, you only need to know what table and an array of fields. This creates, prepares, binds, and sanitizes your db update.

$db->insert('programare',$fields2);

//here is the id of the above query


//Put your sub queries down here...
header('Location: account.php');
}
  Reply
#10
Can you haste your whole scrip at hastebin.com - I need to see your checkboxes too so I can debug this...Also, remove your header from subqueries so we can know if there are any errors that we can't see because of the redirect...

When we put the redirect back in place, use Redirect::to('whatever.php'); instead of Header Location since this is handled from a UC function.
  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)