PDA

View Full Version : Possible to add multiple fields to mysql?


bsxiong
10-08-2007, 11:29 AM
Hi all,

this is my code to insert information to my database:

<style type=text/css>body {font-family:verdana; font-size:12px;}.table{ font-size: 12px}</style>
<form name="classroom" action="/index.php" method="post">
<table width="500" border="0" cellspacing="0" cellpadding="5" class=table>
<tr>
<td bgcolor=#F5F5F5>Your Name: </td>
<td><input name="name" value=""></td>
</tr>
<tr>
<td>Title of Problem: </td>

<td><input name="title"></td>
</tr>
<tr>
<td>Date:<font color=gray><br>Year-Month-Day<br>2007-09-28</font> </td>
<td><input name="date"></td>
</tr>
<tr>

<td>Room Number:</td>
<td><input name="room" maxlength=3></td>
</tr>
<tr>
<td>Computer Number:<font color=gray><br>(eg 09)</font> </td>
<td><input name="computer_number" maxlength=2></td>
</tr>

<tr>
<td>Problem Type: </td>
<td><select name="problem_type">
<option value="">Please Select One</option>
<option value="Library">Library</option>
<option value="Chat">Chat</option>
<option value="Internet">Internet</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>

<td>Problem Summary : </td>
<td><textarea name=problem_summary cols=40 rows=10></textarea></td>
</tr>
<tr>
<td>What did you do? </td>
<td><textarea name=action cols=40 rows=10></textarea></td>
</tr>

<tr>
<td>Instructor's Name: </td>
<td><input name="instructor_name"></td>
</tr>
<tr>
<td>Instructor's Course/Dept: <font color=gray><br></font> </td>
<td><input name="course"></td>

</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table></form>



for example: Currently, the code only let you submit one field at a time. So then there is a little problem if....say we have 9 computer with the same problem. I don't want to have to submit 9 different times. Is there a way to just have a check box or something like that.

So if say i computer number 7,8,9,11,21 have the same problem, i could just select them in a multiList or check them all in some check box and when i hit submit, computer 7,8,9,11,21 will be added to my mysql DB with the same information.?


any help will be great.

<h1>
10-08-2007, 02:06 PM
What you want to do would be achieved by server language before querying the database. If I understand you correctly, if you use computer numbers 7,8,9,11,21 then you want 5 new rows to added to the database, containing the exact information other than the computer number? Just type the computer numbers in separated by a comma, then use the server language to split up the numbers into an array, and run the insert queries in the loop..

bsxiong
10-08-2007, 02:12 PM
thanks a lot! that was exactly what i was thinking. I know the concept of it, but i'm not expert in PHP, can you help?

rfresh
10-09-2007, 12:13 AM
I would use a multiple select listbox on your main form to select which computers:

<select name="computer[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>

Then in the form that is called by your main form, parse out the select list and write to the database:

$test=$_POST['computer'];
if ($test)
{
foreach ($test as $t)
{
// do your database inserts here using $t variable
}
}

bsxiong
10-09-2007, 03:23 PM
you're DA BOMB! rfresh!