Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL error on form submit
    primarykey
    data
    text
    <p>UPDATE:</p> <p>Thank you all so much for your help on this. I've taken a different tack and decided to use just one table.</p> <hr> <p>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.</p> <p>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.</p> <p>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:</p> <pre><code>&lt;?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-&gt;setQuery($query); $db-&gt;query(); if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?&gt; </code></pre> <p>The error was for line 11, which would be VALUES line for <code>if($form_id="offense")</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload