Click to See Complete Forum and Search --> : SQL Insert Not Working..


scottyrob
01-30-2007, 01:06 PM
Hi, im getting this error with the following code and i cant figure out why!

Query failed (INSERT INTO tblExplorerGroup (F_Name, S_Name, Address, Town, Postcode, Mobile_No, Home_No, Email, DoB, Age, Base, Former_Group, Parent1_Name, Parent1_Email, Parent1_Phone1, Parent1_Phone2, Parent2_Name, Parent2_Email, Parent2_Phone1, Parent2_Phone2, YoungLeader, Subscription_Ref, Subscription_Status, GiftAid_Status, NightsAway, Meetings_Attended, VACC_Balanace, Health_Notes, Notes, HomeIssues, Admin) VALUES(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, z, aa, , bb, cc, dd, ee)) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' bb, cc, dd, ee)' at line 1

This error has been reported! Please check back again shortly when we hope to have this error resolved!


<?

include("DbConnect.php");

$ID = $_POST["ID"];
$F_Name = $_POST["F_Name"];
$S_Name = $_POST["S_Name"];
$Address = $_POST["Address"];
$Town = $_POST["Town"];
$Postcode = $_POST["Postcode"];
$Mobile_No = $_POST["Mobile_No"];
$Home_No = $_POST["Home_No"];
$Email = $_POST["Email"];
$DoB = $_POST["DoB"];
$Age = $_POST["Age"];
$Base = $_POST["Base"];
$Former_Group = $_POST["Former_Group"];
$Parent1_Name = $_POST["Parent1_Name"];
$Parent1_Email = $_POST["Parent1_Email"];
$Parent1_Phone1 = $_POST["Parent1_Phone1"];
$Parent1_Phone2 = $_POST["Parent1_Phone2"];
$Parent2_Name = $_POST["Parent2_Name"];
$Parent2_Email = $_POST["Parent2_Email"];
$Parent2_Phone1 = $_POST["Parent2_Phone1"];
$Parent2_Phone2 = $_POST["Parent2_Phone2"];
$YoungLeader = $_POST["YoungLeader"];
$Subscription_Ref = $_POST["Subscription_Ref"];
$Subscription_Status = $_POST["Subscription_Status"];
$GiftAid_Status = $_POST["GiftAid_Status"];
$NightsAway = $_POST["NightsAway"];
$Meetings_Attended = $_POST["Meetings_Attended"];
$VACC_Balance = $_POST["VACC_Balance"];
$Health_Notes = $_POST["Health_Notes"];
$Notes = $_POST["Notes"];
$HomeIssues = $_POST["HomeIssues"];
$Admin = $_POST["Admin"];

$sql = "INSERT INTO tblExplorerGroup (F_Name, S_Name, Address, Town, Postcode, Mobile_No, Home_No, Email, DoB, Age, Base, Former_Group, Parent1_Name, Parent1_Email, Parent1_Phone1, Parent1_Phone2, Parent2_Name, Parent2_Email, Parent2_Phone1, Parent2_Phone2, YoungLeader, Subscription_Ref, Subscription_Status, GiftAid_Status, NightsAway, Meetings_Attended, VACC_Balanace, Health_Notes, Notes, HomeIssues, Admin) VALUES($F_Name, $S_Name, $Address, $Town, $Postcode, $Mobile_No, $Home_No, $Email, $DoB, $Age, $Base, $Former_Group, $Parent1_Name, $Parent1_Email, $Parent1_Phone1, $Parent1_Phone2, $Parent2_Name, $Parent2_Email, $Parent2_Phone1, $Parent2_Phone2, $YoungLeader, $Subscription_Ref, $Subscription_Status, $GiftAid_Status, $NightsAway, $Meetings_Attended, $VACC_Balanace, $Health_Notes, $Notes, $HomeIssues, $Admin)";
$query = mysql_query($sql) or dying_mail("Query failed ($sql) " . mysql_error() . "<br><br>This error has been reported! Please check back again shortly when we hope to have this error resolved!");

echo "<meta http-equiv='refresh' content='0; url=ManageExplorer.php' />";

?>

<script type="text/javascript">
window.alert("The record for <?php echo $F_Name; echo " "; echo $S_Name ?> has been added. You will now be redirected");
</script>


Cheers

bokeh
01-30-2007, 02:33 PM
Your query needs backticks and quotes.INSERT INTO `tablename` (`column-one`, `column-two`) VALUES ('value-one', 'value-two')

Also you are not sanitizing your user input. At the very least use mysql_real_escape_string() (http://www.php.net/mysql_real_escape_string).

scottyrob
01-30-2007, 02:49 PM
$sql = "INSERT INTO `tblExplorerGroup` (`F_Name`, `S_Name`, `Address`, `Town`, `Postcode`, `Mobile_No`, `Home_No`, `Email`, `DoB`, `Age`, `Base`, `Former_Group`, `Parent1_Name`, `Parent1_Email`, `Parent1_Phone1`, `Parent1_Phone2`, `Parent2_Name`, `Parent2_Email`, `Parent2_Phone1`, `Parent2_Phone2`, `YoungLeader`, `Subscription_Ref`, `Subscription_Status`, `GiftAid_Status`, `NightsAway`, `Meetings_Attended`, `VACC_Balanace`, `Health_Notes`, `Notes`, `HomeIssues`, `Admin`, `Username`) VALUES('$F_Name', '$S_Name', '$Address', '$Town', '$Postcode', '$Mobile_No', '$Home_No', '$Email', '$DoB', '$Age', '$Base', '$Former_Group', '$Parent1_Name', '$Parent1_Email', '$Parent1_Phone1', '$Parent1_Phone2', '$Parent2_Name', '$Parent2_Email', '$Parent2_Phone1', '$Parent2_Phone2', '$YoungLeader', '$Subscription_Ref', '$Subscription_Status', '$GiftAid_Status', '$NightsAway', '$Meetings_Attended', '$VACC_Balanace', '$Health_Notes', '$Notes', '$HomeIssues', '$Admin', '$Username')";



Parse error: syntax error, unexpected T_VARIABLE in /home/loddouk1/public_html/secure/ManageExplorerNewSubmit.php on line 43


Why am i get that error (its on that line)

Scott

NightShift58
01-30-2007, 02:55 PM
It looks that way, but it's actually - most probably - on the previous line...

bokeh
01-30-2007, 03:01 PM
No PHP parse error on that line.

NightShift58
01-30-2007, 03:06 PM
Check for a missing semicolon on the previous line or a missing quote...