home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 August / PCWorld_2001-08_cd.bin / Komunikace / phptriad / phptriadsetup2-11.exe / htdocs / phpMyAdmin / sql.php < prev    next >
Encoding:
PHP Script  |  2000-08-20  |  3.3 KB  |  100 lines

  1. <?php
  2. /* $Id: sql.php,v 1.26 2000/08/06 13:23:57 tobias Exp $ */;
  3.  
  4. require("lib.inc.php");
  5. $no_require = true;
  6.  
  7.  
  8. if(isset($goto) && $goto == "sql.php")
  9. {
  10.     $goto = "sql.php?server=$server&db=$db&table=$table&pos=$pos&sql_query=".urlencode($sql_query);
  11. }
  12.  
  13. // Go back to further page if table should not be dropped
  14. if(isset($btnDrop) && $btnDrop == $strNo)
  15. {
  16.     if(file_exists($goto))
  17.         include($goto);
  18.     else
  19.         Header("Location: $goto");
  20.     exit;
  21. }
  22.  
  23. // Check if table should be dropped
  24. $is_drop_sql_query = eregi("DROP +(TABLE|DATABASE)|ALTER TABLE +[[:alnum:]_]* +DROP|DELETE FROM", $sql_query); // Get word "drop"
  25.  
  26. if(!$cfgConfirm)
  27.     $btnDrop = $strYes;
  28.  
  29. if($is_drop_sql_query && !isset($btnDrop))
  30. {
  31.     include("header.inc.php");
  32.     echo $strDoYouReally.urldecode(stripslashes($sql_query))."?<br>";
  33.     ?>
  34.     <form action="sql.php" method="post" enctype="application/x-www-form-urlencoded">
  35.     <input type="hidden" name="sql_query" value="<?php echo urldecode(stripslashes($sql_query)); ?>">
  36.     <input type="hidden" name="server" value="<?php echo $server ?>">
  37.     <input type="hidden" name="db" value="<?php echo $db ?>">
  38.     <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : "";?>">
  39.     <input type="hidden" name="table" value="<?php echo isset($table) ? $table : "";?>">
  40.     <input type="hidden" name="goto" value="<?php echo isset($goto) ? $goto : "";?>">
  41.     <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : "";?>">
  42.     <input type="Submit" name="btnDrop" value="<?php echo $strYes; ?>">
  43.     <input type="Submit" name="btnDrop" value="<?php echo $strNo; ?>">
  44.     </form>
  45.     <?php
  46. }
  47. // if table should be dropped or other queries should be perfomed
  48. //elseif (!$is_drop_sql_query || $btnDrop == $strYes)
  49. else
  50. {
  51.     $sql_query = isset($sql_query) ? stripslashes($sql_query) : '';
  52.     $sql_order = isset($sql_order) ? stripslashes($sql_order) : '';
  53.     if(isset($sessionMaxRows) )
  54.         $cfgMaxRows = $sessionMaxRows;
  55.     $sql_limit = (isset($pos) && eregi("^SELECT", $sql_query)) ? " LIMIT $pos, $cfgMaxRows" : '';
  56.     $result = mysql_db_query($db, $sql_query.$sql_order.$sql_limit);
  57.     // the same SELECT without LIMIT
  58.     if(eregi("^SELECT", $sql_query))
  59.     {
  60.         $OPresult = mysql_db_query($db, $sql_query.$sql_order);
  61.         $SelectNumRows = @mysql_num_rows($OPresult);
  62.     }
  63.  
  64.     if(!$result)
  65.     {
  66.         $error = mysql_error();
  67.         include("header.inc.php");
  68.         mysql_die($error);
  69.     }
  70.  
  71.     $num_rows = @mysql_num_rows($result);
  72.  
  73.     if($num_rows < 1)
  74.     {
  75.         if(file_exists($goto))
  76.         {
  77.             include("header.inc.php");
  78.             if(isset($zero_rows) && !empty($zero_rows))
  79.                 $message = $zero_rows;
  80.             else
  81.                 $message = $strEmptyResultSet;
  82.             include($goto);
  83.         }
  84.         else
  85.         {
  86.             $message = $zero_rows;
  87.             Header("Location: $goto");
  88.         }
  89.         exit;
  90.     }
  91.     else
  92.     {
  93.         include("header.inc.php");
  94.         display_table($result);
  95.         if(!eregi("SHOW VARIABLES|SHOW PROCESSLIST|SHOW STATUS", $sql_query))
  96.             echo "<p><a href=\"tbl_change.php?server=$server&db=$db&table=$table&pos=$pos&goto=$goto&sql_query=".urlencode($sql_query)."\"> $strInsertNewRow</a></p>";
  97.     }
  98. }
  99. require ("footer.inc.php");
  100. ?>