Jump to content

how to add multiple items with same AND different parts


gmas

Recommended Posts

Well I made this form that's going to help me add items to my database but only some part is different for each item but other parts are the same.

 

I want to insert item1 > title1 description1 tags comments

                      item2 > title2 description2 tags comments

                      item3 > title3 description3 tags comments

 

title and descriptions are different for each item but tags and comments are the same. This is done within one page form. I have title descrition for each item where i represent the item number. This is the code for my form, it's longer than what's up there but same idea. I just don't know how to do the sql part.  ???

 

<script language="javascript" type="text/javascript">
function transferText () { 
if (document.getElementById("duplicateText").checked == true) {
  for (i=2;i< 30 ; i++){

document.getElementById("title_"+i).value = document.getElementById("title_1").value ;
document.getElementById("servertype_"+i).value = document.getElementById("servertype_1").value ;
document.getElementById("videolink_"+i).value = document.getElementById("videolink_1").value ;
document.getElementById("servercode_"+i).value = document.getElementById("servercode_1").value ;


}
    }

}  
   
   
   
 function clearText () { 
if (document.getElementById("clear").checked == true) {
  for (i=2;i< 30 ; i++){

document.getElementById("title_"+i).value = "" ;
document.getElementById("servertype_"+i).value = "" ;
document.getElementById("videolink_"+i).value = "" ;
document.getElementById("servercode_"+i).value = "" ;

}
    }

}    
   



  </script>

</head>

<body>

  
<h1>Add Items</h1>
<form action="process.php"  method="post" name="adminForm" id="adminForm" class="adminForm">


            
  <table border="0" cellpadding="3" cellspacing="0" >
    <tr>
      <td><fieldset>
        <legend>Create up to 30 items in a row!</legend>
        <table border="0" cellpadding="3" cellspacing="0">
          <?php for ($i=1;$i< 30+1;$i++) { ?>
          <tr>
            <td>Title (Ep <?php echo $i; ?>): </td>
            <td><input name="title[]"  type="text" size="50" id="title_<?php echo $i; ?>" value="" /></td>
<td >Server Type: </td>
            <td><input name="servertype[]" type="text" id="servertype_<?php echo $i; ?>" value="" size="20" /></td>
           </tr>
            <tr>
            <td >Video Link: </td>
            <td><input name="videolink[]" type="text" id="videolink_<?php echo $i; ?>" value="" size="50" /></td>
          
            <td >Server Code: </td>
            <td><input name="servercode[]" type="text" id="servercode_<?php echo $i; ?>" value="" size="20" /></td>
       
       
       
          </tr><tr><td><br /></td></tr>
<?php } ?> <br />
        </table>
      </fieldset></td>
      <td valign="top"><fieldset>
        <legend>Options</legend>
        <table border="0" cellpadding="3" cellspacing="0">
          <tr>
            <td>Copy </td>
            <td><input type="checkbox" id="duplicateText" name="duplicateText" onclick="javascript:transferText()" />
            
            Clear <input type="checkbox" id="clear" name="clear" onclick="javascript:clearText()" />
            
            
            </td>
            
         
          </tr>
          <tr>
            <td colspan="2">PS: Only pages with title will be inserted.</td>
          </tr>
          <tr>
            <td>Published</td>
            <td><select name="published">
		<option value="1">Yes</option>
            <option value="0">No</option>
            </select></td>
          </tr>
          <tr>
         <td>Featured</td> 
            <td> 
<select name="featured">
            <option value="0">No</option>
            <option value="1">Yes</option>
            </select>
            
           </td>
           </tr>
           <tr>
           <td>Access Level</td>             

	<td> <select name="accesslevel">
		<option value="0">0</option>
            <option value="1">1</option>
            <option value="2">2</option>
            </select></td>
          </tr>
          <tr>
            <td>Category: (CatID) <?php echo $lists['catid']; ?></td>
          </tr>
        
          <tr>
            <td>Added by: (ID)</td>
            <td><input type="text" name="author" size="20" /></td>
          </tr>
  
          <tr>
            <td>Date</td>
            <td><input type="text" name="time" size="20" /></td>
          </tr>
              <tr>
      
            <td >Details: </td>
            <td><input name="details[]" type="text" value="" size="30" /></td>
      </tr> 
      <tr>       
            <td >Tags: </td>
            <td><input name="tags[]" type="text"  value="" size="30" /></td>
      
          </tr>
          <tr><td><input type="submit" value="Submit"> </td></tr>
        </table>
      </fieldset></td>
    </tr>
  </table>
  <input type="hidden" name="task" value="" />
  <input type="hidden" id="state" name="state" value="1" />
  <input type="hidden" name="id" value="" />
  <input type="hidden" name="option" value="<?php echo $option; ?>" />
  <?php echo $hidden;?>
</form>



</body>
</html>

my bad, here's what I have so far

 

 


$id = $_POST['id'];
$title = $_POST['title'];
$details = $_POST['itemcomment'];
$tags = $_POST['videotags'];
$catid = $_POST['catid'];
$published = $_POST['published'];
$featured = $_POST['featured'];
$videourl = $_POST['videourl'];
$picturelink = $_POST['picturelink'];
$videoservertype = $_POST['videoservertype'];
$videoservercode = $_POST['videoservercode'];
$addedby = $_POST['addedby'];
$addeddate = $_POST['addeddate'];
$accesslevel = $_POST['accesslevel'];



for ($i=0;$i< 30 ;$i++){

$query = "INSERT INTO items ( title, itemcomment, videotags, catid, published, featured, videourl, picturelink, videoservertype, videoservercode, addedby, addeddate, accesslevel)
VALUES( '$title', '$details', '$tags', '$catid', '$published', '$featured', '$videourl', '$picturelink', '$videoservertype', '$videoservercode', '$addedby','$addeddate', '$accesslevel')";
}


mysql_query($query)

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.