mysql - Using a value from one mysqli query in a second query for PHP -


i'm trying build registration page. i'm trying associate kiddies going camp parent paying camp. i've established foreign key, , these queries run fine in phpadmin.

the first query inserting new kid database works fine. -the second query asking kidid added returns correct value.

however third query, requires result of second query not work. i'm pretty new world , appreciate offered.

require_once 'login.php'; //sending data server.  $mysql = new mysqli($db_hostname, $db_username, $db_password, $db_databasename);    $mysql->query("insert `kid`(`first_name`, `last_name`, `parent1_first_name`, `parent1_last_name`, `parent2_first_name`, `p2_last_name`, `p1_phone`, `p2_phone`, `p1_email`, `p2_email`, `emergencycontact_fname`, `emergencycontact_lname`, `emergencycontact_phone`, `kidstreetaddress`, `kidzip`, `specialneeds`, `dob`, `pickupid`, `kidsex`, `swimid`)          values ('$kidfirstname','$kidlastname','$p1firstname','$p1lastname','$p2firstname','$p2lastname','$p1finphone','$p2finphone','$p1email','$p2email','$efirstname','$elastname','$efinphone','$kidstreetaddress',$kidzip,'$kidspecialneeds','$cdob','$kidpickup','$kidsex',(select `swimid` `swimmingstrength` `swimid` = 1))");  $kidid = $mysql->query("select `kidid` `kid` order `kidid` desc limit 1"); $kidid->data_seek($i); $row = $kidid->fetch_row(); $kidfinid = $row[0];  $mysql->query("insert `customer`(`first_name`, `last_name`, `billing_address`, `billing_zip`, `billing_state`, `billing_phone`, `billing_email`, `kidid`)  values ('$billfirstname','$billlastname','$billfulladdress',$billzip,'$billstate','$billfinphone','$billemail',(select `kidid` `kid` `kidid`=$kidfinid)");  $kidid->close(); $mysql->close(); 

my guess somehow need make sure php grabbing result of second query before running third, not sure how set up.

insert has 2 forms. 1 values , takes constants. other select. 2 not mix.

you want insert . . . select only, used this:

insert `customer`(`first_name`, `last_name`, `billing_address`, `billing_zip`,                         `billing_state`, `billing_phone`, `billing_email`, `kidid`)      select '$billfirstname', '$billlastname', '$billfulladdress', $billzip, '$billstate',            '$billfinphone', '$billemail', `kidid`     kid     `kidid` = $kidfinid; 

in other words, can put constants on select list line. in fact, don't need values form of insert @ all.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -