Hi,
I am trying to develop a php page where user can write mysql query (select, insert, update) and run.
I have developed one for select query. here is the code:
<?
/***************************
* Author: P. Sengupta
* Used for Admin Utility only
***************************/
?>
<br>
<h2>Run SELECT Query</h2>
<?
$query=$_POST["query"];
?>
<form action="#" method="post">
<textarea name="query" cols="80" rows="10">
<?=$query?>
</textarea>
<br>
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</form>
<?php
if (empty($query)) {
echo "<br>Enter query...";
exit;
}
else {
$q = str_replace (" ", "", $query);
if (string_begins_with(strtoupper($q), 'SELECT')) {}
else {
echo "<font color=red>Sorry! Only SELECT statement is allowed. The query expression you entered does not seem like a SELECT statement...</font>";
exit;
}
}
//echo "here....";
include 'config.php';
//$query=" select * from store_items ";
getDBLink();
$result = mysql_query($query);
if (mysql_errno()) {
echo "<font color=red>MySQL error ".mysql_errno().": ".mysql_error()."</font>";
exit;
}
if (!$result) {
echo "No result found... Check the query...</font>";
exit;
}
$num = mysql_num_rows ($result);
if ($num==0) {
echo "<font color=red>Zero records found</font>";
exit;
}
else {
echo "<font color=blue>$num records found.</font><br>";
}
$fields = mysql_num_fields($result);
echo "<table cellspacing=1 cellpadding=2 bgcolor=#000000><tr bgcolor=#cccccc>";
for($count=0;$count<$fields;$count++) {
$field = mysql_fetch_field($result,$count);
echo "<td>$field->name <br>($field->type)</td>";
}
echo "</tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<tr bgcolor=#ffffff>";
for($count=0;$count<$fields;$count++) {
echo "<td>$row[$count] </td>";
}
echo "</tr>";
}
mysql_close();
echo "</table>";
function string_begins_with($string, $search)
{
return (strncmp($string, $search, strlen($search)) == 0);
}
?>
Now I want to modify this page for working all three (select, insert and update) quires together. can anybody
please help me??
MY mail id : prasenjitsengupta2005@gmail.com