PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

Страниц (1): [1]

> Найдено сообщений: 4
enermult Отправлено: 03 Мая, 2011 - 15:42:26 • Тема: метод post. • Форум: Если скрипт не работает

Ответов: 7
Просмотров: 14998
большое всем спасибо за помощь, работают оба кода.
косяк в серваке был, перенастроил все по инструкции с сайта, заработало.
enermult Отправлено: 03 Мая, 2011 - 03:32:57 • Тема: метод post. • Форум: Если скрипт не работает

Ответов: 7
Просмотров: 14998
отдельно все ок, если вводим через форму, браузер выплевывает:
Цитата:
" . mysql_error()); mysql_select_db("dbcurse") or die("Can't select database!
" . mysql_error()); function universal_like_escape($str) { return '%'.str_replace('*','%',addCslashes(mysql_real_escape_string(str_replace('\\','\\\\',$str)), '_%')).'%'; } if(isset($_POST['search_query'])) { //start script $search_query = universal_like_escape ($_POST['search_query']); $result= mysql_query( "SELECT * FROM films WHERE title LIKE '$search_query' OR director LIKE '$search_query' OR duration LIKE '$search_query' OR year LIKE '$search_query' ORDER BY year DESC" ); if (($count_rows = mysql_num_rows($result)) > 0) { echo "Found $count_rows match!
"; while ($row=mysql_fetch_assoc($result)) { echo "The original title of the film is: {$row[title]}.
The director's name of the film(s) is: {$row[$director]}.
The duration of the film(s) is: {$row[duration]} minutes.
The year of the film(s) is: {$row[year]}.
"; } } else { echo "Sorry, couldn't find anything about your query ({$_POST[search_query]})"; } } else { echo 'переменная $_POST[search_query] не передана скрипту'; } ?>

может у меня в компе бесы, хотя врядли.
enermult Отправлено: 03 Мая, 2011 - 00:25:35 • Тема: метод post. • Форум: Если скрипт не работает

Ответов: 7
Просмотров: 14998
убирал, результат такой же, только еще вылезает 5 "notice: undefined variable: $search_query..." про 15,16 и 22 строчку...
enermult Отправлено: 02 Мая, 2011 - 23:26:14 • Тема: метод post. • Форум: Если скрипт не работает

Ответов: 7
Просмотров: 14998
Доброго времени суток!
Я недавно начал изучать php, и возникла проблема с написанием кода.
Вообщем у меня есть база с инфой о фильмах (название, режиcсер, время фильма и год).
Я хочу сделать поиск по этой базе, но у меня почему-то из формы для запроса ничего не передается.

Вот форма:
CODE (html):
скопировать код в буфер обмена
  1.  <html>
  2.  <head>
  3.  <title>Search</title>
  4.  </head>
  5.  <body>
  6.  <center>
  7.  Enter the original title, director's name, duration or year of the film you are looking for:
  8.  <form action="search.php" method="post" onsubmit="javascript: if ((search_query.value=='')||(search_query.value=='Поиск...')) { return false; } else { return true; }">
  9.  <input type="text" name="search_query" onfocus="if (this.value=='Поиск...') this.value=''" value="Поиск..." style="font: 12px Verdana; height:20px; width:200px;" />
  10.  <input type="submit" name="name" value="Найти" style="font: bold 12px Verdana; background-color:#FFFFFF; height:20px; width:50px;"/>
  11.  </form>
  12.  </center>
  13.  </body>
  14.  </html>

вот search.php:
PHP:
скопировать код в буфер обмена
  1. <html>
  2.  <head>
  3.  <title>Search Results</title>
  4.  </head>
  5.  <body>
  6.  <?PHP
  7.  mysql_pconnect ("localhost", "root", "pass") or die ("Can't connect!");
  8.  mysql_select_db("dbcurse") or die("Can't select database!");
  9.  
  10.  global $search_query;
  11.  
  12.  if(isset($_POST['search_query'])){$search_query = $_POST['search_query'];}
  13.  
  14.    
  15.   $query= mysql_query("SELECT * FROM films WHERE title = '$search_query' OR director = '$search_query' OR duration = '$search_query'
  16. OR year = '$search_query' ORDER BY year DESC");
  17.  
  18.  
  19.   $result= mysql_num_rows($query);
  20.  if ($result == 0)
  21.  {
  22.   echo "Sorry, couldn't find anything about your query ($search_query)";
  23.  exit;
  24.  }
  25.  else if ($result == 1)
  26.  {
  27.  echo "Found <b>1</b> match!<br>";
  28.  }
  29.  else {
  30.  echo "Found <b>$result</b> matches! <br>";
  31.  }
  32.  
  33.    while ($row= mysql_fetch_array($query))
  34.  {
  35.  
  36.  $title= $row["title"];
  37.  $director = $row["director"];
  38.  $duration = $row["duration"];
  39.  $year= $row["year"];
  40.  
  41.  echo "The original title of the film is: $title.<br>";
  42.  echo "The director's name of the film(s) is: $director.<br>";
  43.  echo "The duration of the film(s) is: $duration minutes. <br>";
  44.  echo "The year of the film(s) is: $year.<br>";
  45.  }
  46.  
  47.  ?>
  48.  </body>
  49.  </html>

когда я что-то ввожу в форму и жму "найти", в браузере вылезает следующее:
Цитата:
1 match!
"; } else { echo "Found $result matches!
"; } while ($row= mysql_fetch_array($query)) { $title= $row["title"]; $director = $row["director"]; $duration = $row["duration"]; $year= $row["year"]; echo "The original title of the film is: $title.
"; echo "The director's name of the film(s) is: $director.
"; echo "The duration of the film(s) is: $duration minutes.
"; echo "The year of the film(s) is: $year.
"; } ?>

это пишется независимо от того, есть ли это в базе, один там результат, несколько или вообще ничего.
когда просто запускаю search.php все работает, на монитор выводится:
Цитата:
Sorry, couldn't find anything about your query ()
, т.к. ничего не запрошено,
или я могу, например, в ручную установить значение, заменив 12 строчку в search.php на:
, запустив его, мне вылезет:
Цитата:
Found 2 matches!
The original title of the film is: Inception.
The director's name of the film(s) is: Nolan.
The duration of the film(s) is: 148 minutes.
The year of the film(s) is: 2010.
The original title of the film is: The Town.
The director's name of the film(s) is: Affleck.
The duration of the film(s) is: 124 minutes.
The year of the film(s) is: 2010.
как я и хочу, то что есть в базе.

Насколько я понимаю, проблема в том, что из формы отправки не передаются значения, а значит проблема в ней. Или передаются, но у меня никак не получается их вытащить из POST, т.е. я как-то неправильно пишу 12ю строчку в search.php.

Пожалуйста, помогите разобраться, сам никак не могу найти свою ошибку.
Заранее благодарен.

Страниц (1): [1]
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB