here is my code for the query_proc sheet
<?/* connect to DB */
function connect_to_db()
{
if(!mysql_connect("localhost","ise456","153103"))
{
echo "<h3>Cannot connect to the database</h3>";
echo "<h3>Check Login Info</h3>";
die();
}
mysql_select_db("ISE456");
}
/* Writes out a table from a single result query. */
function make_table($query_result)
{
$row = mysql_fetch_array($query_result);
// Make header
$table = "<table><tr>";
for($i = 0; $i < mysql_num_fields($query_result); ++$i)
{
$table .= "<th BGCOLOR='00CCFF'>". mysql_field_name($query_result,$i). "</th>";
}
$table .= "</tr>\n<tr BGCOLOR='009966'>";
// Make first row
for($i = 0; $i < mysql_num_fields($query_result); ++$i)
{
$table .= "<td>" . $row[mysql_field_name($query_result,$i)]. "</td>";
}
$table .= "</tr>\n";
//Fill rest of the table
$row_color = "009966";
while( $row=mysql_fetch_array($query_result))
{
($row_color == "009966")? $row_color = "#9900FF" : $row_color = "009966";
$table .= "<tr BGCOLOR='". $row_color ."'>";
for($i = 0; $i < mysql_num_fields($query_result); ++$i)
{
$table .= "<td>" . $row[mysql_field_name($query_result,$i)]. "</td>";
}
$table .= "</tr>\n";
}
$table .= "</tr></table>";
return $table;
}
// make new queries
$sql="INSERT INTO table (NUM, NAME, STATUS, CITY) VALUES ('$_POST[NUM]','$_POST[NAME]','$_POST[STATUS]','$_POST[CITY]')";
if (!mysql_query($sql))
{
die();
}
echo "Successful Insert!";
?>
here is the code for the queries sheet:
<html>
<body>
<h3> PHP Query Processor </h3>
<form name="input" action="queries.php" method="get">
<textarea name="query" rows="10" cols="20">Type Query Here</textarea><br>
<input type="submit" value="Run Query">
</form>
<hr>
<?
// Load query and remove escape slashes
$query = stripslashes($_GET["query"]);
// Check for a null query
($query == "" || $query == "Type Query Here" ) ? die() : "";
include("query_proc.php");
connect_to_db();
$result= mysql_query($query)
or die("Query ".$query." falied--> error message: " . mysql_error());
echo "<Table><tr><td name='querytable' valign='top' width=150 bgcolor='33FF99'><FONT COLOR='9966FF'>"
. $query . "</color></td><td>" . make_table($result) . "</td></table>";
?>
</body>
</html>

New Topic/Question
Reply




MultiQuote




|