Image preview in form before submit problem

I found this code in Upload Image Files without Refreshing Page using Ajax and Jquery and modification my form

<?
require_once("include/main.php");
dbconn(false);
loggedinorreturn(); 
if (get_user_class() < UC_SYSOP){
stderr("&#1048;&#1079;&#1074;&#1080;&#1085;&#1080;&#1090;&#1077;", "&#1044;&#1086;&#1089;&#1090;&#1091;&#1087;&#1072; &#1085;&#1077;&#1090;.");
}

$path = "uploads/";
	$valid_formats = array("jpg", "png", "gif", "bmp");
	if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
    if($_POST['addnew'] == 'yes'){

			if(strlen($name)) {
					list($txt, $ext) = explode(".", $name);
					if(in_array($ext,$valid_formats)) {
					if($size<(1024*1024)) {
							$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
							$tmp = $_FILES['photoimg']['tmp_name'];
							if(move_uploaded_file($tmp, $path.$actual_image_name)) {
                            echo "<img src='uploads/".$actual_image_name."'>";
                        } else echo "&#1054;&#1096;&#1080;&#1073;&#1082;&#1072;!";
                    } else echo "&#1052;&#1072;&#1082;&#1089;&#1080;&#1084;&#1091;&#1084; 1 MB";
                } else echo "&#1053;&#1077;&#1074;&#1077;&#1088;&#1085;&#1099;&#1081; &#1092;&#1086;&#1088;&#1084;&#1072;&#1090; &#1092;&#1072;&#1081;&#1083;&#1072;";
            } else echo "&#1042;&#1099;&#1073;&#1077;&#1088;&#1080;&#1090;&#1077; &#1080;&#1079;&#1086;&#1073;&#1088;&#1072;&#1078;&#1077;&#1085;&#1080;&#1077;..!";

        $image = sqlesc($actual_image_name);
	$name = $_FILES['photoimg']['name'];
	 $size = $_FILES['photoimg']['size'];
         $added = sqlesc(get_date_time());
         $name = sqlesc($_POST['name']);
         $code_production = sqlesc($_POST['code_production']);
         $catname = $_POST['catname'];
	 $napolnitel = $_POST['napolnitel'];
         $price = sqlesc($_POST['price']);
         $about_product = sqlesc($_POST['about_product']);
         $info_pack = sqlesc($_POST['info_pack']);
       //$somthing = sqlesc(implode(', ', $_POST['somthing']));


			
			
mysql_query("INSERT INTO production (added, image, name, code_production, catname, napolnitel, price, about_product, info_pack) 
VALUES(".$added.", ".$image.", ".$name.", ".$code_production.", ".sqlesc($catname).", ".$napolnitel.", ".$price.", ".$about_product.", ".$info_pack.")") or sqlerr(__FILE__, __LINE__);
//echo '<script>document.location.replace("add.php");</script>';
header('Location: ./index.php');
}
}

?>
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.form.js"></script>
<script type="text/javascript" >
 $(document).ready(function() { 
		
            $('#photoimg').live('change', function()			{ 
			           $("#preview").html('');
			    $("#preview").html('<img src="loader.gif" title="&#1048;&#1076;&#1077;&#1090; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1082;&#1072;...." alt="&#1048;&#1076;&#1077;&#1090; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1082;&#1072;...."/>');
			$("#imageform").ajaxForm({
						target: '#preview'
		}).submit();
		
			});
        }); 
</script>

<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td align="center">      
<form id="imageform" method="post" enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="addnew" value="yes">
<table class="tableinborder" cellSpacing=1 cellPadding=6 width="100%" border=0>	
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1053;&#1072;&#1079;&#1074;&#1072;&#1085;&#1080;&#1077;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><input size="60" name="name"></td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1053;&#1072;&#1087;&#1086;&#1083;&#1085;&#1080;&#1090;&#1077;&#1083;&#1100;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><input size="60" name="napolnitel"></td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1050;&#1086;&#1076;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><input size="10" name="code_production"></td>
</tr>
<?
$genre = "";
$res = mysql_query("SELECT id, catname FROM categories ORDER BY id ASC") or die;
while ($row = mysql_fetch_array($res)){ 
$ros = mysql_query("SELECT id, name FROM subcategories WHERE catid = '".$row['id']."' ORDER BY name ASC") or die;
$genre .= "<option class=\\"speciald\\" disabled value=\\"".$row['catname']."\\">".$row['catname']."</option>\
";
while ($showSub = mysql_fetch_array($ros)) {  
$genre .= "<option value=\\"".$showSub['id']."\\"> - ".$showSub['name']."</option>\
";
}
}
?>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1050;&#1072;&#1090;&#1072;&#1083;&#1086;&#1075;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><select size="10" name="catname"><?echo $genre?></select></td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1054;&#1087;&#1080;&#1089;&#1072;&#1085;&#1080;&#1077; &#1090;&#1086;&#1074;&#1072;&#1088;&#1072;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><textarea name="about_product" rows="10" cols="60"></textarea></td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1059;&#1087;&#1072;&#1082;&#1086;&#1074;&#1082;&#1072; &#1080; &#1082;&#1086;&#1083;-&#1074;&#1086;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><input size="60" name="info_pack"></td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1062;&#1077;&#1085;&#1072;:</td>
    <td class="tablea" height="20" width="75%"><p align="left"><input size="7" name="price"> &#1088;&#1091;&#1073;.</td>
</tr>
<tr>
    <td class="tablea" height="20" width="25%"><p align="left">&#1050;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1072;:</td>
    <td class="tablea" height="20" width="75%"><p align="left">
    <input type="file" name="photoimg" id="photoimg" /><div id='preview'></div></td>
</tr>
<tr>      
    <td class="tablea" height="20" width="100%" colspan="4"><center><input type="submit" value="&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100; &#1090;&#1086;&#1074;&#1072;&#1088;"></center></td>
</tr>
</table>
</form>

The problem is, when i choose image, the form automatic submited.
Without give me upload another image or check form before.

And after the form automatic submitted, it dosn’t do header(). All action do in the <div id=‘preview’></div> with header error

How to do Only preview image after choose, and submit all the form with button submit (in my form in russian Добавить товар)

Thanks

I have created an HTML form that contact text input fields as well as file input for image uploads. I have already created the submit.php that handles the image file uploaded as well as other text inputs that are typed in by the users and this php file works fine.

That was add the information form to database but:

  1. After submiting give me Error (see on the screen) http://s2.postimg.org/rd4ie680p/error.jpg and the error print in <div id=‘preview’>here</div>
  2. I don’t want the auto submit information, how to change and what ? (only image preview in form)