DDR爱好者之家 Design By 杰米
接着上篇继续学习: 《php实现购物车的功能(上)》
7、实现一个管理界面
登录界面
由以下代码实现:
7.1 admin.php
<"Problem:"); echo "<p>You could not be logged in.<br /> You must be logged in to view this page.</p>"; do_html_URL('login.php','Login'); do_html_footer(); exit; } } do_html_header("Administration"); if(check_admin_user()) { display_admin_menu(); } else { echo "<p>You are not authorized to enter the administration area.</p>"; do_html_URL('login.php','Login'); } do_html_footer(); "htmlcode">function login($username,$password) //登录 { $conn = db_connect(); //连接数据库 if(!$conn) return 0; //检查用户名唯一性 $query = "select * from admin where username='". $username ."' and password = sha1('". $password ."')"; $result = $conn ->query($query); if(!$result) return 0; if($result ->num_rows > 0) return 1; else return 0; }7.3 user_auth_fns.php文件中的函数check_admin_user()
function check_admin_user() //检查是否是管理员 { if(isset($_SESSION['admin_user'])) return true; else return false; }管理主界面
由以下代码实现:
7.4 output_fns.php文件中的函数display_admin_menu()
function display_admin_menu() //输出管理员菜单 { "index.php">Go to main site</a><br /> <a href="insert_category_form.php">Add a new category</a><br /> <a href="insert_book_form.php">Add a new book</a><br /> <a href="change_password_form.php">Change admin password</a><br /> <"<div align= \" center \"><a href=\"". $target ."\"> <img src=\"images/". $image .".gif\" alt=\"". $alt ."\" border = \" 0 \" height = \" 50 \" width = \" 135 \" /></a></div>"; }由以下代码实现:
7.5 insert_category_form.php<"admin.php","Back to administrtion menu"); } else { echo "<p>You are not authorized to enter the administation area.</p>"; } do_html_footer(); "text-align: left">7.6 insert_category.php
<"Adding a category"); if(check_admin_user()) { if(filled_out($_POST)) { $catname =$_POST['catname']; if(insert_category($catname)) { echo "<p>Category \"". $catname ."\" was added to the database.</p>"; } else { echo "<p>Category \"". $catname ."\" could not be added to the database.</p>"; } } else { echo "<p>You have not filled out the form. Please try again.</p>"; } do_html_URL("admin.php","Back to administration menu"); } else { echo "<p>You are not authorised to view this page.</p>"; } do_html_footer(); "text-align: center">管理员目录界面
目录编辑界面-可更新,删除
目录更新成功
目录主界面可以看到该目录更改成功
由以下代码实现:
7.7 edit_category_form.php<"Edit category"); if(check_admin_user()) { if($catname = get_category_name($_GET['catid'])) { $catid = $_GET['catid']; $cat = compact('catname','catid'); display_category_form($cat); } else { echo "<p>Could not retrieve category details.</p>"; } do_html_URL("admin.php","Back to administration menu"); } else { echo "<p>You are not authorized to enter the administration area.</p>"; } do_html_footer(); "htmlcode"><"Updating category"); if(check_admin_user()) { if(filled_out($_POST)) { if(update_category($_POST['catid'],$_POST['catname'])) { echo "<p>Category was updated.</p>"; } else { echo "<p>Category could not be updated.</p>"; } } else { echo "<p>you have not filled out the form. Please try again.</p>"; } do_html_URL("admin.php","Back to administration menu"); } else { echo "<p>You are not authorised to view this page.</p>"; } do_html_footer(); "htmlcode"><"post" action="<"> <table border="0"> <tr> <td>Category Name:</td> <td><input type="text" name="catname" size="40" maxlength="40" value="<"/></td> </tr> <tr> <td <"colspan=2";} "center"> <"<input type=\"hidden\" name=\"catid\" value=\"". $category['catid'] ."\" />"; } "submit" value="<"/></form> </td> <"<td> <form method=\"post\" action=\"delete_category.php\"> <input type=\"hidden\" name=\"catid\" value=\"". $category['catid'] ."\" /> <input type=\"submit\" value=\"Delete category\" /> </form></td>"; } "post" action="<"> <table border="0"> <tr> <td>ISBN:</td> <td><input type="text" name="isbn" value="<" /></td> </tr> <tr> <td>Book Title:</td> <td><input type="text" name="title" value="<" /></td> </tr> <tr> <td>Book Author:</td> <td><input type="text" name="author" value="<"/></td> </tr> <tr> <td>Category:</td> <td> <select name="catid"> <"<option value=\"". $thiscat['catid'] ."\""; if(($edit) && ($thiscat['catid'] == $book['catid'])) { echo " selected"; } echo ">". $thiscat['catname'] ."</option>"; } "text" name="price" value="<" /></td> </tr> <tr> <td>Description:</td> <td><textarea rows="3" cols="50" name="description"><"colspan=2"; }"center"> <"<input type=\"hidden\" name=\"oldisbn\" value=\"".$book['isbn']."\" />";"submit" value="<" /></form></td> <"<td> <form method=\"post\" action=\"delete_book.php\"> <input type=\"hidden\" name=\"isbn\" value=\"".$book['isbn']."\" /> <input type=\"submit\" value=\"Delete book\"/> </form></td>"; } "change_password.php" method="post"> <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc"> <tr> <td>Old password:</td> <td><input type="password" name="old_passwd" size="16" maxlength="16"/></td> </tr> <tr> <td>New password:</td> <td><input type="password" name="new_passwd" size="16" maxlength="16"/></td> </tr> <tr> <td>Repeat new password:</td> <td><input type="password" name="new_passwd2" size="16" maxlength="16"/></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Change password"/></td> </tr> </table> </form> <br /> <"select * from categories where catname='". $catname ."'"; $result = $conn ->query($query); if((!$result) || ($result ->num_rows != 0)) return false; $query = "insert into categories values ('','". $catname ."')"; $result = $conn ->query($query); if(!$result) return false; else return true; } function insert_book($isbn,$title,$author,$catid,$price,$description) //图书插入 { $conn = db_connect(); //连接数据库 $query = "select * from books where isbn='". $isbn ."'"; $result = $conn ->query($query); if((!$result) || ($result ->num_rows != 0)) return false; $query = "insert into books values ('". $isbn ."','". $author ."','". $title ."', '". $catid ."','". $price ."','". $description ."')"; $result = $conn ->query($query); if(!$result) return false; else return true; } function update_category($catid,$catname) //更改目录名称 { $conn = db_connect(); //连接数据库 $query = "update categories set catname='". $catname ."' where catid='". $catid ."'"; $result = @$conn ->query($query); if(!$result) return false; else return true; } function update_book($oldisbn,$isbn,$title,$author,$catid,$price,$description) { $conn = db_connect(); //连接数据库 $query = "update books set isbn='". $isbn ."', title='". $title ."', author='". $author ."', catid='". $catid ."', price ='". $price ."', description='". $description ."' where isbn='". $oldisbn ."'"; $result = @$conn ->query($query); if(!$result) return false; else return true; } function delete_category($catid) //删除目录 { $conn = db_connect(); //连接数据库 $query = "select * from books where catid='". $catid ."'"; $result = @$conn ->query($query); if((!$result) || (@$result ->num_rows > 0)) //如果该目录有图书,无法删除该目录 return false; $query = "delete from categories where catid='". $catid ."'"; $result = @$conn ->query($query); if(!$result) return false; else return true; } function delete_book($isbn) //删除图书 { $conn = db_connect(); //连接数据库 $query = "delete from books where isbn='". $isbn ."'"; $result = @$conn ->query($query); if(!$result) return false; else return true; } "color: #333333">在真正的在线商店,可能必须建立一些订单记录和实施系统——在这个系统中,用户无法看到已经预定了的订单。顾客希望在不必与我们联系的前提下就能检查到他们的订单处理情况。用户应当可以通过一种身份验证方式使之能够查看自己以前的订单,并且也可以将操作与个人情况紧密地结合起来。也更方便我们收集一些用户习惯信息。 图书的图片可以通过FTP之类的服务传输到该网站的图像目录并给它们取一个合适的名字。可以把文件上载到图片插入页,以使该操作方便一些。 可以添加用户登录、个性化设置以及书目推荐、在线评论、会员制度、库存级别检查等。可以添加的功能是非常多的。 以上就是php实现购物车功能的全部代码,希望对大家的学习有所帮助。
源码下载:购物车
DDR爱好者之家 Design By 杰米广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!DDR爱好者之家 Design By 杰米暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]