php - On submit, JavaScript alert showing and database data not insert if my code is any error -


 <!-- html form  -->  <form action="insert_products.php" method="post" name="insert_products" enctype="multipart/form-data">  <table align="center" width="95%" cellspacing="20" cellpadding="5">  <tr>   <td align="center" bgcolor="#cccccc"><strong>select category:</strong></td>   <td><select name="category_id" id="insert_product_form_category">       <option value="select category" selected="selected" disabled="disabled">select category</option> <!-- select category  -->         <?php           global $con;           $get_categories = "select * categories";           $run_get_categories = mysqli_query($con, $get_categories);           while ($row_run_get_categories = mysqli_fetch_array($run_get_categories)) {             $category_id = $row_run_get_categories['category_id'];             $category_name = $row_run_get_categories['category_name'];             echo "<option value='$category_id'>$category_name</option>";           }         ?>      </select>   </td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>select brand:</strong></td>   <td><select name="brand_id" id="insert_product_form_brand">       <option value="select brand" selected="selected" disabled="disabled">select brand</option> <!-- select brand  -->         <?php              global $con;           $get_brands = "select * brands";           $run_get_brands = mysqli_query($con, $get_brands);           while ($row_run_get_brands = mysqli_fetch_array($run_get_brands)) {             $brand_id = $row_run_get_brands['brand_id'];             $brand_name = $row_run_get_brands['brand_name'];             echo "<option value='$brand_id'>$brand_name</option>";           }         ?>        </select>   </td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product title:</strong></td>   <td><input type="text" name="product_title" id="insert_product_form_title" placeholder="product title"><td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product image-1:</strong></td>   <td><input type="file" name="product_img1" id="insert_product_form_img1"></td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product image-2:</strong></td>   <td><input type="file" name="product_img2" id="insert_product_form_img2"></td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product image-3:</strong></td>   <td><input type="file" name="product_img3" id="insert_product_form_img3"></td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product price:</strong></td>   <td><input type="number" name="product_price" id="insert_product_form_price" min="1" max="100000" placeholder="price"></td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product description:</strong></td>   <td><textarea name="product_desc" rows="10" cols="30" id="insert_product_form_desc" placeholder="type product description"></textarea></td>  </tr>  <tr>   <td align="center" bgcolor="#cccccc"><strong>product keyword:</strong></td>   <td><input type="text" name="product_keyword" id="insert_product_form_keyword" placeholder="type product keyword"></td>  </tr>  <tr>   <td>&nbsp;</td>   <td><input type="submit" name="submit" id="btn" value="submit" /></td>  </tr>  </table>  </form>   <?php include("db.php"); ?>   <?php    if (isset($_post['submit'])) {    $product_category = '';    $product_brand = '';    $product_title = '';    $product_img1_name = '';    $product_img2_name = '';    $product_img3_name = '';    $product_img1_tmp_name = '';    $product_img2_tmp_name = '';    $product_img3_tmp_name = '';    $product_img1_size = '';    $product_img2_size = '';    $product_img3_size = '';    $product_img1_type = '';    $product_img2_type = '';    $product_img3_type = '';    $product_price = '';    $product_desc = '';    $product_keyword = '';    $status = '';    $product_category = $_post['category_id'];    $product_brand = $_post['brand_id'];    $product_title = $_post['product_title'];    $product_img1_name = time() . '_' . $_files['product_img1']['name'];    $product_img2_name = time() . '_' . $_files['product_img2']['name'];    $product_img3_name = time() . '_' . $_files['product_img3']['name'];    $product_img1_tmp_name = $_files['product_img1']['tmp_name'];    $product_img2_tmp_name = $_files['product_img2']['tmp_name'];    $product_img3_tmp_name = $_files['product_img3']['tmp_name'];    $product_img1_size = $_files['product_img1']['size'];    $product_img2_size = $_files['product_img2']['size'];    $product_img3_size = $_files['product_img3']['size'];    $product_img1_type = $_files['product_img1']['type'];    $product_img2_type = $_files['product_img2']['type'];    $product_img3_type = $_files['product_img3']['type'];    $product_price = $_post['product_price'];    $product_desc = $_post['product_desc'];    $product_keyword = $_post['product_keyword'];    $status = 'on';    $uploaded_img_size_limit = 778240;    if ($product_category== '' || $product_brand== '' || $product_title== '' || $product_img1_name== '' || $product_img2_name== '' || $product_img3_name== '' || $product_price== '' || $product_desc== '' || $product_keyword== '') {    echo "<script>alert('please fill form complately !')</script>";    exit();    }    if ($product_img1_size > $uploaded_img_size_limit) {    echo "<script>alert('image 1 size must equal or less 756 kb !')</script>";    exit();    }    if ($product_img2_size > $uploaded_img_size_limit) {    echo "<script>alert('image 2 size must equal or less 756 kb !')</script>";    exit();    }    if ($product_img3_size > $uploaded_img_size_limit) {    echo "<script>alert('image 3 size must equal or less 756 kb !')</script>";    exit();    }    if ($product_img1_type != 'image/jpeg' && $user_picture_type != 'image/jpg' && $user_picture_type != 'image/gif' && $user_picture_type != 'image/png') {    echo "<script>alert('please upload image file in image 1 !')</script>";    exit();    }    if ($product_img2_type != 'image/jpeg' && $user_picture_type != 'image/jpg' && $user_picture_type != 'image/gif' && $user_picture_type != 'image/png') {    echo "<script>alert('please upload image file in image 2 !')</script>";    exit();    }    if ($product_img3_type != 'image/jpeg' && $user_picture_type != 'image/jpg' && $user_picture_type != 'image/gif' && $user_picture_type != 'image/png') {    echo "<script>alert('please upload image file in image 3 !')</script>";    exit();    } else {    $uploaded_images_dir = "uploaded_images/";    move_uploaded_file($product_img1_tmp_name, $uploaded_images_dir . $product_img1_name);    move_uploaded_file($product_img2_tmp_name, $uploaded_images_dir . $product_img2_name);    move_uploaded_file($product_img3_tmp_name, $uploaded_images_dir . $product_img3_name);    $add_product = "insert products (category_id, brand_id, product_title, product_img1, product_img2, product_img3, product_price, product_desc, product_keyword, status,) values ('$product_category', '$product_brand', '$product_title', '$product_img1_name', '$product_img2_name', '$product_img3_name', '$product_price', '$product_desc', '$product_keyword', '$status')";    global $con;    $run_add_product = mysqli_query($con, $add_product);    if ($run_add_product) {    echo "<script>alert('product has been uploaded , added !')</script>";    exit();    }    }        }    ?> 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -