Advertisement

07.01.2008 at 11:42AM PDT, ID: 23531225
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Webshop problem, images goes right folder but Mysql insert don't work

Asked by tikkanen in PHP and Databases, PHP Scripting Language

Tags:

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/config.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,$allowedExtensions[$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,(strlen($newpath)-4),strlen($newpath));
                        $oldpath=getcwd()."/$id"."_".$_FILES['image']['name'];      
                        copy($_FILES['image']['tmp_name'],$oldpath);
                        $hidvar="/$id$ext";
                        //chdir("../productImages");
                        $picpath=$hidvar;
                        $newpath=getcwd()."\\$id"."_".$_FILES['image']['name'];      
                        //copy($_FILES['image']['tmp_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,(strlen($newpath)-4),strlen($newpath));
                        $oldpath=getcwd()."/$id"."_".$_FILES['image2']['name'];      
                        copy($_FILES['image2']['tmp_name'],$oldpath);
                        $hidvar2="/$id$ext";
                        //chdir("../productImages");
                        $picpath=$hidvar2;
                        $newpath=getcwd()."\\$id"."_".$_FILES['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["listSubCat"]."','" . $_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:confirmation.php?msg=".urlencode("Product 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/config.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,$allowedExtensions[$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,(strlen($newpath)-4),strlen($newpath));
                        $oldpath=getcwd()."/$id"."_".$_FILES['image']['name'];      
                        copy($_FILES['image']['tmp_name'],$oldpath);
                        $hidvar="/$id$ext";
                        //chdir("../productImages");
                        $picpath=$hidvar;
                        $newpath=getcwd()."\\$id"."_".$_FILES['image']['name'];      
                        //copy($_FILES['image']['tmp_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["listSubCat"]."','" . $_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:confirmation.php?msg=".urlencode("Product has been Saved!"));
                        
                  }

?>Start Free Trial
 
 
[+][-]07.02.2008 at 12:00AM PDT, ID: 21914057

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 07:26AM PDT, ID: 21916724

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 07:27AM PDT, ID: 21916727

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 08:49AM PDT, ID: 21917638

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 10:36AM PDT, ID: 21927541

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:08AM PDT, ID: 21955872

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:10AM PDT, ID: 21955895

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 09:44AM PDT, ID: 21989693

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Tags: php
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628