Jump to content

Looping Forms


AltarofScience

Recommended Posts

So I made the code as simple as possible to avoid any confusing crap:

 

scripttest.php:

<?php 
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'aosdb';
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
or die ('Error connecting to mysql');
$idcol=7;
$j=0;
$b=1;
mysql_select_db($dbname);
$queryj = "SELECT name FROM IMPrints";
$resultj = mysql_query($queryj);
$num=mysql_num_rows($resultj);
while($j<$num){
$Column = mysql_result($resultj, $j);
echo $Column;
$queryb = "SELECT * FROM IMBuilt WHERE idcol=$idcol";
$resultb = mysql_query($queryb);
$built = mysql_fetch_row($resultb);
include("mysqltest.php");
$j++;
$b++;
}
?>

 

mysqltest.php:

<?php
if($_POST) {
$povar = $built[$b]+$_POST["built"][$j];
$queryi="UPDATE IMBuilt SET $Column = $povar WHERE idcol = $idcol";
mysql_query($queryi);
}
echo $povar;
?>
<form class="bd" method="post" action="scripttest.php"><input type="text" name="built[]"><input type="submit" value="Build"></form>

 

Everything mostly looks fine except one thing:

If I set name="built"

than no matter what form i enter the value to be added in, it affects all the values.

If I set name="built[]"

then no matter what form i enter the value to be added in, it only affects the first value.

 

Currently in the table there are 4 columns. Each form is supposed to edit the column value where idcol=6.

So the first one edits column Basic in the row where idcol is 6.

A value input in the second for should be added to the current value for Column Advanced where idcol=6.

But I can't get the forms, which are produced by the loop, to edit the column they are paired with.

 

In the display in the broswer it lists the column value correctly over each form and also the current value in the table. next to the column.

But it doesn't change the right columns.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.