I was wondering if anyone can point me in the right direction. I wanted to create a text box in php where you can input data, separated by commas and the script creates a record for each one.
For example:
I scan multiple bar codes, and in the text box each bar code is its own line. Now when I move to the drop down box it auto separates each with a comma, then in the drop down I can choose the location of where it is, and when I click the "add" button it then creates a new record for each new bar code added to the database. That way, when updating the bar code its "location" can be changed.
Any idea on how to do this? I am lost...
Thanks in advance!
Text box with multiple records
Re: Text box with multiple records
the explode() function is what you need.
http://php.net/explode
Here's sort of what your code would look like
http://php.net/explode
Here's sort of what your code would look like
Code: Select all
foreach( explode(",", $_POST['textbox']) as $key => $value )
{
echo $key ." ". $value . "<br />";
}
Fighting for peace is declaring war on war. If you want peace be peaceful.
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Text box with multiple records
I was wondering if this will work?
Then the INSERT INTO should look like:
I was wondering if this will work? However, if piece1, piece2 and piece3 there in the $rawstring am I only limited to 3 lines in the multiline text box? Due to what we do at work, I would need at least a 200 line limit. When adding data to the database...
Then when the info is added, how can I use the multi-line textbox to do a search on the database and update the record using a drop down box? Please advise...I am needing to get this done as quickly as possible...
Code: Select all
# <?php
# // This is the string, delimited by a comma, rather than a new-line.
# $rawString = "piece1,piece2,piece3";
#
# // Split the string into pieces
# $pieces = explode(",", $rawString);
#
# // Build the top of the INSERT query
# $sql = "INSERT INTO `myTable`(`myField`) VALUES\n";
#
# // Build the rest of the INSERT query by re-assembling the
# // pieces.
# $sql .= "('";
# $sql .= implode("'), ('", $pieces);
# $sql .= "')";
# ?>
Code: Select all
# INSERT INTO `myTable`(`myField`) VALUES
# ('piece1'), ('piece2'), ('piece3')
Then when the info is added, how can I use the multi-line textbox to do a search on the database and update the record using a drop down box? Please advise...I am needing to get this done as quickly as possible...
- Lord Strife
- Posts: 104
- Joined: Wed Oct 28, 2009 3:10 pm
Re: Text box with multiple records
might work 
Code: Select all
<?php
if(isset($_POST['submit']) AND $_POST['textarea'] != '' AND $_POST['location'] != ''){
$info = $_POST['textarea'];
$location = $_POST['location'];
$tapes = explode("\n", $info);
/*foreach ($tapes as $tapenumber) {
$sql = "INSERT INTO tapes(id, tapenumber, location) VALUES('',$tapenumber,$location)";
}*/
foreach ($tapes as $tapenumber) {
echo $tapenumber;
echo "<br/>";
}
echo $location;
}
else{
?>
<form action="test.php" method="post">
<textarea name="textarea" col="30" rows="10"></textarea>
<br />
<select name="location">
<option value="usa">Usa</option>
<option value="mexico">Mexico</option>
</select>
<br />
<input type="submit" name="submit" value="TEST">
</form>
<?php
}
?>
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Text box with multiple records
What I have now:
Code: Select all
<center>
<h1><p><center>Conway ODC TMS - New Tapes</center></p></h1>
<?php
include 'connect.php';
?>
<?php
if(isset($_POST['submit']) AND $_POST['textarea'] != '' AND $_POST['location'] != ''){
$info = $_POST['textarea'];
$location = $_POST['location'];
$tapes = explode("\n", $info);
foreach ($tapes as $tapenumber) {
$sql = "INSERT INTO tapes(id, tapenumber, location) VALUES('',$tapenumber,$location)";
mysql_query($sql) or die("could not update database" . mysql_error());
}
}
else{
?>
<form action="tapeenter.php" method="post">
<textarea name="textarea" col="30" rows="10"></textarea>
<br />
Tape Location:
<select name="location">
<option selected>
<option>tape drive cwy
<option>tape drive lr
<option>Tape Storage Room
</select>
<br />
<input type="submit" name="submit" value="TEST">
</form>
<?php
}
?>
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Text box with multiple records
Thanks to Lord Strife, it is FULLY FUNCTIONAL now...WOOT! Thank you so much! Life saver!
- Lord Strife
- Posts: 104
- Joined: Wed Oct 28, 2009 3:10 pm
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Text box with multiple records
The goal at which I am trying to accomplish is a fully working tape management system. Where basically you use the database to do the following:
Add new tapes (tape number, location, library)
Update tapes (keep the tape number and library the same, but change the location)
Search tapes (Be able to use a field to put x amount of tape numbers and do a search. Show the tape numbers and location of said tape(s))
Delete tapes (Be able to put a tape number(s) in a delete the volumes from the database - admin function)
And a few others, but that's what I am trying to fully accomplish. Then being able to upgrade it to do library searches to show who the customer is, the DBA's, their location, username/password if any, etc.
Thanks to Lord Strife, the Add new tapes function is working successfully, however the updating tapes doesn't work properly. Search and Delete isn't built yet.
Add new tapes (tape number, location, library)
Update tapes (keep the tape number and library the same, but change the location)
Search tapes (Be able to use a field to put x amount of tape numbers and do a search. Show the tape numbers and location of said tape(s))
Delete tapes (Be able to put a tape number(s) in a delete the volumes from the database - admin function)
And a few others, but that's what I am trying to fully accomplish. Then being able to upgrade it to do library searches to show who the customer is, the DBA's, their location, username/password if any, etc.
Thanks to Lord Strife, the Add new tapes function is working successfully, however the updating tapes doesn't work properly. Search and Delete isn't built yet.

