Please send questions to
st10@humboldt.edu .
<html>
<!-- try_mysql0.php - see: CAN we connect from PHP to our mysql accounts
on sorrel?
by: Sharon Tuttle
last modified: 11-30-06
-->
<head>
<title> try_mysql0.php </title>
</head>
<body>
<h2> try_mysql0.php - can we connect to mysql? </h2>
<?php
// if you have username and password already...
if ($_POST["_submit_check"])
{
$username = $_POST["username"];
$password = $_POST["password"];
print "HEY YOU!! ABOUT TO TRY TO CONNECT...";
$con = mysql_connect("localhost", $username, $password);
print "<br>ABOUT TO SEE IF CONNECTED...";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// NOTE: on sorrel's mysql, database name is same as username
print "ABOUT TO SELECT DATABASE...";
@mysql_select_db($username) or die("Unable to select database");
print "<br>ABOUT TO CLOSE CONNECTION...";
mysql_close($con);
}
else
{
print '<form method="post" action="' . $_SERVER[PHP_SELF] . '">';
?>
<table>
<tr> <td> Username: </td>
<td> <input type="text" name="username">
</tr>
<tr> <td> Password: </td>
<td> <input type="password" name="password">
</tr>
</table>
<br><br>
<input type="submit" value="Log in">
<input type="hidden" name="_submit_check" value="1">
</form>
<?php
}
?>
</body>
</head>