douwei1174 2017-09-19 08:11
浏览 15

too long

I have Html table in which row can be added by add button if needed. Row contains size dropdown and color dropdown. In database i have 2 tables product_size and product_color, i have a condition that if two row sizes values are same then it should have same product_size_id(that is primary key of product_size table otherwise different product_size_id). I am sharing my code please help if anyone can point out where problem is. CODE:

for ($i=0; $i<count($_POST['size']); $i++){
    $size = $_POST['size'][$i];
    $qry1="INSERT INTO product_size (product_id, product_size) VALUES ('$product_id', '$size')";
    $result1=mysqli_query($con,$qry1);
    $insertid=mysqli_insert_id($con);
    if($result1)
    {
    $newqry="SELECT * from product_size where product_size_id='".$insertid."'";
    $newresource=mysqli_query($con,$newqry);

     $newresult=mysql_fetch_array($newresource);

      if ($newresult['product_size']== $_POST['size'][$i]) 
          {
              $product_size_id= $newresult['product_size_id'];
          }

      else
          {    
              $product_size_id = $insertid; /*it always going to this condition*/
          }

    $quantity = $_POST['dress_quantity'][$i];
    $color = $_POST['color'][$i];
    $qry2="INSERT INTO product_color (product_size_id, product_color, product_quantity) VALUES ('$product_size_id', '$color', '$quantity')";
    $result2=mysqli_query($con,$qry2); 
    echo '<script>alert("Item Added Successfully!")</script>';
    echo '<script>window.location="try.php"</script>';

  }
}

//HTML CODE:

<TABLE id="dataTable">
  <thead>
  <tr>
  <th style="text-align: center;">&nbsp;Select&nbsp;</th>    
  <th style="text-align: center;">&nbsp;<b>Size</b>&nbsp;</th>
  <th style="text-align: center;">&nbsp;<b>Color</b>&nbsp;</th>
  <th><b>Quantity</b></th>
  </tr>
  </thead>

  <tbody>
  <tr id='C1' class='customer'>
  <td><input type="checkbox" name="chk"/></td>
  <td><select  name="size[]" id="size" required="" >
  <option value="">Select Size</option>
  <option value="Small">Small</option>
  <option value="Medium">Medium</option>
  <option value="Large">Large</option>
  <option value="X-Large">X-Large</option>
  </select></td>
  <td>
  <select name="color[]" required="" >
    <option value="">Select Color</option>
    <option value="Aqua">Aqua</option>   
    <option value="Blue">Blue</option>   
    <option value="Black">Black</option>    
    <option value="Green">Green</option>   
  </select></td>

  <td>
  <input style="width: 120px; height: 26px; " type="number" name="dress_quantity[]" class="qty1" onchange="calculate();" min="1" max="1000" maxlength="4" placeholder="Size Quantity" value="" required="">  

  </td>
  </tr>
  </tbody>
  </TABLE>
  <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
  <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害