View Single Post
  #1 (permalink)  
Old 02-14-2008, 01:17 PM
jazzmatazz2005 jazzmatazz2005 is offline
WebProWorld Member
 
Join Date: Aug 2003
Location: Jersey City, NJ
Posts: 74
jazzmatazz2005 RepRank 0
Default Adding multiple entries to my database at 1 time

i have put together a few pages on my local machine.
the first page allows me to to add images to a certain name that's already in the DB
the code looks likes this:

<form enctype='multipart/form-data' action='process.php' method='post'>
<table width='78%' border=0>
<tr><td> name</td>
<td><select name="name" id="name">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['fname']?>"><?php echo $row_Recordset1['fname']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
The last profle created is selected by default </td>
</tr>
<tr><td> smimage</td>
<td>
<input name='smimage' type='file' size="125"></td></tr>
<tr><td> lgimage</td>
<td>
<input name='lgimage' type='file' size="125"></td></tr>
</table>
<input type='submit' value='Submit Form'> <input type=reset value='Clear Form'></form>
<br><br><br>

The process page looks like this:

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','name');
$smimage=$HTTP_POST_FILES['smimage'];
$lgimage=$HTTP_POST_FILES['lgimage'];
if($HTTP_POST_FILES['smimage']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['smimage']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['smimage']['name'].", was not uploaded!";
$errors=1;
}
if($HTTP_POST_FILES['lgimage']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['lgimage']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['lgimage']['name'].", was not uploaded!";
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date("h_i_s")."_".$HTTP_POST_FILES['smimage']['name'];
$image_list[1] = $image_part;
copy($HTTP_POST_FILES['smimage']['tmp_name'], "../media/img/".$image_part);
$image_part = date("h_i_s")."_".$HTTP_POST_FILES['lgimage']['name'];
$image_list[2] = $image_part;
copy($HTTP_POST_FILES['lgimage']['tmp_name'], "../media/img/".$image_part);
$where_form_is="".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."media/img/".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF) ,"/"));
$message="name: ".$name."
smimage: ".$where_form_is."files/".$image_list[1]."
lgimage: ".$where_form_is."files/".$image_list[2]."
";
$link = mysql_connect("localhost","root","");
mysql_select_db("unrated1",$link);
$query="insert into unrated2 (name,smimage,lgimage) values ('".$name."','".$where_form_is."".$image_list[1]."','".$where_form_is."".$image_list[2]."')";
mysql_query($query);
?>


<!-- This is the content of the Thank you page, be careful while changing it -->

<h2>Thank you!</h2>

<table width=50%>
<tr><td>name: </td><td> <?php echo $name; ?> </td></tr>
<tr><td>smimage: </td><td> <?php echo $smimage; ?> </td></tr>
<tr><td>lgimage: </td><td> <?php echo $lgimage; ?> </td></tr>
</table><br /><br />
<a href="form1.php">insert another</a>
<br /><br />
<a href="../1/form1.html">Create Profile </a>
<!-- Do not change anything below this line -->

<?php
}
?>

This is a sample of what this code is putting in the database
1295 Nadia media/img/10_13_37_TN_nadia_dawn_20.jpg media/img/10_13_37_nadia_dawn_20.jpg 2008-02-14 10:13:37
1296 Nadia media/img/10_13_51_TN_nadia_dawn_21.jpg media/img/10_13_51_nadia_dawn_21.jpg 2008-02-14 10:13:51
1297 Nadia media/img/10_14_04_TN_nadia_dawn_22.jpg media/img/10_14_04_nadia_dawn_22.jpg 2008-02-14 10:14:04

Every row has a the primary key, name, smimage, lgimage,time stamp.

The problem some names have lots of pictures that need to go with them and the way the code is currently i have to do it one at a time and that to slow when i have about 5000 images that need to go in.

How can i make this work so i can put in up to 20 entries (rows) at a time and not change the database structure.
__________________
It's better to do business with me than against me!

Last edited by jazzmatazz2005; 02-14-2008 at 01:25 PM.
Reply With Quote