jsk1gcc Posted January 11, 2011 Share Posted January 11, 2011 Just a quick question I have a form, couple of drop down boxes, input fields etc.. at the end is the submit button. now my question is should my insert into database sqls go before the submit button inside the form? out side the form? after the button inside the form? If by any chance you could give me some advice on the best way to layout my sql that would be great. They are big and go into three tables, at the moment I have them as three seperate queries but I think they must be able to go into one. can someone please help me with the layout and syntax. here is what the queries look like at the moment: if ($IBselect=$_POST ['IBselect']); { //CUSTOMER $enterCust="INSERT INTO customer(username, password, title, firstName, lastName, address, town, country, postCode, phone, email, dateCust) VALUES ('$_POST[username]', '$_POST[password]', '$_POST[title]', '$_POST[firstName]', '$_POST[lastName]', '$_POST[address]', '$_POST[town]', '$_POST[country]', '$_POST[postCode]', '$_POST[phone]', '$_POST[email]', 'DATE: Auto CURDATE()', CURDATE()"; $enterCust_query=mysql_query($enterCust)or die(mysql_error()); //CARD $enterCard="INSERT INTO card(cardNumber, name, expDate, cardID) VALUES ('$_POST[cardNumber]','$_POST[name]', ' $_POST[expDate]', '$_POST[cardID]')"; $enterCard_query=mysql_query($enterCard); //BOOKING $RCenterBook=mysql_query("INSERT INTO booking (custNumber, cardID, rideName, seatNo1, seatNo2, price, price2, dateBook, ID_time_tbl) VALUES ('$custNumber', '$_POST[cardID]', '$rideName', '$_SESSION[iBextract]', '$_SESSION[iBextract2]', '$IBendPrice1', '$IBendPrice2', 'DATE: Auto CURDATE()', CURDATE()', '$_SESSION[iB_slot_Time]'"); $IBenterBooking_query=mysql_query($IBenterBook); if (!mysql_query($enterCard, $enterCust, $IBenterBook)) { die("Error:" .mysql_error()); } echo "1 record added IB"; } Thanks =) Quote Link to comment https://forums.phpfreaks.com/topic/224125-where-should-i-should-put-my-insert-sql/ Share on other sites More sharing options...
Rifts Posted January 11, 2011 Share Posted January 11, 2011 have your form action="process.php" create a process.php file and have that code you pasted in there. Quote Link to comment https://forums.phpfreaks.com/topic/224125-where-should-i-should-put-my-insert-sql/#findComment-1158097 Share on other sites More sharing options...
Pikachu2000 Posted January 11, 2011 Share Posted January 11, 2011 Typically, when submitting a form to itself for processing by PHP, you'd want to keep the code before the html starts to output, especially if you'll be using header() redirects, or need to display the resulting data. Quote Link to comment https://forums.phpfreaks.com/topic/224125-where-should-i-should-put-my-insert-sql/#findComment-1158100 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.