<form action="http://holland.mathcs.emory.edu/~cs377001/Web/query.php"
method="POST">
<p>
Query:
<P>
<TEXTAREA
name="query" rows="20" cols="60">
</TEXTAREA>
<p> Press to execute query: <input type="submit" value="Send">
<p> Press to clear input: <input type="reset">
</form>
|
<html>
<head>
<title> CS377 MySQL Web client</title>
</head>
<body>
<H3>
<HR>
Answer to the query
<HR>
</H3>
<P>
<UL>
<?php
$conn = mysqli_connect("holland.mathcs.emory.edu","cs377", "abc123", "companyDB");
if ( mysqli_connect_errno() != 0 ) # ----------- check connection error
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit(1);
}
$query = $_POST['query']; # Get the query input from the webpage
print("<UL><TABLE bgcolor=\"#FFEEEE\" BORDER=\"5\">\n");
print("<TR> <TD><FONT color=\"blue\"><B><PRE>\n");
print( $query ); # echo the query
print("</PRE></B></FONT></TD></TR></TABLE></UL>\n");
print("<P><HR><P>\n");
if ( ($result = mysqli_query($conn, $query)) == NULL ) # Execute query
{
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
print("<UL>\n");
print("<TABLE bgcolor=\"lightyellow\" BORDER=\"5\">\n");
# ------------------------------------------------------------
# Print names of attributes in one row of the table
# ------------------------------------------------------------
print("<TR bgcolor=\"lightcyan\">\n"); # Start row of HTML table
while ( ($field_details = mysqli_fetch_field($result)) != NULL )
{
print ("<TH>" . $field_details->name . "</TH>"); # One item in row
}
print ("</TR>\n"); # End row of HTML table
# ------------------------------------------------------------
# Print the tuples
# ------------------------------------------------------------
while ( ($row = mysqli_fetch_row( $result )) != NULL )
{
# Print one tuple as a row in table
print("<TR>\n"); # Start row
for ( $i = 0; $i < count($row); $i++ )
{
print ("<TD>" . $row[$i] . "</TD>"); # Print values in one row
}
print ("</TR>\n"); # End row
}
print("</TABLE>\n");
print("</UL>\n");
print("<P>\n");
mysqli_free_result($result);
mysqli_close($conn);
?>
</UL>
<P>
<HR>
<HR>
<HR>
<HR>
|
Note: this program is almost the same program to execute a query discussed here: click here
I made these changes:
|