Jump to content

Adding Image


arunpatal

Recommended Posts

I am trying to add 2nd image but its not working.

 

fileField upload the image and name it $pid.jpg which is id (auto_increment)

 

i added new field into database call img1, now i want to upload another image which will be named as img1 input field.

 

Please check :)

 

 

 

<?php

// Parse the form data and add inventory item to the system

if (isset($_POST['product_name'])) {

 

$product_name = mysql_real_escape_string($_POST['product_name']);

$price = mysql_real_escape_string($_POST['price']);

$img1 = mysql_real_escape_string($_POST['img1']);

$category = mysql_real_escape_string($_POST['category']);

$subcategory = mysql_real_escape_string($_POST['subcategory']);

$details = mysql_real_escape_string($_POST['details']);

// See if that product name is an identical match to another product in the system

$sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1");

$productMatch = mysql_num_rows($sql); // count the output amount

if ($productMatch > 0) {

echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>';

exit();

}

// Add this product into the database now

$sql = mysql_query("INSERT INTO products (product_name, price, img1, details, category, subcategory, date_added)

VALUES('$product_name','$price','$img1','$details','$category','$subcategory',now())") or die (mysql_error());

$pid = mysql_insert_id();

// Place image in the folder

$newname = "$pid.jpg";

move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname");

header("location: inventory_list.php");

exit();

 

$img1 = "$img1";

move_uploaded_file( $_FILES['fileField1']['tmp_name'], "../inventory_images/$img1");

header("location: inventory_list.php");

exit();

}

?>

 

 

 

OK guys....

 

Now its working

 

I had to take off exit();

Link to comment
https://forums.phpfreaks.com/topic/270425-adding-image/
Share on other sites

Your use of the exit statement here is incorrect. You should be using the correct if { }else { } conditional instead:

 

if ($productMatch > 0) {
    'true block'
}else{
    'false block'
}

 

Also, check to make sure the file was actually uploaded before using header();

 

if(move_uploaded_file( $_FILES['fileField1']['tmp_name'], "../inventory_images/$img1"))
{
    header("location: inventory_list.php");
}else
{
    'error handler'
}

Link to comment
https://forums.phpfreaks.com/topic/270425-adding-image/#findComment-1390900
Share on other sites

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.