Jump to content

Where should I should put my INSERT SQL?


jsk1gcc

Recommended Posts

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 =)

Link to comment
https://forums.phpfreaks.com/topic/224125-where-should-i-should-put-my-insert-sql/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.