rajkumaretl Posted June 29, 2010 Share Posted June 29, 2010 Hi I have two forms ones is html the next is php: 1st form: <html> <body> <form action="insert7.php" method="post"> Firstname: <input type="text" name="firstname" /> Son/Daughter Of: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> SPL_MEMBER: <input type="text" name="SPL_MEMBER"/> WORKER_MEMBER: <input type="text" name="WORKER_MEMBER"/> Ordinary_Member: <input type="text" name="Ordinary_Member"/> CELL: <input type="text" name="CELL"/> GENDER: <input type="text" name="GENDER"/> F_H_Name: <input type="text" name="F_H_Name"/> DOB: <input type="text" name="DOB"/> QUAL: <input type="text" name="QUAL"/> INCOME: <input type="text" name="INCOME"/> Occupation: <input type="text" name="Occupation"/> Address: <input type="text" name="Address"/> Block: <input type="text" name="Block"/> Tehsil: <input type="text" name="Tehsil"/> Distt: <input type="text" name="Distt"/> State: <input type="text" name="State"/> Pin Code: <input type="text" name="Pin Code"/> Tel_Nos_R: <input type="text" name="Tel_Nos_R"/> Tel_Nos_O: <input type="text" name="Tel_Nos_O"/> EMAIL_ID: <input type="text" name="EMAIL_ID"/> EXIST_ID_RCPT: <input type="text" name="EXIST_ID_RCPT"/> TIME_CONTRIB: <input type="text" name="TIME_CONTRIB"/> RCVR_NAME: <input type="text" name="RCVR_NAME"/> RCVR_ID: <input type="text" name="RCVR_ID"/> RCVR_MOB: <input type="text" name="RCVR_MOB"/> DD: <input type="text" name="DD"/> CHEQUE: <input type="text" name="CHEQUE"/> MO: <input type="text" name="MO"/> PAY_SLIP: <input type="text" name="PAY_SLIP"/> OTHER_PAY: <input type="text" name="OTHER_PAY"/> AMOUNT: <input type="text" name="AMOUNT"/> DD_CHQ_SLP_NO: <input type="text" name="DD_CHQ_SLP_NO"/> DD_DT: <input type="text" name="DD_DT"/> ISSUING_BANK: <input type="text" name="ISSUING_BANK"/> DRAW_BANK: <input type="text" name="DRAW_BANK"/> <input type="submit" /> </form> </body> </html> ----------------------------------------2nd form in php with less columns works fine, as below----------------------------------------------<?php $con = mysql_connect("localhost","userid","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql="INSERT INTO persons1 (FirstName, LastName, Age) VALUES ('$_POST[firstname]|$_POST[sPL_MEMBER]|$_POST[WORKER_MEMBER]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> ------------if i change above php form to include all the html columns concatinated(as below), that the php page does not insert a record, please help----------------------------- <?php $con = mysql_connect("localhost","userid","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql="INSERT INTO persons1 (FirstName, LastName, Age) VALUES ('$_POST[firstname]|$_POST[sPL_MEMBER]|$_POST[WORKER_MEMBER]|$_POST[Ordinary_Member]|$_POST[CELL]|$_POST[GENDER]|$_POST[F_H_Name]|$_POST[DOB]|$_POST[QUAL]|$_POST[iNCOME]|$_POST[Occupation]|$_POST[Address]|$_POST[block]|$_POST[Tehsil]','$_POST[lastname]|$_POST[Distt]|$_POST[state]|$_POST[Pin Code]|$_POST[Tel_Nos_R]|$_POST[Tel_Nos_O]|$_POST[email_ID]|$_POST[EXIST_ID_RCPT]|$_POST[TIME_CONTRIB]|$_POST[RCVR_NAME]|$_POST[RCVR_ID]|$_POST[RCVR_MOB]','$_POST[age]|$_POST[DD]|$_POST[CHEQUE]|$_POST[MO]|$_POST[PAY_SLIP]|$_POST[OTHER_PAY]|$_POST[AMOUNT]|$_POST[DD_CHQ_SLP_NO]|$_POST[DD_DT]|$_POST[iSSUING_BANK]|$_POST[DRAW_BANK]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/206193-insert-into-multiple-columns-with-php-mysql/ Share on other sites More sharing options...
kickstart Posted June 29, 2010 Share Posted June 29, 2010 Hi For an insert you need a list of the fields that you are inserting the data into and a list of the values. Both lists are seperated with commas. Any text field value must be surrounded with quotes. You insert appears to be a list of fields and an unrelated list of values. All the best Keith Link to comment https://forums.phpfreaks.com/topic/206193-insert-into-multiple-columns-with-php-mysql/#findComment-1078778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.