ciaracous
08-22-2006, 03:00 PM
I am trying to insert values into a datbase on products and upload an image of it at the same time. I am able to insert all of the values in no problem when i do not try to upload and I can upload the image if I just click on browse and upload and not insert other values. The reason I am running into problems is because I used a seperate script for my upload to that of the insert. My upload code is in a file called doupload.php
<?php
$file_dir = '/home/c/ciaracousins/public_html/clothes/';
// Get the image..
$image = $HTTP_POST_FILES['image'];
// Verify for erros
if ( $image['error'] == 0 )
{
// Ok, next: is it uploaded?
if ( is_uploaded_file ( $image['tmp_name'] ))
{
// Copy it to folder and check
if ( move_uploaded_file ( $image['tmp_name'] , $file_dir . $image['name'] ))
{
// Ok, done
# do something here, use header.. java redirection.. don't know, use your imagination..
print 'Done! The file was uploaded!';
}
}
}
?>
And my insert code code is in a file called admin_insert.php
<?
include "db.php";
$submit=$HTTP_POST_VARS["submit"];
$reset=$HTTP_POST_VARS["reset"];
$shopName=$HTTP_POST_VARS["shopName"];
$prodName=$HTTP_POST_VARS["prodName"];
$dept=$HTTP_POST_VARS["dept"];
$brand=$HTTP_POST_VARS["brand"];
$type=$HTTP_POST_VARS["type"];
$price=$HTTP_POST_VARS["price"];
$NoInStock=$HTTP_POST_VARS["NoInStock"];
$image=$HTTP_POST_VARS["image"];
if (!$shopName || !$prodName || !$dept || !$brand || !$type
|| !$price || !$NoInStock || !$image){
echo "Please fill all the fields";
exit;
}
/* Performing SQL query */
$query = "select * from product where prodName = '$prodName'";
//$result = mysql_query($query,$connect);
require_once('db.php');
$query = "INSERT INTO product Values ('','$shopName','$prodName', '$dept', '$brand', '$type', '$image', '$price', '$NoInStock')";
$result = mysql_query($query);
if ($result){
echo "data inserted";
}
else{
echo "This product has already been entered !!!";
}
/* Free resultset */
/* Closing connection */
mysql_close();
?>
What I want to do is to combine the two of these so that when I click on the "Add record" button on my admin_insert.htm page, the image will upload to the server and the values entered will be stored to the database.
admin_insert.htm:
<form action="admin_insert.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<tr>
<td align="center"><p style="color: #FF6600; font size=24"><strong>Add New Records</strong></p></td></tr>
<tr><td></td></tr>
<table align="left" width="100%" border="0">
<tr>
<td align="right" style="color: #006699;">
<strong>Shop Name:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="shopName" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Product Name:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="prodName" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Department:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="dept" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>brand:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="brand" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Type:</strong>
</td>
<td>
<input maxLength="45" size="45" name="type" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Price:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="price" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Quantity:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="NoInStock" />
</td>
</tr>
<!--<tr>
<td align="right" style="color: #006699;">
<strong>File to Upload:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="image" />
</td>
</tr>-->
<tr>
<td align="right" style="color: #006699;">
<strong>File to Upload:</strong>
</td>
<td>
<input type="text" name="image" />
<!--<input type="submit" value="Upload!" />-->
</td>
</tr>
<tr>
<td></td>
<td align="left" colspan="2">
<input type="submit" value="Add Record" name=submit />
<input type=reset value=Reset name=reset />
</td>
</tr>
</table>
</form>
</TBODY>
</TABLE>
</FORM>
I am also having problems with the upload part. If I have
<input type="file" name="image" />
it keeps saying to enter all fields. It is not recognising what is being entered because image is set to be a text value in the database, because I am not storing the image in the db, I am trying to upload the image to the server and then just store its path in the db.
Can anyone help me with this?
Thanks
<?php
$file_dir = '/home/c/ciaracousins/public_html/clothes/';
// Get the image..
$image = $HTTP_POST_FILES['image'];
// Verify for erros
if ( $image['error'] == 0 )
{
// Ok, next: is it uploaded?
if ( is_uploaded_file ( $image['tmp_name'] ))
{
// Copy it to folder and check
if ( move_uploaded_file ( $image['tmp_name'] , $file_dir . $image['name'] ))
{
// Ok, done
# do something here, use header.. java redirection.. don't know, use your imagination..
print 'Done! The file was uploaded!';
}
}
}
?>
And my insert code code is in a file called admin_insert.php
<?
include "db.php";
$submit=$HTTP_POST_VARS["submit"];
$reset=$HTTP_POST_VARS["reset"];
$shopName=$HTTP_POST_VARS["shopName"];
$prodName=$HTTP_POST_VARS["prodName"];
$dept=$HTTP_POST_VARS["dept"];
$brand=$HTTP_POST_VARS["brand"];
$type=$HTTP_POST_VARS["type"];
$price=$HTTP_POST_VARS["price"];
$NoInStock=$HTTP_POST_VARS["NoInStock"];
$image=$HTTP_POST_VARS["image"];
if (!$shopName || !$prodName || !$dept || !$brand || !$type
|| !$price || !$NoInStock || !$image){
echo "Please fill all the fields";
exit;
}
/* Performing SQL query */
$query = "select * from product where prodName = '$prodName'";
//$result = mysql_query($query,$connect);
require_once('db.php');
$query = "INSERT INTO product Values ('','$shopName','$prodName', '$dept', '$brand', '$type', '$image', '$price', '$NoInStock')";
$result = mysql_query($query);
if ($result){
echo "data inserted";
}
else{
echo "This product has already been entered !!!";
}
/* Free resultset */
/* Closing connection */
mysql_close();
?>
What I want to do is to combine the two of these so that when I click on the "Add record" button on my admin_insert.htm page, the image will upload to the server and the values entered will be stored to the database.
admin_insert.htm:
<form action="admin_insert.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<tr>
<td align="center"><p style="color: #FF6600; font size=24"><strong>Add New Records</strong></p></td></tr>
<tr><td></td></tr>
<table align="left" width="100%" border="0">
<tr>
<td align="right" style="color: #006699;">
<strong>Shop Name:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="shopName" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Product Name:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="prodName" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Department:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="dept" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>brand:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="brand" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Type:</strong>
</td>
<td>
<input maxLength="45" size="45" name="type" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Price:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="price" />
</td>
</tr>
<tr>
<td align="right" style="color: #006699;">
<strong>Quantity:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="NoInStock" />
</td>
</tr>
<!--<tr>
<td align="right" style="color: #006699;">
<strong>File to Upload:</strong>
</td>
<td>
<input onfocus="ShowPwWarning()" maxLength="45" size="45" name="image" />
</td>
</tr>-->
<tr>
<td align="right" style="color: #006699;">
<strong>File to Upload:</strong>
</td>
<td>
<input type="text" name="image" />
<!--<input type="submit" value="Upload!" />-->
</td>
</tr>
<tr>
<td></td>
<td align="left" colspan="2">
<input type="submit" value="Add Record" name=submit />
<input type=reset value=Reset name=reset />
</td>
</tr>
</table>
</form>
</TBODY>
</TABLE>
</FORM>
I am also having problems with the upload part. If I have
<input type="file" name="image" />
it keeps saying to enter all fields. It is not recognising what is being entered because image is set to be a text value in the database, because I am not storing the image in the db, I am trying to upload the image to the server and then just store its path in the db.
Can anyone help me with this?
Thanks