Location: PHPKode > projects > Wexplorer > weXplorer/query.php
<?php
/*
 * Created on 8 nov. 2005
 *
 */
require_once('config.inc.php');
session_start();
?>
<html>
<head>
<title>Query</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<table border="1">

<?php
if(!isset($_SESSION['logged'])){ 
	if(trim($_POST['query'])==ADMIN_PASSWD){
		unset($_POST['query']);
		$_SESSION['logged'] = true;
		echo "Query 'bye' to log out.";
	}  else if(trim($_POST['query'])!="")
		echo "Wrong pass phrase. Please log in";
	else 
		echo "Please log in";
} else if(trim($_POST['query'])=="bye"){
	session_destroy();
	unset($_POST['query']);
}
if(isset($_SESSION['logged'])){
	$db = sqlite_open(LOGFILE, 0666, $sqliteerror);
	if (!$db)
		die($sqliteerror);
	
	if (isset($_POST['query'])&&trim($_POST['query']!="")){
		$_POST['query']=	stripcslashes($_POST['query']);
			
		$query = sqlite_query($db,$_POST['query']);
		$result = sqlite_fetch_all($query, SQLITE_ASSOC);
		 
		foreach ($result as $entry) {
			if(!$headerprinted){
				echo "<tr bgcolor='cccccc'><td>";
				echo join("</td><td>", array_keys($entry))."\n";
				echo "</td></tr>";
				$headerprinted = true;
			}
			echo "<tr><td>";
			echo join("&nbsp;</td><td>", $entry)."\n";
			echo "</td></tr>";
		}
		if(!$headerprinted)
			echo "<pre>No results</pre>";
	} else {
	 	$_POST['query'] = "SELECT * FROM log LIMIT 30";
	}
} 

?>

<table>
<form name="query" method="post" action="">
  <textarea id="queryarea" name="query" cols="50" rows="10"><?php echo $_POST['query']; ?></textarea>
  <input type="submit" name="Submit" value="Submit">
</form>
<script language="JavaScript" type="text/javascript">
	document.getElementById('queryarea').focus();
</script>
<pre>For query syntax see: <a href="http://www.sqlite.org/">http://www.sqlite.org/</a> 
</pre>

</body>
</html>
Return current item: Wexplorer