Mike Millner wrote:
Hello everyone,
I have this form that we use for keeping track of tapes we send off site
for storage where I work. The form works almost perfectly with the help
of a few people.
We use a scanner to input the tape id's. The scanner automatically puts
a carriage return at the end of each tape so they all go on seperate lines.
Anyway the question is this: After the last tape is scanned I end up
with a line put into the mysql db that looks like this: (from mysql log
file)
243 Query INSERT INTO tape_tracking_test
(media_id,retention,out_date,return_date,box_id) values
('','7WK=%s','2005-01-11','2005-3-01','006455C5092800')
If you look closely you'll see the first field is '' Single quotes with
nothing in between.
How can I get PHP to ignore that line that has empty data in the
media_id field? I have checking in place to not allow empty fields but
PHP/mysql think that last carriage return is not empty.
I don't want to tell users they have to backspace at the end of the last
tape (which fixes the problem)
I hope I'm explaining this properly. If not I'm sure you guys will let
me know :)
Here is the script:
Above here is javascript for a calendar
//--
/script
/head
Body
body onLoad=showCalendar('now')
?php
if (isset($_POST['submit'])) { // Handle the form.
$message = NULL; // Create an empty new variable.
}
// Check for MediaID.
if (strlen($_POST['MediaID']) 0) {
$MediaID = TRUE;
} else {
$MediaID = FALSE;
$message .= 'pYou forgot to enter a Media ID!/p';
}
// Set the page title and include the HTML header.
$page_title = 'submit!';
?
form action=?php echo $_SERVER['PHP_SELF']; ? method=post
fieldsetlegendEnter the Tape information into the form below:/legend
pbRetention:/bbr
Select name=Retention
option value=4WK4 Weeks/option
option value=7WK7 Weeks/option
option value=1YR1 Year/option
option value=2YR2 Years/option
/select/p
pbOut Date:
/bbr input type=text name=OutDate size=20 maxlength=40
value=?php print date(Y-m-d); ? //p
pbReturn Date:/b
script type=text/javascript
language=JavaScriptdoRCCalendar()/script
pbBox ID:/bbr input type=text name=BoxID size=20
maxlength=40 value=?php if (!empty($_POST['BoxID'])) echo
$_POST['BoxID']; ? //p
pbMedia ID:/bbr
textarea name=MediaID rows=6 cols=24
?php if (!empty($_POST['MediaID'])) echo $_POST['MediaID']; ?
/textarea
form name=submit action=
div align=centerinput type=submit name=date value=Submit
//div
/form
/fieldset
?
$delimiter = \n;
$MediaID_ar = explode($delimiter,$_POST['MediaID']);
$len_ar['MediaID'] = count($MediaID_ar);
$len_ar['Retention'] = strlen($_POST['Retention']);
$len_ar['OutDate'] = strlen($_POST['OutDate']);
$len_ar['ReturnDate'] = strlen($_POST['calendarDate']);
$len_ar['BoxID'] = strlen($_POST['BoxID']);
if(($len_ar['MediaID']) ($len_ar['OutDate'])
($len_ar['ReturnDate']) ($len_ar['BoxID'])) {
define ('DB_USER', 'mysql');
define ('DB_PASSWORD', 'mysql');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'tape_track_db');
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die
(mysql_error());
mysql_select_db (DB_NAME);
for($i=0; $i $len_ar['MediaID']; $i++) {
$MediaID_ar[$i] = str_replace(array(\r,\n),,$MediaID_ar[$i]);
mysql_query (INSERT INTO tape_tracking_test
(media_id,retention,out_date,return_date,box_id) values
('.$MediaID_ar[$i].','. $_POST['Retention'] .=%s','.
$_POST['OutDate'] .','. $_POST['calendarDate'] .','. $_POST['BoxID']
.'));
echo mysql_error();
}
mysql_close();
} else {
echo font color = RedpYou have not entered all information for each
box./p/font;
}
?
/form!-- End of Form --
/body
/html
Hi Mike
I am not sure of the format of the media id, but can you not use a
simple regex so that if mediaID is not of a certain pattern (e.g. all
alphanumeric and a certain length), the relevant corrective action is taken?
Regards
--
Rory McKinley
Nebula Solutions
+27 21 555 3227 - office
+27 21 551 0676 - fax
+27 82 857 2391 - mobile
www.nebula.co.za
--
Rory McKinley
Nebula Solutions
+27 21 555 3227 - office
+27 21 551 0676 - fax
+27 82 857 2391 - mobile
www.nebula.co.za
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php