如何是你的一切,如何避免重複的用戶在我的數據庫和PHP
希望每一個在這裏是OK,
現在我有一個表格,該管理員可以創建用戶,他可以刪除用戶如讓我顯示的代碼首先
這是我的代碼
> > <?php error_reporting(E_ALL);
>
> session_start();
> if(!isset($_SESSION['login']) ||
> $_SESSION['login']!='1') {
> header("Location:loginpage.php");
> } ?>
>
> <!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=utf-8" />
> <title>My Control panel</title> <link
> href="../css_style.css"
> rel="stylesheet" type="text/css" />
> </head>
>
>
>
> <body> <div id="werpper"> <div
> id="content">
>
> <div id="header">My control -
> Panel</div> <div id="body_cntent">
> <div id="left_side"> <p>Home and
> instructions</p> <p><a
> href="../control_panel.php">main
> directory</a></p> <p><a
> href="add_event.php">Add new
> event</a></p> <p><a
> href="../editoccasion.php">Control
> Occasion's</a></p> <p><a
> href="add_photos_and_occasion.php">Add
> Photos_occasion</a></p> <p><a
> href="../signout.php">Sign out</a></p>
> </div> <div id="right_side">
>
> <h2>Add new user</h2>
>
> <form action="" method="post">
>
> <table width="600" border="0"
> cellpadding="5" cellspacing="0">
> <tr>
> <td width="78">User name</td>
> <td width="2"> </td>
> <td width="149"><input type="text" name="uname" value="" /></td>
> <td width="332" rowspan="5" align="left" valign="top"><p
> class="red">For Administration use
> only.</p>
> <p>You can add or delete users from <a
> href="edit_users.php">here</a><br />
> You can't edit any user if you like to change any user account you
> can delete the user and create it
> again with the new
> information.</p></td> </tr> <tr>
> <td>Password</td>
> <td> </td>
> <td><input type="text" name="pass" value="" /></td>
> </tr> <tr>
> <td> </td>
> <td> </td>
> <td><input type="submit" name="submit" value="Add user" /></td>
> </tr> <tr>
> <td> </td>
> <td> </td>
> <td> </td>
> </tr> <tr>
> <td> </td>
> <td> </td>
> <td align="right"> </td>
> </tr> </table> </form>
>
> </div> </div>
>
> <div id="footer"></div> </div> </div>
>
> <?php
> if (isset($_POST['submit'])) {
> include_once "../config/config.php";
> $uname = $_POST['uname']; $pass =$_POST['pass'];
> $check = "select * from users where id = {$uname}"; $result_check
> = $db->query($check)or die($db->error);
>
> while ($row = $result_check -> fetch_object()) {
> if(num_rows == 1){
>
> echo "error";
>
> }else{
> $add_user = "insert into users (id, uname, pass) values ('',
> '$uname', '$pass')";
> $result = $db -> query($add_user) or die ("$db->error");
> if ($result) {
> echo "user added successfuly";
> }else{
>
> echo "There was an error please try again later";
>
> } } } } ?>
>
> </body> </html>
所有我需要在這裏知道的是如何解決這個代碼的問題
$check = "select * from users where id = {$uname}";
$result_check = $db->query($check)or die($db->error);
while ($row = $result_check -> fetch_object()) {
if(num_rows == 1){
echo "error";
}
我怎樣才能避免重複的用戶在我的分貝
我會檢討當我回家時,這又一次,但任何幫助將是值得稱道的 – 2010-12-20 14:23:10