UPDATE:
Thank you all so much for your help on this. I’ve taken a different tack and decided
to use just one table.
I have a database set up consisting of 3 tables. I have three short forms and I want to use the same add_player.php to write the form data to the database.
Depending on which form is submitted (I have a hidden field defining form_id in each form), data would get written to one of three tables: ff_offense, ff_kicker, ff_defense.
I am getting an unexpected } error. I know my syntax is off, but I’m not well versed enough in PHP to be able to spot the culprit. Here is the code of add_player.php:
<?php
$con = mysql_connect("localhost","dariia","celtic03");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("football", $con);
if($form_id ="offense") {$query="INSERT INTO ff_offense (ID, PLAYER, POSITION, TEAM, PASS_YDS, RUSH_YDS, REC_YDS, RECEPTIONS, TD)
VALUES ('NULL','$_POST[PLAYER]','$_POST[POSITION]','$_POST[TEAM]','$_POST[PASS_YDS]','$_POST[RUSH_YDS]','$_POST[REC_YDS]','$_POST[RECEPTIONS]','$_POST[TD]')"}
elseif($form_id="kicker") {$query="INSERT INTO ff_kicker {K_ID, K_PLAYER, K_TEAM, K_EXTRA_PTS, K_FG)
VALUES ('NULL','$_POST[K_PLAYER]','$_POST[K_TEAM]','$_POST[K_EXTRA_PTS]','$_POST[K_FG]')"}
elseif($form_id="defense") { $query= "INSERT INTO ff_defense {D_ID, D_TEAM, D_SACKS, D_INT, D_TD}
VALUES ('NULL','$_POST[D_TEAM]','$_POST[D_SACKS]','$_POST[D_INT]','$_POST[D_TD]')"} ;
$db->setQuery($query);
$db->query();
if (!mysql_query($query,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
The error was for line 11, which would be VALUES line for if($form_id="offense").
Looks like you are missing some semi-colons after your strings as well.