php与mysql入门程序
    我们在学习一门语言或数据库时,一般先编写一个登录程序,输入用户名和密码,然后
创建一个表,插入数据,然后检索所插入的程序。以下给出该部分的源代码,希望对php与mysql
的入门人有帮助。

test1.htm:

<html>
<head>
<title>php与mysql入门程序</title>

<br>
<form method="post" action="test1.php3">
  <p>数据库名: 
    <input type="text" name="dbname" value="">
    用户名称: 
    <input type="text" name="username">
  </p>
  <p>用户密码: 
    <input type="text" name="userpassword">
    <input type="submit" name="Submit" value="提交">
    <input type="reset" name="Submit2" value="清空">
  </p>
</form>

</head>
</html>

该部分程序提供录入用户名和密码,然后调用test1.php3

test1.php3:

<?php 
//完成功能:
//执行数据库登录,删除表test1,创建一个表 test1,插入一条数据,然后查询并显示该值

$dbnameall $dbname.":3306";
//显示数据库名,用户名,密码
echo 'dbname   is:'.$dbnameall."<BR>";
echo 
'username is:'.$username."<BR>";
echo 
'password is:'.$userpassword."<BR>";
//连接数据库
$dbh =  mysql_connect($dbnameall,$username,$userpassword); 
//打开数据库,根据情况修改数据库名
mysql_select_db('test'); 

$query "drop table test1"
$res mysql_query($query$dbh); 

$query "create table test1(s1 char(10))"
$res mysql_query($query$dbh); 

$query "insert into test1(s1) values ('test1')"
$res mysql_query($query$dbh); 

$query "select max(s1) from test1"
$res mysql_query($query$dbh); 

$err mysql_error(); 
if(
$err){ 
  echo 
"发生错误,请通知站长</a>"

  
$row mysql_fetch_row($res); 
  echo 
"当前最大值的第一列为: ".$row[0]; 
?> 


说明: 以上程序用最简单的代码描述了mysql在php中使用的语法,
   大家可尝试查询所有的数据并通过表格形式体现出来。