Guest User

Untitled

a guest
Jan 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. foreach ($_POST ["data"] as $id => $subs) {
  2.  
  3. foreach ($subs as $key=>$sub) {
  4.  
  5. $subcategory = $sub;
  6.  
  7. if($subs['id']=="$subcategory"){
  8. echo $sql = " insert into x(kodLebuhraya,kodSeksyen) values ('".$subs['id']."','".$sub."')";echo "<br>";
  9. }else{
  10. //echo "hi2";
  11. echo $sql = " insert into x(kodLebuhraya,kodSeksyen) values ('".$subs['id']."','".$sub."')";echo "<br>";
  12. }
  13.  
  14. }
  15.  
  16. }
  17.  
  18. <label>Set One</label>
  19. <input class="location" type="text" name="data[location][]" value=""/>
  20. <input class="shipval" type="text" name="data[shipval][]" value=""/>
  21. <label>Set Two</label>
  22. <input class="location" type="text" name="data[location][]" value=""/>
  23. <input class="shipval" type="text" name="data[shipval][]" value=""/>
  24. <label>Set Three</label>
  25. <input class="location" type="text" name="data[location][]" value=""/>
  26. <input class="shipval" type="text" name="data[shipval][]" value=""/>
  27.  
  28. foreach ($_POST['data']['location'] as $key => $location) {
  29. $shipVal = $_POST['data']['shipval'][$key];
  30.  
  31. //now you have a pair of $location and $shipVal
  32. echo $location.' : '.$shipVal.'<hr>';
  33.  
  34. }
  35.  
  36. $sql = "INSERT INTO x(`kodLebuhraya`,`kodSeksyen`) VALUES ('%s','%s')" ;
  37. printf($sql,mysqli_real_escape_string($_POST['data'][0]),mysqli_real_escape_string($_POST['data'][1]['id']));
  38.  
  39. INSERT INTO x(`kodLebuhraya`,`kodSeksyen`) VALUES ('A','B')
  40.  
  41. <form method="POST">
  42. A : <input id="location" type="text" name="data[]" value="" />
  43. B : <input id="shipval" type="text" name="data[][id]" value="" />
  44. <input id="shipval" type="submit" name="submit" value="Submit" />
  45. </form>
Add Comment
Please, Sign In to add comment