2012-05-07 16 views
-4

同じユーザー名を持つユーザーを登録しないPHPスクリプトが必要です。私はスクリプトを書く、それは正常に動作しますが、同じUSERNAMEを持つユーザーを登録します。スクリプトのユーザー名を確認し、利用可能な場合は登録を継続し、使用できない場合は登録を停止します。申し訳ありませんが、私の英語は病気です:d:D PLZこのスクリプトを書いてください。同じユーザー名を持つユーザーを登録しないPHPスクリプトが必要

これは私のスクリプトで、plzはこの

my script

にスクリプトを編集する方法を教えて:いくつかの時点で

<!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>Untitled Document</title> 
</head> 


<body> 


<?php require_once('Connections/tourname_regcs16.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 


    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 


    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 


$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { 
    $insertSQL = sprintf("INSERT INTO members (team_name, team_member1, team_member2, team_member3, team_member4, team_member5, email, phone_number, emoney, password,win ,defeat ,score , tour_status_complete, tour_status_progress, tour_status_willstart, team_status_payed, team_status_notpayed, team_place_1, team_place_2, team_place_3, team_place_4, team_place_5, team_place_6, team_place_7, team_place_8, team_place_9, team_place_10, team_place_11, team_place_12, team_place_13, team_place_14, team_place_15, team_place_16, team_place_17, team_place_18, team_place_19, team_place_20, team_place_final, `data`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
         GetSQLValueString($_POST['team_name'], "text"), 
         GetSQLValueString($_POST['team_member1'], "text"), 
         GetSQLValueString($_POST['team_member2'], "text"), 
         GetSQLValueString($_POST['team_member3'], "text"), 
         GetSQLValueString($_POST['team_member4'], "text"), 
         GetSQLValueString($_POST['team_member5'], "text"), 
         GetSQLValueString($_POST['email'], "text"), 
         GetSQLValueString($_POST['phone_number'], "text"), 
         GetSQLValueString($_POST['emoney'], "text"), 
         GetSQLValueString($_POST['password'], "text"), 
         GetSQLValueString($_POST['win'], "text"), 
         GetSQLValueString($_POST['defeat'], "text"), 
         GetSQLValueString($_POST['score'], "text"), 
         GetSQLValueString($_POST['tour_status_complete'], "text"), 
         GetSQLValueString($_POST['tour_status_progress'], "text"), 
         GetSQLValueString($_POST['tour_status_willstart'], "text"), 
         GetSQLValueString($_POST['team_status_payed'], "text"), 
         GetSQLValueString($_POST['team_status_notpayed'], "text"), 
         GetSQLValueString($_POST['team_place_1'], "text"), 
         GetSQLValueString($_POST['team_place_2'], "text"), 
         GetSQLValueString($_POST['team_place_3'], "text"), 
         GetSQLValueString($_POST['team_place_4'], "text"), 
         GetSQLValueString($_POST['team_place_5'], "text"), 
         GetSQLValueString($_POST['team_place_6'], "text"), 
         GetSQLValueString($_POST['team_place_7'], "text"), 
         GetSQLValueString($_POST['team_place_8'], "text"), 
         GetSQLValueString($_POST['team_place_9'], "text"), 
         GetSQLValueString($_POST['team_place_10'], "text"), 
         GetSQLValueString($_POST['team_place_11'], "text"), 
         GetSQLValueString($_POST['team_place_12'], "text"), 
         GetSQLValueString($_POST['team_place_13'], "text"), 
         GetSQLValueString($_POST['team_place_14'], "text"), 
         GetSQLValueString($_POST['team_place_15'], "text"), 
         GetSQLValueString($_POST['team_place_16'], "text"), 
         GetSQLValueString($_POST['team_place_17'], "text"), 
         GetSQLValueString($_POST['team_place_18'], "text"), 
         GetSQLValueString($_POST['team_place_19'], "text"), 
         GetSQLValueString($_POST['team_place_20'], "text"), 
         GetSQLValueString($_POST['team_place_final'], "text"), 
         GetSQLValueString($_POST['data'], "date")); 


    mysql_select_db($database_tourname_regcs16, $tourname_regcs16); 
    $Result1 = mysql_query($insertSQL, $tourname_regcs16) or die(mysql_error()); 


    $insertGoTo = "cs16_reg_complete.php"; 
    if (isset($_SERVER['QUERY_STRING'])) { 
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
    $insertGoTo .= $_SERVER['QUERY_STRING']; 
    } 
    header(sprintf("Location: %s", $insertGoTo)); 
} 








?> 
<style type="text/css"> 
#form1 table tr td p { 
    text-align: center; 
} 
</style> 




<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> 
    <table width="493" align="center"> 
    <tr valign="baseline"> 
     <td width="120" align="right" nowrap="nowrap">გუნდის სახელი:</td> 
     <td width="250"><p><input type="text" name="team_name" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">გუნდის წევრი №1:</td> 
     <td><p><input type="text" name="team_member1" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">გუნდის წევრი №2:</td> 
     <td><p><input type="text" name="team_member2" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">გუნდის წევრი №3:</td> 
     <td><p><input type="text" name="team_member3" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">გუნდის წევრი №4:</td> 
     <td><p><input type="text" name="team_member4" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">გუნდის წევრი №5:</td> 
     <td><p><input type="text" name="team_member5" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">Emoney:</td> 
     <td><p><input type="text" name="emoney" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">ელ. ფოსტა:</td> 
     <td><p><input type="text" name="email" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">მობ. ნომერი:</td> 
     <td><p><input type="text" name="phone_number" value="" size="32" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">პაროლი:</td> 
     <td><p><input type="password" name="password" value="" size="32" /></p></td> 

    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">&nbsp;</td> 
     <td><p><br><input type="submit" value="რეგისტრაცია" /></p></td> 
     <td>&nbsp;</td> 
    </tr> 
    </table> 
    <input type="hidden" name="win" value="0" /> 
    <input type="hidden" name="defeat" value="0" /> 
    <input type="hidden" name="score" value="0" /> 
    <input type="hidden" name="tour_status_complete" value="Complete" /> 
    <input type="hidden" name="tour_status_progress" value="In Progress" /> 
    <input type="hidden" name="tour_status_willstart" value="Is Starting" /> 
    <input type="hidden" name="team_status_payed" value="Payed" /> 
    <input type="hidden" name="team_status_notpayed" value="Not Payed" /> 
    <input type="hidden" name="team_place_1" value="Round I" /> 
    <input type="hidden" name="team_place_2" value="Round II" /> 
    <input type="hidden" name="team_place_3" value="Round III" /> 
    <input type="hidden" name="team_place_4" value="Round IV" /> 
    <input type="hidden" name="team_place_5" value="Round V" /> 
    <input type="hidden" name="team_place_6" value="Round VI" /> 
    <input type="hidden" name="team_place_7" value="Round VII" /> 
    <input type="hidden" name="team_place_8" value="Round VIII" /> 
    <input type="hidden" name="team_place_9" value="Round IX" /> 
    <input type="hidden" name="team_place_10" value="Round X" /> 
    <input type="hidden" name="team_place_11" value="Round XI" /> 
    <input type="hidden" name="team_place_12" value="Round XII" /> 
    <input type="hidden" name="team_place_13" value="Round XIII" /> 
    <input type="hidden" name="team_place_14" value="Round XIV" /> 
    <input type="hidden" name="team_place_15" value="Round XV" /> 
    <input type="hidden" name="team_place_16" value="Round XVI" /> 
    <input type="hidden" name="team_place_17" value="Round XVII" /> 
    <input type="hidden" name="team_place_18" value="Round XVIII" /> 
    <input type="hidden" name="team_place_19" value="Round XIX" /> 
    <input type="hidden" name="team_place_20" value="Round XX" /> 
    <input type="hidden" name="team_place_final" value="Final" /> 
    <input type="hidden" name="data" value="<?php 
echo "Server time: ".date("M d, Y - g:i:s A"); 
?>" /> 
    <input type="hidden" name="MM_insert" value="form1" /> 
</form> 
</body> 
</html> 
+3

はあなたの仕事 –

+0

のいくつかを示してください[あなたが試してみましたか?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Songo

+2

まあ、行きます書いてください。 –

答えて

0

を、ユーザー名の文字列で(つまり、jQueryの経由)AJAXリクエストを送りますいくつかの単純なPHPスクリプトには、ユーザー名を取得し、SQLクエリを実行して、ユーザー名が既にDBにあるかどうかを確認し、結果を返します。

+0

コードはありませんか?これはユーザーが尋ねたものです。 –

2

質問を自分で試みたことがないので、チュートリアルを探しているようです。 MySQLを使用すると仮定すると、here's a neat tutorial

将来的には、これはあなたのために仕事をするコミュニティではないので、あなたの仕事の一部を示すことをお勧めします。私たちはあなたを助けるためにここにいます。

1

火災; PHPのmysqlクエリのユーザー名 ex。 select * from users where username='$username'。行が返された場合、ユーザー名はすでに割り当てられています。そうでなければ、そのユーザーを登録できます。

1

あなたがデータベースに見て、入力されたユーザー名を見つけようと、ユーザープレス登録ボタン、登録段階で、単に必要があります。レコードが見つかった場合

SELECT * FROM users WHERE username = ? 

、単にこれで登録エラー」のユーザーを表示しますデータベースユーザーテーブルに新しいレコードを作成する:

INSERT INTO users SET username = ?, ... 
1

PHPでフォーム送信アクションで確認できます。たとえば、..

if(isset($_POST) && (!empty($_POST)){ 
    $username = $_POST['username']; 
    $username_exist_query = "SELECT * from usertable where username = '".$usernae."' WHERE conditions"; 
    $username_result = mysql_query($username_exist_query) or die(mysql_error()); 
    if($username_result){ 
     if(mysql_num_rows($username_result) == 0){ 
      //Do Registration operation 
    }else{ 
     echo "Username already exist!"; 
    } 
    } 

} 

このコード例は役に立ちます。

おかげ

関連する問題