Re: probably stupid, but...

From: Date: Fri, 12 Nov 2004 20:41:18 +0000
Subject: Re: probably stupid, but...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-201866@lists.php.net to get a copy of this message
You've got some parsing errors going on. Nothing particularly wrong with the logic...
$i=1; while ($i<20) { if ($_POST[book_title_$i]' != "")
change the if statement to: if ($_POST["book_title_$i"] != "") The problem you have is that the $_POST var you're referencing, first of all, isn't included in quotation marks, so the code probably thinks it's a constant that's not defined. Second of all, because it's not included in quotation marks, it's having problems with adding the $i var to the end of the POST var name. You could also do: $_POST['book_title_' . $i] and achieve the same effect. Lastly, what's that single quotation mark doing in there? Get rid of it.
{ INSERT INTO curriculum VALUES ('','$_POST[book_title_$i]','$_POST[book_level_$i]','$_POST[level_grades_$i]','$_POST[book_section_$i]','$_POST[chapter_$i]','$_POST[chapter_title_$i]','$_POST[lesson_title_$i]','$_POST[skill_$i]','$_POST[life_skill_$i]','$_POST[success_indicator_$i]','$_POST[ncscos_$i]','$_POST[subject_$i]','$_POST[pages_$i]','$_POST[c_kit_$i]');
First of all, you're trying to execute a SQL statement, but you're not saving it to a variable, nor are you executing it against any kind of database. So, it's doing nothing. Save it to a variable by doing: $sql = "INSERT INTO ... The next thing you need to worry about is how to get your $_POST variables into the SQL statement. This problem is similar to what you have above. It should look something like this: $sql = "INSERT INTO curriculum VALUES ('','" . $_POST['book_title_' . $i] . "','" . $_POST['book_level_' . $i] . "','" ..... and so on Lastly, you'll need to execute the statement against a database. Turn to the PHP manual for this help: <http://www.php.net/mysql> I would suggest you read up on how variables get processed, as well. <http://www.php.net/variables>
$message .= "The entry $i was entered "; $i++; } else { $i++; } } But I get THIS error in the log: [12-Nov-2004 14:59:19] PHP Parse error: parse error, unexpected T_VARIABLE, expecting ']' in /home/public/html/depts/fourh/curriculum_form_post.php on line 19 ------------- How can I go about iterating through the script? or do I just need to write 20 if/else statements and separate inserts?
-- Ben Ramsey Zend Certified Engineer http://benramsey.com --------------------------------------------------- Atlanta PHP - http://www.atlphp.org/ The Southeast's premier PHP community. ---------------------------------------------------

« previous php.general (#201866) next »