Jump to content

Error Inserting Record


twilitegxa

Recommended Posts

I have a page that was working correctly, and now all of a sudden it's not! Not sure what happened, but what it's supposed to do is allow the user to insert a new record into the database, along with two images. The data and the first image are uploading just fine, but now the second one isn't working for some reason. Can anyone take a look and see what might be the problem? It's inserting the path for the image into the database, but it's not saving it into the upload folder. I don't really understand how it could work one day and not a week or so later. Can anyone help me out here?

 

 

I have it set to upload the image if the field for the image is not empty (''), but maybe that is causing the problem? If I take it out, it works properly, but then if the user leaves it empty, it produces an error, although the page reroutes like it's supposed to and everything and the record is inserted. Is there a better way to write this?

 

 


<?php
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');


$dbname = 'database';
mysql_select_db($dbname);


$name = $_POST['name'];
$metal = $_POST['metal'];
$desc = $_POST['desc'];
$item_no = $_POST['item_no'];
$cut = $_POST['cut'];
$color = $_POST['color'];
$carats = $_POST['carats'];
$clarity = $_POST['clarity'];
$size = $_POST['size'];
$type = $_POST['type'];
$other = $_POST['other'];
$total = $_POST['total'];
$certificate = $_POST['certificate'];
$value = $_POST['value'];
$image2 = '';
$image = '';


//insert previous file upload code here








//set where you want to store files
//in this example we keep file in folder upload 
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
//$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];


//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
if ($image2 != '') {
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
}
//copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
//echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; 
//echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>"; 
//echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; 
//echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
//echo "<P>";


//echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; 
//echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; 
//echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; 
//echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
//echo "<P>";


//echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; 
//echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; 
//echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; 
//echo "<img src=\"$path3\" width=\"150\" height=\"150\">";


///////////////////////////////////////////////////////


// Use this code to display the error or success.


$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
//$filesize3=$HTTP_POST_FILES['ufile']['size'][2];


if($filesize1 && $filesize2 != 0) 
{
echo "Processing your request . . . .";
}


else {
//echo "ERROR.....";
}


//////////////////////////////////////////////


// What files that have a problem? (if found)


//if($filesize1==0) {
//echo "There're something error in your first file";
//echo "<BR />";
//}


//if($filesize2==0) {
//echo "There're something error in your second file";
//echo "<BR />";
//}


//if($filesize3==0) {
//echo "There're something error in your third file";
//echo "<BR />";
//}


$image1 = str_replace("upload/","",$path1);
$image2 = str_replace("upload/","",$path2);


//end new code here
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$metal', '$other', '$total', '$certificate', '$value', '$image1', '$name', '$desc', '$item_no', '$type', '$image2')";
$query_res = mysql_query($query) or die(mysql_error());
      //}
    //}










     
echo '<script language="Javascript">';
echo 'window.location="[url=http://jhrevell.com/collections]http://jhrevell.com/collections[/url]"';
echo '</script>';
      
?>


Link to comment
Share on other sites

I think I figured out a way to do it. On the line that sets the path for the upload, I added an if statement there and now it appears to be working. I'm not sure why it worked before. Maybe I forgot to test with an empty second image? Oh, well, thanks for the quick response!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.