<?php $p = $_GET['p']; $sql = mysql_query('SELECT name,url FROM search WHERE name = "' . $p . '"') or die(mysql_error("rere")); while ($r = mysql_fetch_array($sql)) { print "<p><b>Результат поиска:</b> <a href=index.php?option=content&task=view&id=" . $r['url'] . ">" . $r['name'] . "</a>"; } ?> 

As you understand, in the case of or die will be a void, and I want the inscription PARDON to be displayed. How to fix or die ? or what generally needs to be fixed in the code?

  • one
    mysql_query ($ query) or die! die! die! kill! ;) - Vfvtnjd

5 answers 5

Try to include:

 // Добавлять сообщения обо всех ошибках, кроме E_NOTICE // Это значение включено по умолчанию в php.ini error_reporting(E_ALL ^ E_NOTICE); И для теста замени на: $sql = mysql_query('KAKAYATO LAZA', $not_def) or die("PARDON:" . mysql_error()); 

You definitely have no format error:

 resource mysql_query ( string $query [, resource $link_identifier = NULL ] ) с $link_identifier? 

I would change the code a bit:

 <?php error_reporting(E_ALL ^ E_NOTICE); $p = $_GET['p']; $query = sprintf("SELECT name,url FROM search WHERE name = '%s'", mysql_real_escape_string($p)); $sql = mysql_query($query) or die("Query_error:" . mysql_error()); while ($r = mysql_fetch_array($sql)) { print "<p><b>Результат поиска:</b> <a href=index.php?option=content&task=view&id=" . $r['url'] . ">" . $r['name'] . "</a>"; } ?> 
      or die (print"PARDON"); 

    something like this

    • not working - meravaz
    • or so die ("PARDON"); - vdk company

    In general, this die has always surprised me. This, of course, is sometimes necessary, but do not forget about exception handling . Read useful information.

       or die(mysql_error().' PARDON'); 
      • Unfortunately it does not work, hmm, maybe something better to fix in the code? not or die? - meravaz
      • one
        And you make a mistake in "voluntarily" $ sql = mysql_query ('SELECT name, url FROM search_ERROR WHERE name = "'. $ P. '"') Or die (mysql_error (). 'PARDON'); - Deonis
       die("PARDON"); //либо echo ("PARDON"); die(); //die();die();exit;