Page 1 of 1

A little hlep with logic

Posted: Wed Jan 30, 2008 8:43 am
by micknc
Hey guys,

Sorry in advance for the long post but I have to explain what is happening so you can see the logic I am trying to use.

I am building an intranet site for my company that will keep track of our packages as they move through the warehouse. Things are going well and I am learning a lot about php. My newest endeavor is to build an INSERT form that would take two pieces of information from a hand held scanner and put it into MySql. The info would be the package number and the status (or station).

I have already made an easy little drop down form for the office staff to do one package at a time as the paper work goes into the warehouse but I need a form that would do a batch job for them. He wants to be able to preselect his zone and then scan about 30 packages to send the batch out.

Here is what I have been thinking:
I could send him to a page that allows him to choose a zone. Based on that choice I would hard code the 'status' field into the insert and allow the package number to come from the form input.
The problem I am having is this:
If I put one form on the page I can make the scanner scan the code and then hit enter so the scan goes through but when the page refreshes (I am using POST) it is no longer in the form and it requires a click back into the form (no good).
I could do a page with multiple row inserts based on a thread at
http://www.desilva.biz/mysql/insert.html
but if I write a page with 30 form fields and he enters 25 then wouldn't I get a bunch empty fields? I could set the database to reject null in the package field but then he would get an error. (again not the best solution)

So here is the question. Is there a better logical way to go about this? Does anybody have a good idea? Maybe a different type of form page?

Re: A little hlep with logic

Posted: Wed Jan 30, 2008 9:11 am
by micknc
I tried this:

Code: Select all

$sql1 = "INSERT INTO $table (TRACK_STATUS, TRACK_SO_NO)
  VALUES
  ('$_POST[TRACK_STATUS]','$_POST[TRACK_SO_NO1]')";
$sql2 = "INSERT INTO $table (TRACK_STATUS, TRACK_SO_NO)
  VALUES
  ('$_POST[TRACK_STATUS]','$_POST[TRACK_SO_NO2]')";
$sql3 = "INSERT INTO $table (TRACK_STATUS, TRACK_SO_NO)
  VALUES
  ('$_POST[TRACK_STATUS]','$_POST[TRACK_SO_NO3]')";
$sql4 = "INSERT INTO $table (TRACK_STATUS, TRACK_SO_NO)
  VALUES
  ('$_POST[TRACK_STATUS]','$_POST[TRACK_SO_NO4]')";
$sql5 = "INSERT INTO $table (TRACK_STATUS, TRACK_SO_NO)
  VALUES
  ('$_POST[TRACK_STATUS]','$_POST[TRACK_SO_NO5]')";
 
mysql_query($sql1);
mysql_query($sql2);
mysql_query($sql3);
mysql_query($sql4);
mysql_query($sql5);
It works but poulates TRACK_SO_NO is with nothing if the field is blank. Track_status is defined by a drop down at the top of the page.
Is there a code to not post if SO_NO is null.

Re: A little hlep with logic

Posted: Wed Jan 30, 2008 9:49 am
by pickle
The simplest way to do this would be to keep 2 form elements - one selecting the zone & one with the package number - like you had originally. When the form gets submitted, have the zone pulldown automatically "select" the POSTed zone, based on what is in POST. That way, after successive page loads, the zone will stay the same, but still allow the user to change it if necessary.

Oh, and NEVER put raw $_POST data into a query. It should ALWAYS be escaped - you might need to run it through stripslashes() depending on if magic_quotes are on or not (get_magic_quotes_gpc() should help there), and run it through mysql_real_escape_string() as well.