PAGO Posted March 12, 2014 Share Posted March 12, 2014 Hey, I come right to the problem. I tried to do an Insert. It contains a Select where i retrieve Data from another Table and Variables. $sqlbestellungen = "INSERT INTO bestellungen (bestellung_id_kunde, datum, lieferzeit, bestellung, summe) VALUES ((SELECT id_kunde FROM kunde WHERE email = '$email'), NOW(), '$lieferzeit', '$bestellung', '$summe')"; mysqli_query($con,$sqlbestellungen); When I write the query only with the Select, without "VALUES" and without the Variables, it works. When I write the query only with the Variables, with "VALUES", it works too. I just can't combine them. and when i write two seperate INSERTS it makes two rows. And I need to have it in one. Thanks in advance, PAGO Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted March 12, 2014 Solution Share Posted March 12, 2014 (edited) Not sure on INSERT SELECT try $sqlbestellungen = "INSERT INTO bestellungen (bestellung_id_kunde, datum, lieferzeit, bestellung, summe) SELECT id_kunde, NOW(), '$lieferzeit', '$bestellung', '$summe' FROM kunde WHERE email = '$email'"; Edited March 12, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 12, 2014 Share Posted March 12, 2014 Yeah, can't use a SELECT for only some of the values. As Ch0cu3r showed, just use a SELECT for all the values of the record and just use hard coded values in the field list for those that you want to specifically set. Quote Link to comment Share on other sites More sharing options...
PAGO Posted March 12, 2014 Author Share Posted March 12, 2014 Great! it works. This method just didn't make sense for me, because the part till "from..." is not relevant for the variables. Thank you very, helped me a lot Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 12, 2014 Share Posted March 12, 2014 A select clause does not strickly require column names to be refernced, it can be made of either column names, functions and values (wrapped in quotes). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.