473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

multiple input boxes


I have a form that I'm creating that queries my database for active users,
puts them in a list and then adds an input box for each line. I'm having
troubles trying to figure out how I would then input the information from
the input box into my table when submitted. Each line lists out the id,
first name, last name from the query, but each input box is named the same.
How would I change the name of each input box?

Hopefully this makes some sense. Thanks for any help that you can provide.

A
Nov 22 '06 #1
5 3581
don't name them the same! :)

if you're going through a loop

$name = $i.'_id';
$name = $i_'first_name';
etc

or, a bit more clever $name = 'user['.$i.'][id];
ie <INPUT name="user[1][id]">
<INPUT name="user[1][first_name]">
<INPUT name="user[1][last_name]">
<INPUT name="user[2][id]">

will create a $_POST var that looks like this when submitted

$_POST = array(
user = array(
1 =array(
'id' ='whatever',
'first_name' ='whatever',
'last_name' ='whatever',
),
2 =array(
'id' ='whatever',
),
),
);
Auddog wrote:
I have a form that I'm creating that queries my database for active users,
puts them in a list and then adds an input box for each line. I'm having
troubles trying to figure out how I would then input the information from
the input box into my table when submitted. Each line lists out the id,
first name, last name from the query, but each input box is named the same.
How would I change the name of each input box?

Hopefully this makes some sense. Thanks for any help that you can provide.

A
Nov 22 '06 #2

please pardon my typos in my post... hopefully you get the idea.

Nov 22 '06 #3

"BKDotCom" <bk***********@yahoo.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>
please pardon my typos in my post... hopefully you get the idea.
Here is where I'm currently at in my programming:

<div align="center">
<table width="300" border="1" cellpadding="4" style='border-collapse:
collapse'>
<tr>
<td width="50" bgcolor="#CCCCCC"><div
align="center"><strong>ID</strong></div></td>
<td width="125" bgcolor="#CCCCCC"><strong>First Name</strong></td>
<td width="125" bgcolor="#CCCCCC"><strong>Last Name</strong></td>
<td width="100" bgcolor="#CCCCCC"><strong>Hours</strong></td>
</tr>

</body>
<?php

include 'config.php';

/*** create a new mysqli object with default database***/
$connection = mysqli_connect($hostname, $username, $password, $dbname) or
die ("Unable to connect");

//create query
$query = "SELECT id, fname, lname FROM prod_employee where active = 'yes'";

//excute query
$result = mysqli_query($connection, $query) or die ("Error in query: $query.
".mysqli_error());

// see if any rows were returned
if (mysqli_num_rows($result) 0) {
// yes
// print them one after another
while (list($id, $fname, $lname) = mysqli_fetch_row($result))
{
echo " <tr>
<td><div align=center>$id</div></td>
<td>$fname</td>
<td>$lname</td>
<td><input name=hours type=text size=4 maxlength=4 />
</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}

// free result set memory
mysqli_free_result($result);

// close connection
mysqli_close($connection);

?>

The input box would be the hours input - I'm not sure I catch on to what you
would do. Thanks for the help.

A
Nov 22 '06 #4

Auddog wrote:
while (list($id, $fname, $lname) = mysqli_fetch_row($result))
{
echo " <tr>
<td><div align=center>$id</div></td>
<td>$fname</td>
<td>$lname</td>
<td><input name=hours type=text size=4 maxlength=4 />
</tr>";
}
The input box would be the hours input - I'm not sure I catch on to what you
would do. Thanks for the help.
perhaps instead of '<input name=hours type=text size=4 maxlength=4 />'
you do ''<input name="'.$id.'_hours" type="text" size=4 maxlength=4
/>''

I assume that 'id' is unique for each from
??

Nov 22 '06 #5
"BKDotCom" <bk***********@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
Auddog wrote:
> while (list($id, $fname, $lname) = mysqli_fetch_row($result))
{
echo " <tr>
<td><div align=center>$id</div></td>
<td>$fname</td>
<td>$lname</td>
<td><input name=hours type=text size=4 maxlength=4 />
</tr>";
}
>The input box would be the hours input - I'm not sure I catch on to what
you
would do. Thanks for the help.

perhaps instead of '<input name=hours type=text size=4 maxlength=4 />'
you do ''<input name="'.$id.'_hours" type="text" size=4 maxlength=4
/>''

I assume that 'id' is unique for each from
??
This will make each input name unique by adding the '.$id.'_ - correct?
which is also the same id for each user? Then I can use the $_POST = array
to input into my database.
Nov 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joey | last post by:
Say a customer inserts into a sql database field (NUMINSERTS) the number 6. On the following page, I want to build a table that displays 6 input boxes, since the customer said they wanted 6 text...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
4
by: Dave Parrin-Bull | last post by:
Hi all, I have been asked (nay told!) to do a quiz for a webpage at work, now I can do the basic things like getting the radio boxes up there and assign values to them but here is what they...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
3
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the...
2
by: murraymiken | last post by:
I'm looking to have multiple multiple-select-boxes on a page. But I can only get the contents from the last selected value within a box, via PHP. I've tried numerous methods. What am I doing...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
6
by: Harshpandya | last post by:
Hi all, I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.