RE: Question regarding how-to stop the form inputting empty data at end

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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" <mike@xxxxxxxxxxxxx>
To: <php-db@xxxxxxxxxxxxx>
Subject: 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

//-->
</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 .= '<p>You 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">
<fieldset><legend>Enter the Tape information into the form below:</legend>


<p><b>Retention:</b><br> <Select name="Retention"> <option value="4WK">4 Weeks</option> <option value="7WK">7 Weeks</option> <option value="1YR">1 Year</option> <option value="2YR">2 Years</option> </select></p>

<p><b>Out Date:
</b><br> <input type="text" name="OutDate" size="20" maxlength="40" value="<?php print date("Y-m-d"); ?>" /></p>


<p><b>Return Date:</b>
<script type="text/javascript" language="JavaScript">doRCCalendar()</script>


<p><b>Box ID:</b><br> <input type="text" name="BoxID" size="20" maxlength="40" value="<?php if (!empty($_POST['BoxID'])) echo $_POST['BoxID']; ?>" /></p>


<p><b>Media ID:</b><br> <textarea name="MediaID" rows="6" cols="24"> <?php if (!empty($_POST['MediaID'])) echo $_POST['MediaID']; ?>



</textarea>


<form name="submit" action="">
<div align="center"><input 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 = Red><p>You have not entered all information for each box.</p></font>";
}
?>


</form><!-- End of Form -->
</body>
</html>

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux