Re: [PHP-DB] Question regarding how-to stop the form inputting empty data at end of the form that is empty due to a carriage return

2005-01-13 Thread Manjiri Mahajan

Hi Mike,

I would suggest that you look for [A-Z],[a-z] and
[0-9] characters and build up your string for Media ID
instead of replacing "\r" and "\n". I have gone
through the same situation for bar code scanning.

Regards,
Manjiri




__ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Question regarding how-to stop the form inputting empty data at end of the form that is empty due to a carriage return

2005-01-11 Thread Rory McKinley
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
//-->





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 .= 'You forgot to enter a Media ID!';
   }
// Set the page title and include the HTML header.
$page_title = 'submit!';
?>

Enter the Tape information into the form below:
Retention:

   4 Weeks
   7 Weeks
   1 Year
   2 Years

Out Date:
 " />

Return Date:
doRCCalendar()

Box ID: 

Media ID:










$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 "You have not entered all information for each 
box.";
}
?>




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


RE: [PHP-DB] Question regarding how-to stop the form inputting empty data at end

2005-01-11 Thread Bastien Koert
if the media_ID field is an autonumber, then there is no need to do anything 
with it...mysql will take the null and generate the next id.

bastien
From: "Mike Millner" <[EMAIL PROTECTED]>
To: 
Subject: [PHP-DB] Question regarding how-to stop the form inputting empty 
data at end of the form that is empty due to a carriage return
Date: Tue, 11 Jan 2005 18:52:10 -0700

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
//-->





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 .= 'You forgot to enter a Media ID!';
   }
// Set the page title and include the HTML header.
$page_title = 'submit!';
?>

Enter the Tape information into the form below:
Retention:

   4 Weeks
   7 Weeks
   1 Year
   2 Years

Out Date:
 " />

Return Date:
doRCCalendar()

Box ID: 

Media ID:










$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 "You have not entered all information for each 
box.";
}
?>




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Question regarding how-to stop the form inputting empty data at end of the form that is empty due to a carriage return

2005-01-11 Thread Santa
В сообщении от Среда 12 Январь 2005 04:52 Mike Millner написал(a):
> 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')
>
>
> How can I get PHP to ignore that line that has empty data in the media_id
> field?

Hi.

May be check $MediaID_ar[$i], and if it empty just not write media_id?
f.e.

$query = "INSERT INTO tape_tracking_test (";
if ( ! empty( $MediaID_ar[$i] ) ){
$query .= "media_id, ";
}
$query.= "retention,out_date,return_date,box_id) values (";

if ( ! empty( $MediaID_ar[$i] ) ){
$query .= "'".$MediaID_ar[$i]."',";
}

$query.= '". $_POST['Retention'] ."=%s','". $_POST['OutDate'] 
."','". $_POST['calendarDate'] ."','". $_POST['BoxID'] ."')";

mysql_query( $query );
bla bla bla

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php