tet3828 Posted April 27, 2007 Share Posted April 27, 2007 I am trying to use this code to add values to a drop down menu. I can tell the variable is being passed to the correct document(PHP_SELF) however the value will not store into the mysql table. is my syntax incorrect? I've read and copied and pasted several samples of scrips attempting the same task but they are causing parse errors. $fields = mysql_list_fields("21support", "apps", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; echo "<br/>"; echo "Add Software"; if(isset($_POST[software])); $newapp = $_POST[software]; $add_app = " INSERT INTO `apps` ( `$newapp` VALUES (NULL , '$title');"; mysql_query($add_spp); ?> Quote Link to comment Share on other sites More sharing options...
xenophobia Posted April 27, 2007 Share Posted April 27, 2007 You forgot to close your '<option>' tags. for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); echo "</option>" // add this } Quote Link to comment Share on other sites More sharing options...
btherl Posted April 27, 2007 Share Posted April 27, 2007 Try this: $add_app = " INSERT INTO `apps` ( `$newapp` ) VALUES (NULL , '$title');"; mysql_query($add_spp) or die("Error in $add_app\n" . mysql_error()); Quote Link to comment Share on other sites More sharing options...
tet3828 Posted April 27, 2007 Author Share Posted April 27, 2007 okay Im closer now, thank you. but my original syntax inserting the form data was incorrect. The SQL table 'apps' only contains one column and X amount of rows. SO rather than adding a new row with multiple columns I just need to add one new row. That would leave me to believe this syntax would work but it give me a funky error: Error in INSERT INTO `apps` VALUES ('') Column count doesn't match value count at row 1 Which makes no sense to me because I don't want to add columns just rows. $newapp = $_POST[software]; $add_app = " INSERT INTO `apps` VALUES ('$newapp') "; ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.