<?php

/**
 * 
 *
 * @version 1.0.0
 * @copyright www.azzozhsn.net 2005 
 **/


?>
<html>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1256">
<TITLE>SQL+ ......   by azzozhsn.net</TITLE>
</HEAD>
<b><font size="6">SQL</font><sup><font size="7">+</font></sup></b><br>
by azzzozhsn.net
<hr>
<?php
	$query = $_REQUEST['qurey'];
	$query = str_replace("\'", "'", $query);
	$link = mysql_connect('localhost', 'root', '');
	$database = $_REQUEST['database'];
	if (! $database) {
	    $error = 'Yuo must select database';
	}
    mysql_select_db($database);
	if ($query) {
					
		$result = mysql_query($query);
		$j = @mysql_num_fields($result);
		$i = @mysql_num_rows($result);
		
		echo "<table><tr bgcolor=\"#aaaaaa\">";
		for ($x = 0; $x < $j; $x++)
		{
			$field[$x] = mysql_fetch_field($result);
			echo "<td>{$field[$x]->name}</td>";
		}
		for ($x = 0; $x < $i; $x++)
		{
			$color = ($x%2)?'#cccccc':'#eeeeee';
			echo "<tr bgcolor=\"$color\">";
			
			$row = mysql_fetch_array($result);
			for ($y = 0; $y < $j; $y++)
			{
				echo '<td>'.$row[$y].'</td>';
			}
			echo '</tr>';
		}
		if (mysql_errno()) {
		    $error = mysql_errno().": ".mysql_error();
		}
	}
	echo '</table>
	<table><tr>
	<td with="25%">
	<form method="POST" action="sql+.php">';
	$db_list = mysql_list_dbs($link);
	while ($row = mysql_fetch_object($db_list)) 
	{
		if ($database == $row->Database) {
		    echo "<input type=\"radio\" value=\"".$row->Database."\" checked name=\"database\"> ".$row->Database."\n";
		}
		else
		{
			echo "<input type=\"radio\" value=\"".$row->Database."\" name=\"database\"> ".$row->Database."\n";
		}
		echo "<br>";
	}
?>
	</td>
	<td width="75%" valign="top">
	<textarea rows="8" name="qurey" cols="70"><?echo $query?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
	<font color="red"><?echo $error?></font><br>
	<input type="submit" value="Just do it" name="Submit"><td>
</tr></table>
</form>