HI,
Below is my sales page, where i ask the user fors the sales details. In one of the fields, the user can browse for an image file, more specifically a jpeg and along with other sales details, save the path to that image into the sales table in the database.
add_sales.php
<?php
if ($post == "yes") {
$dbuser = "root";
$dbserver = "localhost";
$dbpass = "dck";
$dbname = "bng";
//THEN WE ARE ADDING A NEW RECORD SUBMITTED FROM THE FORM
//REPLACE THE FIELD CONTENTS SO THEY DON'T MESS UP YOUR QUERY
//CONNECTION STRING
mysql_connect($dbserver, $dbuser, $dbpass)
or die ("UNABLE TO CONNECT TO DATABASE");
mysql_select_db($dbname)
or die ("UNABLE TO SELECT DATABASE");
/-- SECTION: 9994SQL --/
$sql = "INSERT INTO sales (
Company,
DateOfPurchase,
Product,
Logo,
Quantity,
UnitPrice,
ConfirmationOrderCopy,
TotalAmount,
ReceivedPayment,
AmountReceived,
Remarks
$addl_insert_crit ) VALUES ( '$Company',
'$DateOfPurchase',
'$Product',
'$Logo',
'$Quantity',
'$UnitPrice',
'$ConfirmationOrderCopy',
'$TotalAmount',
'$ReceivedPayment',
'$AmountReceived',
'$Remarks'
$addl_insert_values )";
if ($sql_debug_mode==1) { echo "<BR>SQL: $sql<BR>"; }
$result = mysql_query($sql);
if ($result == 1) {
echo "Record Inserted";
} else {
echo "Error inserting record (9994SQL)";
}
//** END INSERT SQL **
} //END IF POST = YES FOR ADDING NEW RECORDS
if (!$post) {
//THEN WE ARE ENTERING A NEW RECORD
//** BEGIN ADD NEW FORM**
/-- SECTION: 9994FORM --/
?>
<form method="post" action="<?php echo $thispage; ?>?proc=New&post=yes&<?php echo $pagevars; ?>">
<center>
<TABLE>
<TR>
<td>
<B>Company:</B>
</td>
<td>
<input type="Company" name="Company" size="20">
</TR>
<TR>
<td>
<B>Date of purchase:</B>
</td>
<td>
<input type="DateOfPurchase" name="DateOfPurchase" size="20">
</TR>
<TR>
<td>
<B>Item sold:</B>
</td>
<td>
<input type="Product" name="Product" size="20">
</TR>
<TR>
<td>
<form enctype="multipart/form-data" name="s">
<B>Logo used with item(if any):</B>
<td><input name="form_data" type="file" size="40"></td>
</form>
</td>
</TR>
<TR>
<td>
<B>Quantity:</B>
</td>
<td>
<input type="Quantity" name="Quantity" size="20">
</TR>
<TR>
<td>
<B>Unit price:</B>
</td>
<td>
<input type="UnitPrice" name="UnitPrice" size="20">
</TR>
<TR>
<td>
<B>No.of copies to order(after confirmation with customer):</B>
</td>
<td>
<input type="ConfirmationOrderCopy" name="ConfirmationOrderCopy" size="20">
</TR>
<TR>
<td>
<B>Total amount:</B>
</td>
<td>
<input type="TotalAmount" name="TotalAmount" size="20">
</TR>
<TR>
<td>
<B>Received payment?</B>
</td>
<td>
<input type="checkbox" name="ReceivedPayment" value="checked">
</TR>
<TR>
<td>
<B>Amount received::</B>
</td>
<td>
<input type="AmountReceived" name="AmountReceived" size="20">
</TR>
<TR>
<td>
<B>Remarks:</B>
</td>
<td>
<textarea name="Remarks" rows="4" cols="35"></textarea>
</TR>
<tr>
<td>
</td>
<td>
<input type="submit" value="Add Record" name="submit">
<input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</center>
<BR>
</form>
<?php
} //END if post=""
//** END ADD NEW ENTRY FORM**
?>
This is what that needs to be added in to the code above for the image upload part starting the line which asks for the logo used.
1. Test if the image is jpeg or jpg
2.Exract jpeg image
3.Resize image
4,Saving new resized image as thumbnail
5.Save uploaded image to a web-accesible folder, meaning:
-we upload the image say example.jpg
-take that image from php server
-save that image to a folder that's accessible by internet like
this http://example.com/images/example.jpg
-create thumbnail for that jpeg
6.Save url of that image to database
Attached is my code to handle the functions above. But the code needs to be integrated into add_sales.php. How do i do that?Please combine or integrate upload.php into add_sales.php. Thank you.