Jump to content

Multiple entry, 1 click. (not update)


Hooch

Recommended Posts

Is this possible? I want to be able to enter all the railcars we have onsite everyday. The database will have over 1000 railcars, but we may only have 200 onsite.So I have made a query for only onsite cars. Now is it possible to have thisquery updated eveyday with a form, or what would be the best way. If this is possible. Thank you.

Link to comment
Share on other sites

Yes. This is what I have so far. I have done more than this, but nothing is working yet.

<?phpinclude 'db.php';$today0 = date('D F d Y'); // Wed May 07 2003 ?><form name="form1" method="post" action="daily-record_chk.php"><table width="252" border="0" align="center" cellpadding="0" cellspacing="0">  <td colspan="4"><div align="left">  <input type="submit" name="Submit" value="Submit" />  </div></td>  <tr>  <td width="72">  <input name="id" type="hidden" id="id" value="<? echo $row['id']; ?>" />      <input name="date" type="hidden" size="35" value="<? echo $today0; ?>" />  </td>  <td colspan="3"><div align="right"> </div></td>  </tr>    <?     $result = mysql_query("SELECT id, area, carid, commodity, inout FROM railcar WHERE inout = 1 ORDER by area, commodity, carid ASC;")or die(mysql_error());    while($row=mysql_fetch_array($result))     {     ?>  <tr>     <td>  <input name="area" type="text" id="area" value="<? echo $row['area']; ?>" size="12">  </td>  <td colspan="2">  <input name="carid" type="text" id="carid" value="<? echo $row['carid']; ?>" size="18" />  </td>  <td width="72">  <input name="commodity" type="text" id="commodity" value="<? echo $row['commodity']; ?>" size="12" />  </td>  </tr>  <?php  }  mysql_close();  ?></table></form>

I am having a problem with the daily-record_chk.php (line 5) I'm at work right now, if you like I can post that code tonight after 9PM. Maybe it only needs a tweaking. But please let me know if I have this posted code correct. I can tell you it query's the info perfect. thanks..Hooch

Link to comment
Share on other sites

I would like it to enter all the railcars onsite into another table.Here's my 2nd table table

CREATE TABLE `daily-record` (  `id` int(4) NOT NULL auto_increment,  `date` varchar(30) NOT NULL default '',  `area` varchar(20) NOT NULL default '',  `carid` varchar(20) NOT NULL default '',  `commodity` varchar(20) NOT NULL default '',  PRIMARY KEY  (`id`)) TYPE=MyISAM AUTO_INCREMENT=0;

With this table up to 220 railcars per day would be entered. But I have no idea how to enter more than 1 row per submit button. I tried cobbling together a tutorial for multiple updates, but it's not working. At one time I had some entry to the table. But it was entering two rows for every one that should have been there. Then it also put the word array in the fields. But that script is goen. Here is what I was working on before. (right now it isn't entering anything)

<?phpinclude 'db.php';$today0 = date('F d Y'); //May 07 2003$sql="SELECT id, area, carid, commodity, inout FROM railcar WHERE inout = 1 ORDER BY area ASC, commodity ASC, carid";$result=mysql_query($sql);// Count table rows $count=mysql_num_rows($result);?><table width="700" border="0" cellspacing="1" cellpadding="0"><form name="form1" method="post" action=""><tr> <td><table width="698" border="0" cellspacing="1" cellpadding="0"><tr><td width="34" align="center"><strong>Id</strong></td><td width="94" align="center"><strong>Date</strong></td><td width="183" align="center"><strong>Area</strong></td><td width="144" align="center"><strong>Car ID </strong></td><td width="237" align="center"><strong>Commodity</strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){?><tr><td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td><td align="center"><input name="date[]" type="text" id="date" value="<? echo $today0; ?>"></td><td align="center"><input name="area[]" type="text" id="area" value="<? echo $rows['area']; ?>"></td><td align="center"><input name="carid[]" type="text" id="carid" value="<? echo $rows['carid']; ?>"></td><td align="center"><input name="commodity[]" type="text" id="commodity" value="<? echo $rows['commodity']; ?>"></td></tr><?php}?><tr><td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td></tr></table></td></tr></form></table><?php// convert posted info to easy to use variables$date = $_POST['date'];//get date from form$area = $_POST['area'];//get area from form$carid = $_POST['carid'];//get carid from form$commodity = $_POST['commodity'];//get commodity from form// Below is taken from a tutorial from http://www.phpeasystep.com// Check if button name "Submit" is active, do this if($Submit){for($i=0;$i<$count;$i++){$sql1="INSERT INTO daily-record ( `id`, `date`, `area`, `carid`, `commodity` ) VALUES ( id='$id[$i]', '$date[$i]', '$area[$i]', '$carid[$i]', '$commodity[$i]')";$result1=mysql_query($sql1);}}if($result1){header("location:this-page.php");}mysql_close();?>

Link to comment
Share on other sites

Update, FIXED!! Wee Haa!!

<?phpinclude 'db.php';$today0 = date('F d Y'); //May 07 2003$sql="SELECT id, area, carid, commodity, inout FROM railcar WHERE inout = 1 ORDER BY area ASC, commodity ASC, carid";$result=mysql_query($sql);// Count table rows $count=mysql_num_rows($result);?><table width="700" border="0" cellspacing="1" cellpadding="0"><form name="form1" method="post" action=""><tr> <td><table width="698" border="0" cellspacing="1" cellpadding="0"><tr><td width="34" align="center"><strong>Id</strong></td><td width="94" align="center"><strong>Date</strong></td><td width="183" align="center"><strong>Area</strong></td><td width="144" align="center"><strong>Car ID </strong></td><td width="237" align="center"><strong>Commodity</strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){?><tr><td align="center"><? $id=$rows['id']; ?><? echo $rows['id']; ?></td><td align="center"><input name="date" type="text" id="date" value="<? echo $today0; ?>"></td><td align="center"><input name="area" type="text" id="area" value="<? echo $rows['area']; ?>"></td><td align="center"><input name="carid" type="text" id="carid" value="<? echo $rows['carid']; ?>"></td><td align="center"><input name="commodity" type="text" id="commodity" value="<? echo $rows['commodity']; ?>"></td></tr><?php}?><tr><td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td></tr></table></td></tr></form></table><?php// convert posted info to easy to use variables$date = $_POST['date'];//get date from form$area = $_POST['area'];//get area from form$carid = $_POST['carid'];//get carid from form$commodity = $_POST['commodity'];//get commodity from form// Below is taken from a tutorial from http://www.phpeasystep.com// Check if button name "Submit" is active, do this if($Submit){for($i=0;$i<$count;$i++){$sql1 = "INSERT INTO `daily-record` ( `id`, `date`, `area`, `carid`, `commodity` ) VALUES ( '', '$date[$i]', '$area[$i]', '$carid[$i]', '$commodity[$i]')";$result1=mysql_query($sql1);}}if($result1){header("location:daily-record333.php");}mysql_close();?>

Lots of trial and error for that one, but I got it. Thanks guy!!

Link to comment
Share on other sites

Right, you were trying to set the ID. You aren't passing the IDs to the next page though in the form, but you can if you want. If you want to have the ID in the form, so that each entry in the daily table is linked to an entry in the full table, you can change this:<td align="center"><? $id=$rows['id']; ?><? echo $rows['id']; ?></td>to this:<td align="center"><? $id=$rows['id']; ?><input type="hidden" name="id[]" value="<?=$rows['id']?>"><? echo $rows['id']; ?></td>And then you could include the id number of each item from the full table in the daily table. Not necessarily in the ID column, maybe have a car_id or another column to store it in, but you can do that too if you wanted. Or, if you wanted to update the information in a table instead of inserting into a new table, then you would include all of IDs so that you know which row to update.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...