Location: PHPKode > scripts > PHPSQLQUERY > phpsqlquery/PHP_SqlQuery-From_A_Form.php
<?php
$hostname_site = "(database hostname)";
$database_site = "(database)";
$username_site = "(database user)";
$password_site = "(database user password)";
$site = mysql_pconnect($hostname_site, $username_site, $password_site) or die(mysql_error());


//Connects to the DB
mysql_select_db($database_site, $site);
?>
<title>Query Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<p align="center">&nbsp;</p>
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr> 
    <td width="0" align="left" valign="top"> 
      <form name="form1" method="post" action="/admin/query.php"></p>
        <table width="458" border="1" align="center">
          <tr align="left" valign="top"> 
            <td height="34" colspan="2"> 
              <div align="left">Select the type of SQL Query you are about to 
                run.</div></td>
          </tr>
          <tr> 
            <td width="134"><label> 
              <input type="radio" name="radio" value="Select" checked>
              Select</label></td>
            <td width="178"><input type="radio" name="radio" value="Update">
              Update/Delete/Insert</td>
          </tr>
        </table>
        <p align="center"> 
          <textarea name="SQLQ" cols="90" rows="8"></textarea>
        </p>
        <p align="center"> 
          <input type="Submit" value="Query">
        </p>
      </form>
      <hr> 
      <?php
	  if ($_SERVER['REQUEST_METHOD'] === "POST") {
	 
	
	if ($_POST['radio'] == "Update"){
     $sqlcmd = stripslashes($_POST['SQLQ']);
	 $sql = $sqlcmd;
	$result = mysql_query($sql, $site) or die(mysql_error());
}

else { 
     $sqlcmd = stripslashes($_POST['SQLQ']);
	 $sql = $sqlcmd;
	 $result = mysql_query($sql, $site) or die(mysql_error());
	$row = mysql_fetch_assoc($result);
	$num = mysql_numrows($result);
	 
	echo "<table cellspacing=6><tr>";
	$i=0;
	while($i<mysql_num_fields($result)) {
		$meta=mysql_fetch_field($result,$i);
		echo "<td>" . $meta->name . "</td>";
		$i++;
		}
	echo "</tr>";
		
	while ($pr_row = mysql_fetch_row($result)) {
	echo "<tr bgcolor=#cccccc>";
		foreach ($pr_row as $data)
		
		echo "<td>$data</td>";
		
		}
		echo "</tr>";
		echo "</table>";
		
}
	

		
	
	
		
	  }
	  	   mysql_close($site); 

	  ?>
      <p>&nbsp;</p>
      <p>&nbsp; </p></td>
  </tr>
</table>
</body>
</html>
Return current item: PHPSQLQUERY