Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,674 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,211 people online right now. Registration is fast and FREE... Join Now!




multiple text fields in a php form

2 Pages V  1 2 >  
Reply to this topicStart new topic

multiple text fields in a php form, how do i send multiple entries to the next page?

chris_drappier
post 2 Jul, 2007 - 11:22 AM
Post #1


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


okay, i'm trying to make a form that i can use to change quantities for
items in a database that has one table with these columns:
rec_id = auto increment primary key
brand = varchar
description = varchar
category = varchar
sub_category = varchar
quantity = int
I have a drop down that sorts
all items by category included in the main page. That form creates a table on a new page that displays the item, current quantity and a field for inputting the new quantity done like so:
CODE

    <form action= "test.php" method= "post">
        <table>
        <tr>
            <th>brand</th>
            <th>item</th>
            <th>sub_category</th>
            <th>color</th>
            <th>present quantity</th>
        </tr>
    <?php
            // Print out the contents of each row into a table
        while($row = mysql_fetch_array($result)){
        echo "<tr>"                               ;
        echo "<td>" . $row['brand']       . "</td>";
        echo "<td>" . $row['description'] . "</td>";
        echo "<td>" . $row['sub_category']. "</td>";
        echo "<td>" . $row['color']       . "</td>";
        echo "<td>" . $row['quantity']    . "</td>";
        echo "<td><input type= text name= " . $row['rec_id'] . "[]></td>";
        echo "</tr>"                              ;
        }
    ?>
        </table>
    <input type= "submit" name= "test" value= "submit" >
    </form>


This returns a table that has an input field for each item listed. I need
to be able to put a quantity in any number of those fields, and have it
update the quantity in the database. I also need it to leave blank fields
alone. So, my query on the page that is supposed to process that form
looks like this:

CODE

$query = "UPDATE quantity SET items.quantity = '$quantity' WHERE
items.rec_id = '$rec_id'";


This works for one of the rows if i set $rec_id = $_POST['whatever'] and
$quantity = $_POST['whatever']

I can't figure out how to:
$quantity = the number I entered in the row
$rec_id = the primary key associated with that row

I tried to include pertinent info without extraneous info, so let me know
if this makes any sense.

I really would apprieciate your help on this, it's had me stumped for a
couple of days.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 2 Jul, 2007 - 11:33 AM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


CODE

<?php
echo "<input type=hidden name=Whatever value=".$rec_id.">";
echo "<input type=hidden name=Whatever value=".$quantity.">";
?>

CODE

<html>
<input type=hidden name=Whatever value="<php echo $rec_id; ?>">
<input type=hidden name=Whatever value="<php echo $quantity; ?>">
</html>

User is offlineProfile CardPM

Go to the top of the page

chris_drappier
post 2 Jul, 2007 - 12:11 PM
Post #3


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


QUOTE(no2pencil @ 2 Jul, 2007 - 12:33 PM) *

CODE

<?php
echo "<input type=hidden name=Whatever value=".$rec_id.">";
echo "<input type=hidden name=Whatever value=".$quantity.">";
?>

CODE

<html>
<input type=hidden name=Whatever value="<php echo $rec_id; ?>">
<input type=hidden name=Whatever value="<php echo $quantity; ?>">
</html>




Not quite what I'm doing here. 'whatever' has to be a variable based on which row I'm updating. and in the second piece of code, $rec_id and $quantity are the variables that I need to set. This is a form that has multiple text inputs, with one submit button. When it is submitted, it should update the quantity column in the rows that have a value entered into them.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 2 Jul, 2007 - 07:08 PM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


The code I provided sends the data from html to php. It's important when working with php to understand which side the code will execute. The html/javascript executes client side & the php executes server side. You can use the hidden field inside of <form> tags to send php variables to POST data. That's what you asked for. If you need to update the sql values, that's done using sql statments.
User is offlineProfile CardPM

Go to the top of the page

Styx
post 3 Jul, 2007 - 05:26 PM
Post #5


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


So, for each of those fields you have there, you want to be able to update them based on rec_id, or just the quantity for each row listed based on rec_id? Also, do you want to update all of the rows in one fell swoop, or individually? This is kind of confusing.

All you have is one text input field that turns out to be some rec_id made into its own array. And your $_POST['whatever'] examples makes it even more unclear what you are trying to do.
User is offlineProfile CardPM

Go to the top of the page

chris_drappier
post 5 Jul, 2007 - 02:26 PM
Post #6


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


QUOTE(Styx @ 3 Jul, 2007 - 06:26 PM) *

So, for each of those fields you have there, you want to be able to update them based on rec_id, or just the quantity for each row listed based on rec_id? Also, do you want to update all of the rows in one fell swoop, or individually? This is kind of confusing.

All you have is one text input field that turns out to be some rec_id made into its own array. And your $_POST['whatever'] examples makes it even more unclear what you are trying to do.



i want to update the quantity field in each row based on their rec_id (which is the primary key) each one has it's own text input that is named by its rec_id and i want to be able to do this with one submit button.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 5 Jul, 2007 - 02:50 PM
Post #7


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


The $_POST value will be the variables that you are passing.

$_POST['rec_id'] for example. That is why you want to include a hidden value when you pass it over the form.
User is offlineProfile CardPM

Go to the top of the page

Styx
post 5 Jul, 2007 - 08:47 PM
Post #8


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


And then, you could either have a button next to each one to update it (each having their own little form) or loop through the rec_id array and update the values (each part of a larger form).
User is offlineProfile CardPM

Go to the top of the page

chris_drappier
post 6 Jul, 2007 - 05:50 AM
Post #9


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


QUOTE(Styx @ 5 Jul, 2007 - 09:47 PM) *

And then, you could either have a button next to each one to update it (each having their own little form) or loop through the rec_id array and update the values (each part of a larger form).



That's what I'm doing on the form, i have a loop through the rec_id like this
CODE


        while($row = mysql_fetch_array($result)){
        echo "<td><input type= text name= " . $row['rec_id'] . "></td>";


my problem is getting each rec_id to the next document without having to say

$_POST['1'], $_POST['2'], etc. all the way up to 155.

I have attached a mysql dump from the database as a text document, also the three .php's that i'm working with. cat_sort is the first page in line where you select your category, cat_sort_table is the second page where the form i'm having trouble with is. and test is the page the post data is sent to.



Attached File(s)
Attached File  inventorydump.txt ( 25.28k ) Number of downloads: 33
Attached File  cat_sort.php ( 848bytes ) Number of downloads: 34
Attached File  cat_sort_table.php ( 1.83k ) Number of downloads: 32
Attached File  test.php ( 721bytes ) Number of downloads: 37
User is offlineProfile CardPM

Go to the top of the page

chris_drappier
post 6 Jul, 2007 - 05:55 AM
Post #10


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


QUOTE(no2pencil @ 5 Jul, 2007 - 03:50 PM) *

The $_POST value will be the variables that you are passing.

$_POST['rec_id'] for example. That is why you want to include a hidden value when you pass it over the form.



I just don't understand where the hidden value will fit in. I don't have much experience with forms and I looked it up on wc3 and google and have a general understanding of how hidden values work, but I can't see how it fits into my delimma. If you could elaborate a little, I would be most appreciative.
I posted the files that i'm working with in another reply if you'd like to take a look at them. On a personal note, DIC is win and receives one internet smile.gif
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 6 Jul, 2007 - 05:57 AM
Post #11


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,846



Thanked 45 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


Use a loop wink2.gif

Name your fields like this: name_$rec_id, address_$rec_id, etc.

Then loop over the record id's to get each field for the corresponding record id.
User is offlineProfile CardPM

Go to the top of the page

chris_drappier
post 6 Jul, 2007 - 06:24 AM
Post #12


New D.I.C Head

*
Joined: 10 Apr, 2007
Posts: 34


My Contributions


can you give me an example of this loop? It sounds like the loop i have in the actual form, but how can i use such a loop to get all of the post data? do you put the loop in $_POST[] somehow? i tried that before like:

CODE

$_POST[ while($row = mysql_fetch_array($result)){
echo $row['rec_id'];
}
]


but of course, I got a syntax error. is that anything like what you mean? or am I way off base here.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:24AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month