www.gusucode.com > 仿51.com的php源码 1.1 > Interface/MusicFavoriteInterface.php
<?php include("../User/CheckLogined.php"); include("../include/dbclass.php"); $dbc=new DbConn(); $uid=$_COOKIE["uid"]; $id=$_GET["id"]; $group=$_GET["group"]; if ($_POST["action"]=="addGroup") { $id=$_POST["id"]; $newGroup=$_POST["newGroup"]; //先查看是不有了 $sqlck="select id from MusicGroup where GroupName='$newGroup' and User_Account='$uid'"; $ck=$dbc->getRs($sqlck); if ($ck !=null) { echo "<script>alert('分类名已存在!');history.back();</script>"; exit(); } $sql="insert into MusicGroup (User_Account,GroupName) values ('$uid','$newGroup')"; $dbc->Execute($sql); header("Location:MusicFavoriteInterface.php?user=$uid&id=$id&group=$newGroup"); } if($_POST["addToFav"]=="确定") { $id=$_POST["id"]; $group=$_POST["group"]; $sql="select id from musicuser where Music_id='$id' and User_Name='$uid'"; $query_id=$dbc->query($sql); $num=$dbc->num_rows($query_id); if ((int)$num>0) { echo "<script>alert('你已经收藏了');window.close();</script>"; exit(); } else { $sqladd="insert into musicuser (Music_id,Music_Group,BornFrom,User_Name) values('$id','$group','0','$uid')"; $dbc->Execute($sqladd); echo "<script>alert('收藏成功!');window.close();</script>"; exit(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>音乐收藏</title> <style type="text/css"> <!-- td{font-size:12px} body { background-color: #EBEBEB; } --> </style> </head> <body> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" style="padding-top:10px"> <tr> <td><fieldset style="border:2px groove #ffffff"> <legend align="left"style="color:#000000;font-weight:bold">收藏到哪个分类?</legend> <table style="width:70%" align="center" valign="middle"> <form name="form1" method="post" action=""> <tr> <td style="padding-top:15px">分类:</td> <td style="padding-top:15px"> <select id="group" name="group" onchange="javascript: Confirm(this);"> <?php $sql1="select * from MusicGroup where User_Account='$uid' order by GroupOrder desc"; $result=$dbc->query($sql1); while ($row=@mysql_fetch_array($result)) { ?> <option value='<?php echo $row["GroupName"]; ?>'><?php echo $row["GroupName"]; ?></option><?php }?><option style="color:#AAA" disabled="disabled">-----</option> <option style="color:blue" value="addGroup">添加新分类>></option> </select> </td> </tr> <tr> <td style="height:15px" colspan="2"></td> </tr> <tr> <td colspan="2" align="center" style="padding-bottom:15px"> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="hidden" id="newGroup" name="newGroup" value="" /> <input type="hidden" id="action" name="action" value="" /> <input type="submit" name="addToFav" value="确定" style="width:70px;background:#d4d0c8;border:2px outset #ffffff" /> <input type="button" value="取消" style="width:70px;background:#d4d0c8;border:2px outset #ffffff" onclick="javascript: window.close();" /> </td> </tr> </form> </table> </fieldset></td> </tr> </table> </body> </html> <script language="javascript"> window.onload = function() { var newGroup = "<?php echo $group; ?>"; var group = document.getElementById("group"); if (group && newGroup != "") { var len = group.length; for (i = 0; i < len; i++) { if (group.options[i].value == newGroup) { group.options[i].selected = true; } } } } function Confirm(obj) { if (obj.options[obj.selectedIndex].disabled) { obj.options[0].selected = true; } else { if (obj.value == "addGroup") { var newGroupName = prompt("请输入一个新的分类名称(小于20个字母或10个汉字):", ""); if (newGroupName == null) { obj.options[0].selected = true; return; } else { if (newGroupName.length > 20) { alert("对不起,分类名称过长!"); obj.options[0].selected = true; return; } else { document.getElementById("newGroup").value = newGroupName; document.getElementById("action").value = "addGroup"; document.getElementById("form1").submit(); } } } } } </script>