Welcome, guest | Sign In | My Account | Store | Cart

Query browser works

add password to this part of the code if you require a password for mysql

Code =

// Connect to the database $conn = mysql_connect('localhost', 'root' 'PASSWORD GOES HERE");

PHP, 75 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Connect to the database
$conn  = mysql_connect('localhost', 'root'); 

// Select the database to use
$Db = mysql_select_db('Table1',$conn); 
?>
</head>
	
<body>
	 <br />
	 <br />
	 <table  align="center" border="1" width="300px">
		 <tr>
			 <th colspan="3"> Query Browser </th>
			</tr>
	 <tr>
		 <td>SQL Command</td>
			 <td>
				 <form method="post" > 
				 <span class="style1"><input type="text" value="SELECT * FROM `table`" size="100" name="input"></span>
     </td>
<td> 
				 <input  type="submit" name="submit" value="GO"/>
				 </form>
			 </td>
		 </tr>
	 <tr>	
	<td colspan="5">
	
<?php
// Query the database
$input = @$_POST['input'];

$result = mysql_query($input) or die('MySQL Error: ' . mysql_error());
?>
			
<?php
	 // And if called for, iterate over the returned rows displaying information
     while($row = mysql_fetch_array($result))
     {
     // Display the information
     echo $row['ID'] . ' ' . $row['Name']. ' ' .
	 $row['Last'] . ' ' . $row['Middle'];
     } 										
?>
	
	 </td>
	 </tr>	
     <tr>
	
	<td >Error Message</td>
	<td colspan="2">
				
<?php 
     // Error handle things
     if($result)
     // Display error message
	 
	 {
	 echo $result;
	 $result ="No Query!";
	 }
	 
	 else
	 
	 {
     echo 'There was an error executing the MySQL query.  
     MySQL returned error number #' . mysql_error() . ' 
     and this explanation:<br />' . mysql_error();
     } 
?> 
	 </td>
	 </table>
	 </Body>
</Html>