Jackanape Posted March 8, 2007 Share Posted March 8, 2007 I've been fiddling with php for a few years now, since taking over admin duties of a phpBB forum. While my skills are adequate to modify and tinker with that, I'm afraid they fall short of functional... I'm trying to put together a simple script that generates a form, and than takes the variables submitted, and inserts them into my mySQL dB. A lot of the syntax is different than I'm used to because I'm working outside of phpBB, so forgive my thickheaded nature. My script easily generates the form as I need it, but I can't suss out how to get it to insert everything once my form is submitted...I've tried foreach() --although probably wrong--and a few other tinkers, to no avail...any help you can offer is always appreciated! if ( isset($HTTP_POST_VARS['submit']) ) { $lines = array(); for ($i = 1; $i < 31; $i++) { $line = $HTTP_POST_VARS['$aid']; $sql = 'UPDATE mlb_teams SET team_line = ' . $line . ' WHERE team_id = ' . $i ; echo 'Line for team' . $i . ' is ' . $line . '. <br />'; if (@mysql_query ($sql)) { print 'Click <a href="ftn.php">HERE</a> to enter another!'; } else { print '<p>Could not add query because: <b>' . mysql_error() . '</b><br>The query was ' . $sql . '</p>'; } } } else { $sql = 'SELECT team_id, team_abbr FROM mlb_teams WHERE team_id != 0'; if ($r = mysql_query ($sql)) { print '<br /> <form method="post">'; while ($row = mysql_fetch_array ($r)) { $id = $row['team_id']; $aid = $row['team_abbr']; print $aid . ': <input class="post" type="text" name="' . $aid . '" size="5" maxlength="5" value="" /><br />'; } print '<br /><br /> Click <input type="submit" name="submit" value="Submit"><br /><br /> </form>'; } else { print '<p>Could not do query because: <b>' . mysql_error() . '</b><br>The query was ' . $sql . '</p>'; } } Link to comment https://forums.phpfreaks.com/topic/41836-newbie-question/ Share on other sites More sharing options...
pocobueno1388 Posted March 8, 2007 Share Posted March 8, 2007 Try changing this: if ( isset($HTTP_POST_VARS['submit']) ) to: if ($_POST['submit']) Link to comment https://forums.phpfreaks.com/topic/41836-newbie-question/#findComment-202897 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 The "isset()" is correct, but $HTTP_POST_VARS is deprecated in favour of $_POST Link to comment https://forums.phpfreaks.com/topic/41836-newbie-question/#findComment-202912 Share on other sites More sharing options...
Jackanape Posted March 8, 2007 Author Share Posted March 8, 2007 Yep, see, there's another bad habit garnered from learning my php via phpBB...I can correct this, but I don't think that's the problem? That works in another form I have running for the same dB, but in this case, it seems I can't even get the submitted data to translate into an array after I hit submit... Do I have to set up a separate form as an html page, and do the handling in longhand? I can do that, but it seems that an array is the answer here, and that's a tough spot for me. None of the submitted variables are forwarding...maybe my document setup is wrong? Right now, it's: if (submitted) {my screwed up array problem here} else {My form, generated by another array, that I have working...} I really just don't know. Link to comment https://forums.phpfreaks.com/topic/41836-newbie-question/#findComment-202946 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 When generating the form fields <?php print $aid . ": <input class='post' type='text' name='line[$id]' size='5' maxlength='5' value='' /><br />"; ?> The values are then posted in an array To process <?php if ( isset($_POST['submit']) ) { foreach ($_POST['line'] as $i => $line) { $sql = 'UPDATE mlb_teams SET team_line = ' . $line . ' WHERE team_id = ' . $i ; } } ?> Link to comment https://forums.phpfreaks.com/topic/41836-newbie-question/#findComment-203039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.