Please send questions to st10@humboldt.edu .
<html> 
 
<!-- try_mysql1.php - see: CAN we create a mysql table via PHP
     on sorrel? 
      
     by: Sharon Tuttle 
     last modified: 11-30-06 
--> 
 
<head> 
    <title> try_mysql1.php </title> 
</head> 
 
<body> 
<h2> try_mysql1.php - can we create a pets table? </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");

        // try to create a new table named pets...

        $command = "create table pets ". 
                   "(pet_id         int not null, ". 
                   " pet_name       varchar(15), ".
                   " pet_birth      date, ". 
                   " num_siblings   int, ".
                   " primary key    (pet_id))";

        mysql_query( $command, $con ) or die("Could not create pets table");

        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>