Library management procedure (2) entry of the Library Directory:
If (! $ UploadAction ):
?>
// This program is used to enter the title, author, and publisher information.
// Editor: Kong Xiuxiang. Date: 2001/3/24
/*
Session_start ();
If (! Isset ($ auth_passed )){
Echo "this function can only be used by authorized users. ";
Return-1;
}
If (isset ($ u_name )){
Session_name ($ u_name );
// Echo" ". Session_name ().": This program will serve you wholeheartedly. \ N ";
// Echo "";
}
*/
?>
Library Directory input
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; // is the repeat repeated.
$ TimeLimit = 0; // Set the time-out period. The default time is 30 seconds. if it is set to 0, the time-out period is not limited.
Set_time_limit ($ TimeLimit );
@ MYSQL_CONNECT ($ hostname, $ dbusername, $ dbpassword) or die ("cannot connect to the database! ");
@ Mysql_select_db ("$ dbname") or die ("You cannot select a database! ");
// $ 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 = "the title of the book is required. If ISBN is empty, the author's surname and name are required by the publishing house.
Check whether the requirements are met. ";
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 "name". $ count [1]."
";
If (! $ R ){
Echo "invalid query
";
Exit;
}
If (mysql_num_rows ($ r )){
If (trim ($ isbn )! = ""){
Echo "duplicate data.
";
Exit;
}
Else
While ($ count = mysql_fetch_array ($ r )){
/*
Echo "while.
";
Echo trim ($ a_first1 );
Echo trim ($ count [2]);
Echo trim ($ a_first1) = trim ($ count [2]);
Echo"
";
Echo trim ($ a_last1) = trim ($ count [3]);
Echo"
";
Echo trim ($ p_name) = trim ($ count [4]);
Echo"
";
*/
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 "this book is already in the database.
";
Echo "name:". $ books_name;
Echo"
Author: ". $ first_name. $ last_name;
Echo"
National Standard No.: ". $ count [5];
Echo"
Book Price: ". $ count [6]." yuan ";
Echo"
Publication date: ". substr ($ count [7],)." year ". substr ($ count [7], 5, 2)." month ";
If ($ count [8])
Echo "page:". $ count [8]. "page ";
Echo"
Return ";
// $ 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 "the title cannot be blank. ";
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 "the name of the first author cannot be blank. ";
// 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"
Return ";
Echo"";
?>
Endif;
?>