Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1.  <?
  2. /* Переменные для соединения с базой данных */
  3. $hostname = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbName = "video";
  7.  
  8. /* Таблица MySQL, в которой хранятся данные */
  9. $filmstable = "films";
  10. $customerstable = "customers";
  11. $orderstable = "orders";
  12.  
  13.  
  14. /* создать соединение */
  15. mysql_connect($hostname,$username,$password) OR DIE("Can not establish connection");
  16. /* выбрать базу данных. Если произойдет ошибка - вывести ее */
  17. mysql_select_db($dbName) or die(mysql_error());
  18.  
  19. $namefilm = $_GET['film'];
  20. $namecustomer = $_GET['customer'];
  21. $date = $_GET['date'];
  22. $returndate = $_GET['returndate'];
  23. $query = "SELECT $customerstable.*, $filmstable.* FROM $filmstable, $customerstable WHERE '$filmstable.name_film' = '$namefilm' AND '$customerstable.name_customer' = '$namecustomer' ";
  24. $res = mysql_query($query) or die(mysql_error());
  25. echo $query;
  26.  
  27. $number_orders = mysql_num_rows($res);
  28.  
  29. if($number_orders == 0) {
  30.   echo "<CENTER><P>No films or customers with this name found in the database</CENTER>";
  31. }                                                                                                                          
  32. $query = "INSERT INTO $orderstable (id_film, id_customer, order_date, expiration_date) VALUES('$filmstable.id_film', '$customerstable.id_customer', '$date', .$returndate)";
  33. /* Выполнить запрос. Если произойдет ошибка - вывести ее. */
  34. mysql_query($query) or die(mysql_error());
  35. echo "Order: ".$namefilm." for ".$namecustomer." from ".$date." until ".$returndate." was added.<BR>";
  36. /* Закрыть соединение */
  37. mysql_close();
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement