Where should I should put my INSERT SQL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

Where should I should put my INSERT SQL?

Post by jsk1gcc »

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:

Code: Select all

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. =)
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: Where should I should put my INSERT SQL?

Post by Neilos »

jsk1gcc wrote:should my insert into database sqls go before the submit button inside the form? out side the form? after the button inside the form?
It shouldn't go on the same page on the form unless you are directing the form to itself. In which case it wouldn't matter where it went.
Post Reply