欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

图书管理程序(二)

程序员文章站 2022-06-22 15:27:31
图书目录输入部分:
图书目录输入部分:
<?
if(!$uploadaction):
?>
<?
//本程序是为输入书名,作者、出版社资料而设。
//编者:孔秀祥。日期:2001/3/24
/*
session_start();
if (!isset($auth_passed)) {
echo "本功能只有授权用户才能使用。";
return -1;
}

if(isset($u_name)) {
  session_name($u_name);

//echo "<center><font color='red'>".session_name().":本程序将竭诚为您服务。</font></center>\n";
//echo "<hr>";
}
*/
?>
<html><head>
<title>图书目录输入 </title>
</head>
<body><table align=center>
<form enctype= "multipart/form-data" name = "submitform"
action= "<? $php_self ?>" method = "post">
<input type= "hidden" name = "max_file_size" value ="20000000">
<input type= "hidden" name = "uploadaction" value = "1">

<!--tr><td>文件名<td><input name = "uploadfile" type = "file" value="" size = "30"></tr-->
<tr><td align=center>著作名<td><input name = "b_name" type = "text" value="" size = "30" maxlength=100></td></tr>
<tr><td align=center>作者<td>姓<input name = "a_first1" type = "text" value="" size = "6" maxlength=20>
名<input name = "a_last1" type = "text" value="" size = "6" maxlength=20></td></tr>
<tr><td align=center>作者<td>姓<input name = "a_first2" type = "text" value="" size = "6" maxlength=20>
名<input name = "a_last2" type = "text" value="" size = "6" maxlength=20></td></tr>
<tr><td align=center>作者<td>姓<input name = "a_first3" type = "text" value="" size = "6" maxlength=20>
名<input name = "a_last3" type = "text" value="" size = "6" maxlength=20></td></tr>
<td>编著方式</td>
<td>
<select size="1" name="author_type" type = "int" default=11>
<option selected value="11">  著 </option>
<option selected value="12"> 编著 </option>
<option value="13"> 主编</option>
<option value="14">副主编</option>
<option value="15">  参编</option>
<option value="16">   注 </option>
<option value="17">   编 </option>
<option value="18">   选 </option>
<option value="19">   评 </option>
<option value="20"> 其他</option>
</select>
  定价<input name = "b_price_a" type = "text" value="" size = "3">.<input name = "b_price_b" type = "text" value="" size = "2">元
</tr>

<tr><td align=center>出版社<td><input name = "p_name" type = "text" value="" size = "30" maxlength=100></td></tr>
<tr><td>出版日期<td><input name = "p_year" type = "text" value="" size = "4">年
<input name = "p_month" type = "text" value="" size = "2">月  
<tr><td>isbn<td><input name = "isbn" type = "text" value="" size = "25">

<tr><td rowspan=5>有关书的说明</td>
<!--/tr><tr-->
<td rowspan=5><textarea wrap=on rows="5" cols="30" name = "b_comment" size = "255">
</textarea></td>
</tr>
</table>

<table align=center>
<tr><td align=center>
<input name = "submit" value = "提交" type = "submit">
<td><input name = "reset" value = "重置" type = "reset">
</td></tr>
</form></center></table></body>

</html>

<?

else:
session_start();
require "config.php3";

$b_price=trim($b_price_a)."\.".trim($b_price_b);
if(strlen($p_month)==1)
     $p_month="0".trim($p_month);
if($p_month=="")
    $p_month="01";
$date_pub=trim($p_year)."-".trim($p_month)."-01";

$uploadaction=0;
$repeat=0;      //是不是重复了。
$timelimit=0; //设置超时限制时间缺省时间为 30秒设置为0时为不限时
set_time_limit($timelimit);
@mysql_connect($hostname,$dbusername,$dbpassword) or die("不能连接数据库!");
@mysql_select_db("$dbname") or die("不能选择数据库!");
//$q="select books.books_id, books.books_name,author.first_name,author.last_name,publisher.publisher_name from books,author,books_author,publisher where books.books_name=\"$b_name\" and books.publisher_id=publisher.publisher_id and books.books_id=books_author.books_id and books_author.author_id=author.author_id";

$b_name=trim($b_name);
$sele="select books.books_id, books.books_name,author.first_name,author.last_name,publisher.publisher_name,books.isbn,books.price,books.date_pub,books.pages";
$fro=" from books,author,books_author,publisher ";
if(trim($isbn)!="")
    $whe="where books.isbn=\"$isbn\" ";
elseif(trim($a_first1)!="" && trim($a_last1)!="" && trim($p_name)!="")
    $whe=" where books.books_name=\"$b_name\" and books.publisher_id=publisher.publisher_id and books.books_id=books_author.books_id and books_author.author_id=author.author_id";
else{
    $msg="书名为必填,其他如果isbn为空,则作者的姓、名,出版社为必填。<br>请检查是否符合要求。";
    xueroom_error_exit($msg,$php_self);

}
$q="$sele$fro$whe";

/*
books.books_id,  
books.books_name,
author.first_name,
author.last_name,
publisher.publisher_name
books.isbn,
books.price,
books.date_pub,
books.pages
*/
$r = @mysql_query($q);
//             $count=@mysql_fetch_row($r);
//             echo "书名".$count[1]."<br>";
if(!$r){
    echo "查询无效 <br>";
    exit;
}
if(mysql_num_rows($r)){
    if(trim($isbn)!=""){
        echo "数据重复。<br>";
        exit;
    }
    else
while($count=mysql_fetch_array($r)){  
/*
          echo "while。<br>";
          echo trim($a_first1);
          echo trim($count[2]);
          echo trim($a_first1)==trim($count[2]);
          echo "<br>";
          echo trim($a_last1)==trim($count[3]);
          echo "<br>";
          echo trim($p_name)==trim($count[4]);
          echo "<br>";
          */
    if( trim($a_first1)==trim($count[2]) && trim($a_last1)==trim($count[3]) && trim($p_name)==trim($count[4])){
        $data_exist+=1;
        $books_id=$count[0];
        $books_name=$count[1];     
        $first_name=$count[2];
        $last_name=$count[3];
        $repeat=1;
        echo "本书已经在数据库中。<br>";     
        echo "<font color='red'>书名:</font>".$books_name;
        echo "<br><font color='blue'>作者:</font>".$first_name.$last_name;
        echo "<br><font color='red'>国标标准书号:</font>".$count[5];
        echo "<br><font color='blue'>书价:</font>".$count[6]."元";
        echo "<br><font color='red'>出版日期:</font>".substr($count[7],0,4)."年".substr($count[7],5,2)."月";
        if($count[8])
          echo "<font color='blue'>页码:</font>".$count[8]."页";
        echo"<br><a href = $php_self>返回 </a>";
        //$repeat=0;
        exit;
//        break;
    }
}//while($count=mysql_fetch_array($r)){  
}//if(mysql_num_rows($r){


//if(!$repeat){

if($p_name!=""){
    $p_name=trim($p_name);
    $address=trim($address);
    $zipcode=trim($zipcode);
    $telephone=trim($telephone);
    $telefax=trim($telefax);
    $email=trim($email);
    $s_publisher="select publisher_id from publisher where publisher_name=\"$p_name\"";
       $results1 = @mysql_query($s_publisher);
       $count1=mysql_fetch_array($results1);
       if(mysql_num_rows($results1)<1){
          $q_publisher="insert into publisher (publisher_name, address, zipcode, telephone, telefax, email) values (\"$p_name\", \"$address\", \"$zipcode\", \"$telephone\", \"$telefax\", \"$email\")";
        $result2 = @mysql_query($q_publisher);
        if($result2){
                   $publisher_id= mysql_insert_id();
          }
    }
    else
        $publisher_id= $count1[0];
}

if($b_name==""){
    echo"书名不能为空。";
    exit;
}
else{
    $b_name=trim($b_name);
    $publisher_id=trim($publisher_id);
//    $date_pub=trim($date_pub);
    $type=trim($type);
    $pages=trim($pages);
//    $b_price=trim();
    $isbn=trim($isbn);
    $s_books="select books_id from books where books_name=\"$b_name\" ";
    $results3 = @mysql_query($s_books);
    $count3=mysql_fetch_array($results3);
    if(mysql_num_rows($results3)<1){
        $q_books="insert into books (books_name, publisher_id, date_pub, type, pages, price,isbn) values (\"$b_name\", \"$publisher_id\", \"$date_pub\", \"$type\", \"$pages\", \"$b_price\",\"$isbn\")";       
        $result3 = @mysql_query($q_books);
        if($result3){
            $books_id= mysql_insert_id();
        }
    }
    else
        $books_id=$count3[0];
}

if(($a_first1=="")||($a_last1=="")){
    echo"第一作者的姓名不能为空。";
    //exit;
}
else{
    $a_first1=trim($a_first1);
    $a_last1=trim($a_last1);
    $address=trim($address);
    $zipcode=trim($zipcode);
    $telephone=trim($telephone);
    $email=trim($email);
       $s_author="select author_id from author where first_name=\"$a_first1\" and last_name=\"$a_last1\"";
       $results = @mysql_query($s_author);
       $count2=mysql_fetch_array($results);
       if(mysql_num_rows($results)<1){
        $q_author="insert into author (first_name, last_name, address, zipcode, telephone, email) values (\"$a_first1\", \"$a_last1\", \"$address\",  \"$zipcode\", \"$telephone\", \"$email\")";
        $result1 = @mysql_query($q_author);
        if($result1){
                   $author_id= mysql_insert_id();
          }
    }
    else
        $author_id =$count2[0];

    if($books_id!=""||$author_id!=""){
           $s_ba="select id from books_author where books_id=\"$books_id\" and author_id=\"$author_id\"";
           $resulta = @mysql_query($s_ba);
           //$counta=mysql_fetch_array($resulta);
           if(mysql_num_rows($resulta)<1){
            $q_books_author="insert into books_author (books_id, author_id, author_type) values (\"$books_id\", \"$author_id\", \"$author_type\")";
            $author_id="";
            $resulta = @mysql_query($q_books_author);
        }
    }
}
if(($a_first2!="")||($a_last2!="")){
    $a_first2=trim($a_first2);
    $a_last2=trim($a_last2);
       $s_author2="select author_id from author where first_name=\"$a_first2\" and last_name=\"$a_last2\"";
       $results5 = @mysql_query($s_author2);
       $count5=mysql_fetch_array($results5);
       if(mysql_num_rows($results5)<1){
        $q_author2="insert into author (first_name, last_name, address, zipcode, telephone, email) values (\"$a_first2\", \"$a_last2\", \"$address\",  \"$zipcode\", \"$telephone\", \"$email\")";
        $result2 = @mysql_query($q_author2);
        if($result2){
                   $author_id= mysql_insert_id();
          }

    }
    else
        $author_id =$count5[0];
    if($books_id!=""||$author_id!=""){
           $s_ba="select id from books_author where books_id=\"$books_id\" and author_id=\"$author_id\"";
           $resulta = @mysql_query($s_ba);
           //$counta=mysql_fetch_array($resulta);
           if(mysql_num_rows($resulta)<1){
            $q_books_author="insert into books_author (books_id, author_id, author_type) values (\"$books_id\", \"$author_id\", \"$author_type\")";
            $author_id="";
            $resulta = @mysql_query($q_books_author);
        }
    }

}
if(($a_first3!="")||($a_last3!="")){
    $a_first3=trim($a_first3);
    $a_last3=trim($a_last3);
       $s_author3="select author_id from author where first_name=\"$a_first3\" and last_name=\"$a_last3\"";
       $results6 = @mysql_query($s_author3);
       $count6=mysql_fetch_array($results6);
       if(mysql_num_rows($results6)<1){
        $q_author3="insert into author (first_name, last_name, address, zipcode, telephone, email) values (\"$a_first2\", \"$a_last2\", \"$address\",  \"$zipcode\", \"$telephone\", \"$email\")";
        $result3 = @mysql_query($q_author3);
        if($result3){
                   $author_id= mysql_insert_id();
          }

    }
    else
        $author_id =$count6[0];
    if($books_id!=""||$author_id!=""){
           $s_ba="select id from books_author where books_id=\"$books_id\" and author_id=\"$author_id\"";
           $resulta = @mysql_query($s_ba);
           //$counta=mysql_fetch_array($resulta);
           if(mysql_num_rows($resulta)<1){
            $q_books_author="insert into books_author (books_id, author_id, author_type) values (\"$books_id\", \"$author_id\", \"$author_type\")";
            $author_id="";
            $resulta = @mysql_query($q_books_author);
        }
    }

}

echo"<br><a href = $php_self>返回 </a>";
echo"</body></html>";

?>
<?
endif;
?>