I have little webshop made in php and now i am trying to develope it that user can upload two imges instead of one.
Images goes straight to the specifed folder in webserver and in Mysql goes other data name, price...
Now i am in that situation that these two images goes in right folder but in mysql database goes probably nothing? After insert button pages come back to index page but it has to go after succesfull insert on Location:confirmation.php page? What is wrong?
Here is my action page code:
<?php
session_start();
if (!isset($_SESSION["session
_login"]) || $_SESSION["session_login"]
== ""){
header("Location:index.php
");
}
include("../includes/confi
g.php");
$chk=1;$ext=0;
if($_FILES['image']['name'
]!=""){
$maxSize = "104857";
$allowedExtensions = array("jpg", "JPG", "JPEG","gif","GIF","png");
$extension = pathinfo($_FILES['image'][
'name']);
$ext=$extension['extension
'];
for($k=0;$k<=5;$k++){
if(strcasecmp($ext,$allowe
dExtension
s[$k])==0)
{
$chk=0;
break;
}else
{
$error ="'".$extension['extension
']."' Extension not allowed";
$chk=1;
}
}
}
$id=time();
chdir("../productImages");
if($_FILES['image']['name'
]!="" && $chk==0){
$newpath=$_FILES['image'][
'name'];
$ext=substr($newpath,(strl
en($newpat
h)-4),strl
en($newpat
h));
$oldpath=getcwd()."/$id"."
_".$_FILES
['image'][
'name'];
copy($_FILES['image']['tmp
_name'],$o
ldpath);
$hidvar="/$id$ext";
//chdir("../productImages"
);
$picpath=$hidvar;
$newpath=getcwd()."\\$id".
"_".$_FILE
S['image']
['name'];
//copy($_FILES['image']['t
mp_name'],
$newpath);
$width = 90;
$height = 84;
$srcFile=$oldpath;
$destFile= $newpath;
//kuva2;
chdir("../productImages");
if($_FILES['image2']['name
']!="" && $chk==0){
$newpath=$_FILES['image2']
['name'];
$ext=substr($newpath,(strl
en($newpat
h)-4),strl
en($newpat
h));
$oldpath=getcwd()."/$id"."
_".$_FILES
['image2']
['name'];
copy($_FILES['image2']['tm
p_name'],$
oldpath);
$hidvar2="/$id$ext";
//chdir("../productImages"
);
$picpath=$hidvar2;
$newpath=getcwd()."\\$id".
"_".$_FILE
S['image2'
]['name'];
//copy($_FILES['image2']['
tmp_name']
,$newpath)
;
$width = 90;
$height = 84;
$srcFile=$oldpath;
$destFile= $newpath;
//kuva2loppuu;
$hidvar = $id."_".$_FILES['image']['
name'];
$hidvar2 = $id."_".$_FILES['image2'][
'name'];
$sql = "INSERT INTO product(CID, SID, prod_name, prod_desc, prod_size, prod_price, wholesale_price, prod_image, prod_image2, reg_ship_price, 2day_ship, 3day_ship, 4day_ship, quantity) VALUES('".$_POST["listCat"
]."','".$_
POST["list
SubCat"]."
','" . $_POST["PName"] ."','" . $_POST["proDescription"] ."','" . $_POST["sizes"] ."', " . $_POST["Price"] .", " . $_POST["wholesale_price"] .",'" . $hidvar ."', '" . $hidvar2 ."', '".$_POST['shipPrice']."',
'".$_POST['2day_ship']."',
'".$_POST['3day_ship']."',
'".$_POST['4day_ship']."',
".$_POST['quantity'].")";
mysql_query($sql) or die(mysql_error());
header("Location:confirmat
ion.php?ms
g=".urlenc
ode("Produ
ct has been Saved!"));
}
}
?>
==========================
==========
==========
=====
here is the code before changing code:
<?php
session_start();
if (!isset($_SESSION["session
_login"]) || $_SESSION["session_login"]
== ""){
header("Location:index.php
");
}
include("../includes/confi
g.php");
$chk=1;$ext=0;
if($_FILES['image']['name'
]!=""){
$maxSize = "104857";
$allowedExtensions = array("jpg", "JPG", "JPEG","gif","GIF","png");
$extension = pathinfo($_FILES['image'][
'name']);
$ext=$extension['extension
'];
for($k=0;$k<=5;$k++){
if(strcasecmp($ext,$allowe
dExtension
s[$k])==0)
{
$chk=0;
break;
}else
{
$error ="'".$extension['extension
']."' Extension not allowed";
$chk=1;
}
}
}
$id=time();
chdir("../productImages");
if($_FILES['image']['name'
]!="" && $chk==0){
$newpath=$_FILES['image'][
'name'];
$ext=substr($newpath,(strl
en($newpat
h)-4),strl
en($newpat
h));
$oldpath=getcwd()."/$id"."
_".$_FILES
['image'][
'name'];
copy($_FILES['image']['tmp
_name'],$o
ldpath);
$hidvar="/$id$ext";
//chdir("../productImages"
);
$picpath=$hidvar;
$newpath=getcwd()."\\$id".
"_".$_FILE
S['image']
['name'];
//copy($_FILES['image']['t
mp_name'],
$newpath);
$width = 90;
$height = 84;
$srcFile=$oldpath;
$destFile= $newpath;
$hidvar = $id."_".$_FILES['image']['
name'];
$sql = "INSERT INTO product(CID, SID, prod_name, prod_desc, prod_size, prod_price, wholesale_price, prod_image, reg_ship_price, 2day_ship, 3day_ship, 4day_ship, quantity) VALUES('".$_POST["listCat"
]."','".$_
POST["list
SubCat"]."
','" . $_POST["PName"] ."','" . $_POST["proDescription"] ."','" . $_POST["sizes"] ."', " . $_POST["Price"] .", " . $_POST["wholesale_price"] .",'" . $hidvar ."', '".$_POST['shipPrice']."',
'".$_POST['2day_ship']."',
'".$_POST['3day_ship']."',
'".$_POST['4day_ship']."',
".$_POST['quantity'].")";
mysql_query($sql) or die(mysql_error());
header("Location:confirmat
ion.php?ms
g=".urlenc
ode("Produ
ct has been Saved!"));
}
?>
Start Free Trial