Advertisement
wotyl

wqeq

Dec 4th, 2014
1,341
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. mysql_query("SET NAMES utf8");
  3. $query = mysql_query("select * from tovar");
  4. if($query == false) { die("чото не чотко");}
  5. $row = mysql_fetch_array($query); /* Сразу вытаскиваем массив */
  6. echo '</table>
  7. <table class="simple-little-table" cellspacing="0" border="1" style: "min-width: 100%; style: "max-width: 100%;">
  8. <tr>
  9. <td>id</td>
  10. <td>Товар</td>
  11. <td>Удалить</td>
  12. <td>Изменить</td>
  13. <td>Новое назв.</td>
  14. </tr>';
  15. while($row = mysql_fetch_row($query))
  16. { print "<tr>
  17. <td>{$row['0']}</td>
  18. <td>{$row['1']}</td>
  19. <form method='post' action=''>
  20. <td><input name='del' class='btn btn-primary' type='submit' value='Del'></td>
  21. <td> <input name='red' class='btn btn-primary' type='submit' value='Ren'></td>
  22. <td><input name='id' type='hidden' value='". $row['0'] ."'>
  23. <input name='namered' type='text' value='". $row['1'] ."'></td>
  24. </form>
  25. </td>
  26. </tr>";
  27. };
  28. echo "</select>";
  29. if ( isset ( $_POST['del'] )){$sql1 =mysql_query ("DELETE FROM `tovar` WHERE tovar_id='".$_POST['id']." ' ");}
  30. elseif ( isset ( $_POST['red'] ))
  31. {//!!!!САМ ЗАПРОС!!!! В самом запросе указываем переменные $_POST['namered'] и $_POST['rentred']
  32. $sql2 =mysql_query ("UPDATE tovar SET tovar_name='". $_POST['namered']."' WHERE tovar_id='".$_POST['id']." ' ");
  33. if($sql2 == false){ echo "неполучилось";}
  34. else { $url = $_SERVER['REQUEST_URI']; echo "<script>location.href='".$url."'</script>"; /* Перенаправляемся на страницу редактирвоания сбрасывая переменные $_POST['del'] и/или $_POST['red'] */}
  35. }
  36.  
  37. ?>
Advertisement
RAW Paste Data Copied
Advertisement