Jump to content

Mutiple entry of values from a html table into database


Scip

Recommended Posts

Hi, this is my first post on these forums but i have been reading for a while now.

 

I am attempting to make a website for my mmo guild mainly as a project to help me learn php and mysql.

 

Now i am trying to make a loot distribution/resource management system. I am currently working on the backend part now(resource management).

 

Basically i have two tables in the db, 'categories' which list the different categories of resources and 'resources' which list the actual resources. The idea was i would could then create a relational database by giving each individual resource  a category id.

 

Now want to be able to edit the resources that have to entered into the database.

 

I have managed to print out resources under the right categories into html tables but i am stack at how to write php and mysql code that will allow the updating of multiple items.

 

<?php
	         $query="SELECT *";
		 $query.="FROM category";

		 $category_set=mysql_query($query,$connection);
		 confirm_query($category_set);

	   ?>
                   <div id="resourcebox"><!-- START RESOURCE BOX-->
                            <form action="new-resource.php" method="post">
                               <table>
                                 <thead><h3>Add a resource</h3></thead>
                                 <tr></tr>
                                 <tr>
                                   <td><p>Name:</p></td>
                                   <td><p>Category:</p></td>
                                   <td><p>Quantity:</p></td>
                                   <td><p>Image:</p></td>
                                 </tr>
                                 <tr>
                                   <td><input type="text" name="name" class="field" value=""/></td>
                                   <!--<td><input type="text" name="category" class="field" value="" /></td>-->
                                   <td><select name="category">
			         <?php
				    while($categories=mysql_fetch_array($category_set)){
                                             echo "<option value=\"{$categories['type']}\" >{$categories['type']}</option>";
				    }
			         ?>
                                        </select>
                                   </td>
                                   <td><input type="text" name="quantity" class="field" value="" /></td>
                                   <td><input type="file" name="Image" class="filefield" value=""/></td>  
                                 </tr>
                                 <tr>
                                   <td ></td>
                                   <td ></td>
                                   <td ></td>
                                   <td ><p class="align"><input type="submit" class="addbutton" value="Add"/></p></td>  
                                 </tr>

                               </table>
                             </form>
                            </div><!-- END RESOURCE BOX--> 
                            
                            <div id="resource-table"><!-- START RESOURCE TABLE -->
                         <?php

	         $query="SELECT *";
		 $query.="FROM resource";

		 $resources_set=mysql_query($query,$connection);
		 confirm_query($resources_set);

	         

	         ?>
                                   <form action="update-resource.php" method="post">

				<?php
				mysql_data_seek($category_set,0);
				while($categories=mysql_fetch_array($category_set)){
					                                              
                                 echo"<h3>{$categories['type']}</h3>
                                           <table><tr>
                                                    <td>Image</td>                                               
                                                    <td>Name</td>
                                                    <td>Quantity</td>
                                                    <td>Update</td>
                                                    <td>Delete</td> 
                                                 </tr>";
				 while($resource=mysql_fetch_array($resources_set)){
					if($resource['type_id']==$categories['id']){
				        echo"<tr>
                                                    <td>{$resource['image']}</td>
                                                    <td>{$resource['resource_ name']}</td>
                                                    <td class=\"quantfield\"><input type=\"text\" name=\"quantity\" class=\"quantfield\" value=\"{$resource['quantity']}\" /></td>
                                                    <td><input type=\"checkbox\" name=\"update\" class=\"\" value=\"\" /></td>
                                                    <td><input type=\"checkbox\" name=\"delete\" class=\"\" value=\"\" /></td> 
                                                 </tr>";
					    }
					        }

                                                 
                                                 echo"</table>" ;
                                                     }
                                                  ?>
                                                 <p><input type="submit" name="submit" value="submit"  /></p>
				                    
				     	    

				   

                                     </form>

 

sorry if my explanation is is not clear.

 

I think my original explanation was poor.

 

I have fed information from a table in the database into a form  in order to edit it. There are going to be hundreds if not thousands of rows to edit, so updating them one by one would be a nightmare.

 

What i want is an example where a form with rows of similar information is submitted to be entered into the same table in the database.

 

I am having problem thinking of php code which can help me do this. I have tried google but i think i am not searching with the right keywords.

 

I know once the form is submitted all the information within it will go into the $_post variable, now i am stack on how to retrieve information which relates to individual rows. I think my html code is bad aswell :s.

 

Right now everything is in a single form, i wouldn't say my html is advance either. What i am now thinking is about having multiple forms.

 

From:

  <form action='url.php'  method='post'>

      <table>

            <tr>

                    <td><input/></td>

                    <td></td>

            </tr>

            <tr>

                    <td><input/></td>

                    <td></td>

            </tr>

      </table>

  </form>  //for each row

 

to:

<table>

          <form action=url.php?form=1>

              <tr>

                <td></td>

                <td></td>

              </tr>

          </form>

          <form action=url.php?form=2>

              <tr>

                <td></td>

                <td></td>

              </tr>

          </form>

</table>

 

:s i not even sure if thats valid html syntax

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.