ID: 12168
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Closed
Bug Type: MySQL related
Operating System: Windows 2000
PHP Version: 4.0.6
Previous Comments:
------------------------------------------------------------------------
[2001-07-14 12:24:43] [EMAIL PROTECTED]
This is a two part script, query.php and mysqltest.php. It's a script that executes a
query on the selected database. But I get an error that says that there is no
database selected. I'm using IIS 5. This is the first page:
<html>
<head>
<title>PHP Code Tester</title>
</head>
<body>
<!-- query.php -->
<?
$host = "localhost";
$user = "dan";
$pass = "moops";
?>
<form action="mysqltest.php">
Please select the database for query:<br><br>
<select name=database>
<?
mysql_connect($host, $user, $pass);
$dbTable = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($dbTable); $i++) {
echo "<option value=\"" . mysql_tablename($dbTable, $i) . "\">" .
mysql_tablename($dbTable, $i) . "\n";
}
?>
</select>
<br><hr>
Please input the SQL Query to be executed:<br><br>
<textarea name="query" cols=50 rows=10></textarea><br><br>
<input type=submit value="Execute Query!">
</form>
</body>
</html>
Sorry if this is a bit long, but this is the second page:
<html>
<head>
<title>PHP SQL Code Tester</title>
</head>
<body>
<!-- mysqltest.php -->
<?
$host = "localhost";
$user = "dan";
$pass = "moops";
mysql_connect($host, $user, $pass);
$query = stripSlashes($query);
$result = mysql_db_query($database, $query);
?>
Results of query <b><? echo $query; ?></b><hr>
<?
if ($result == 0):
echo "<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>";
elseif (mysql_num_rows($result) == 0):
echo "Query executed successfully!</b>";
else:
?>
<table border=1>
<tr>
<?
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo "<td>" . mysql_field_name($result, $i) . "</td>";
}
?>
</tr>
<?
for ($i = 0; $i < mysql_num_rows($result); $i++) {
echo "<tr>";
$rowArray = mysql_fetch_rows($result);
for ($j = 0; $j < mysql_num_fields($result); $j++) {
echo "<td>" . $rowArray[$j] . "</td>";
}
echo "</tr>";
}
?>
</table>
<? endif ?>
<hr><br>
<form action=query.php method=post>
<input type=submit value="New Query">
</form>
</body>
</html>
I'm using the win32 binary of PHP. While I was installing PHP it ran into an error
saying it couldn't configure for IIS, and that I had to manually do it. I set it up
and all the scripts run fine except for when I have to select a database.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12168&edit=1
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]