Problem with entering data from multiple table rows.
Posted: Sat Feb 24, 2007 1:44 pm
I had entered this in the Theory and Design section but decided to move it over here for 2 reasons... 1) it's not that complicated or advanced actually
and 2) Noone seemed to give me an answer for 3 days
and i'm in a bit of a hurry. Sorry to mods.
After a roughly superficial search of Theory And Design section and a bit deeper search of Code Snippets i decided to ask for help with this:
I have the need for a code that would echo as many lines (comprised of multiple text-boxes) as the user wants (with radio buttons of course so that it doesnt get over-flowed) in a table and would enter the data in the database that the user entered in the text-boxes.
I've kind of figured out a way of doing the first part, however i have a problem with entering it in the database. However both parts are found in the same file:
All of that seems to work just fine, so that's not the problem. Any suggestions of course for that part are welcome.
The problem comes when i try to do the same thing with entering the data in the database: I use the For statement again in this way:
So basically what it is supposed to do is add a counter at the end of the name for obvious reasons.
I figured out immediately that $_POST[$variable] most probably wouldn't work.
Any ideas and suggestions?
Thx in advance
After a roughly superficial search of Theory And Design section and a bit deeper search of Code Snippets i decided to ask for help with this:
I have the need for a code that would echo as many lines (comprised of multiple text-boxes) as the user wants (with radio buttons of course so that it doesnt get over-flowed) in a table and would enter the data in the database that the user entered in the text-boxes.
I've kind of figured out a way of doing the first part, however i have a problem with entering it in the database. However both parts are found in the same file:
Code: Select all
//These are the lines
for($a = 1; $a <= $_POST[rows]; $a++)
{
echo "<td>";
echo "<tr ......details about the box....><form method='POST' action='dummy.php'><input type='text' name='something" . $a ."'></td>";
echo "<tr ......details about the box....><input type='text' name='somethingelse" . $a ."'></td>";
//.
//.
//.
//.
//goes in same way for some rows, as many as the columns are,
//.
//.
//.
}
echo "</tr><input type='hidden' value='" . $_POST[rows] . "' name='rows'>";
?>
</table>
<p>
<input type="hidden" name="submit" value="0">
<input type="submit" value="Submit">
</form>
</p>
//here the php stops so i don't make too many echos, it just doesnt look wellThe problem comes when i try to do the same thing with entering the data in the database: I use the For statement again in this way:
Code: Select all
for($a = 1; $a <= $_POST[rows]; $a++)
{
$something="something" . $a;
$somethingelse="somethingelse" . $a;
//.
//.
//.
//again going on for some rows...
//.
//.
//Now comes the query, where the error in my thought actually is:
$sqlstatement = "INSERT INTO dummy VALUES('" . mysql_real_escape_string($_POST[$something]) . "', '" . mysql_real_escape_string($_POST[$somethingelse]) . "','"; //it of course doesnt stop there.
$query = mysql_query($sqlstatement, $con); //$con is defined at the beggining of the file and db is considered fully workingI figured out immediately that $_POST[$variable] most probably wouldn't work.
Any ideas and suggestions?
Thx in advance