0
我有一個用戶表,列中有:用戶名,用戶名,密碼,電子郵件,agree_1,comment_1,agree_2,comment_2,...........更新基於用戶ID的行
i用它來更新表:
UPDATE users SET Agree_1=%s, comment_1=%s, Agree_2=%s, comment_2=%s, Agree_3=%s, comment_3=%s, Agree_4=%s, comment_4=%s, Agree_5=%s, comment_5=%s, Agree_6=%s, comment_6=%s, Agree_7=%s, comment_7=%s, Agree_8=%s, comment_8=%s, Agree_9=%s, comment_9=%s, Agree_10=%s, comment_10=%s, Agree_11=%s, comment_11=%s, Agree_12=%s, comment_12=%s, Agree_13=%s, comment_13=%s, Agree_14=%s, comment_14=%s, Agree_15=%s, comment_15=%s, Agree_16=%s, comment_16=%s, Agree_17=%s, comment_17=%s, WHERE id=%s",
GetSQLValueString($_POST['grp_1'], "text"),
GetSQLValueString($_POST['text_1'], "text"),
GetSQLValueString($_POST['grp_2'], "text"),
GetSQLValueString($_POST['text_2'], "text"),
GetSQLValueString($_POST['grp_3'], "text"),
GetSQLValueString($_POST['text_3'], "text"),
GetSQLValueString($_POST['grp_4'], "text"),
GetSQLValueString($_POST['text_4'], "text"),
GetSQLValueString($_POST['grp_five'], "text"),
GetSQLValueString($_POST['text_five'], "text"),
GetSQLValueString($_POST['grp_six'], "text"),
GetSQLValueString($_POST['text_six'], "text"),
GetSQLValueString($_POST['grp_seven'], "text"),
GetSQLValueString($_POST['text_seven'], "text"),
GetSQLValueString($_POST['grp_eight'], "text"),
GetSQLValueString($_POST['text_eight'], "text"),
GetSQLValueString($_POST['grp_nine'], "text"),
GetSQLValueString($_POST['text_nine'], "text"),
GetSQLValueString($_POST['grp_ten'], "text"),
GetSQLValueString($_POST['text_ten'], "text"),
GetSQLValueString($_POST['grp_eleven'], "text"),
GetSQLValueString($_POST['text_eleven'], "text"),
GetSQLValueString($_POST['grp_twelve'], "text"),
GetSQLValueString($_POST['text_twelve'], "text"),
GetSQLValueString($_POST['grp_thirteen'], "text"),
GetSQLValueString($_POST['text_thirteen'], "text"),
GetSQLValueString($_POST['grp_fourteen'], "text"),
GetSQLValueString($_POST['text_fourteen'], "text"),
GetSQLValueString($_POST['grp_fifteen'], "text"),
GetSQLValueString($_POST['text_fifteen'], "text"),
GetSQLValueString($_POST['grp_sixteen'], "text"),
GetSQLValueString($_POST['text_sixteen'], "text"),
GetSQLValueString($_POST['grp_seventeen'], "text"),
GetSQLValueString($_POST['text_seventeen'], "text"),
GetSQLValueString($_POST['id'], "int"));
我的形式所具有的隱藏字段我把它叫做ID,當我用上面的查詢,更新,它是成功的,但是當我創造了另一個用戶提供的2號,登錄與他的信息,使用上述查詢來更新用戶,它繼續更新ID爲1的用戶,請如何更新我創建的任何用戶。請幫忙。下面是查詢集我曾經從數據庫中選擇:
$query_draft1b_query = sprintf("SELECT id, Agree_1, comment_1, Agree_2, comment_2, Agree_3, comment_3, Agree_4, comment_4, Agree_5, comment_5, Agree_6, comment_6, Agree_7, comment_7, Agree_8, comment_8, Agree_9, comment_9, Agree_10, comment_10, Agree_11, comment_11, Agree_12, comment_12, Agree_13, comment_13, Agree_14, comment_14, Agree_15, comment_15, Agree_16, comment_16, Agree_17, comment_17, Agree_18, comment_18, Agree_19, comment_19, Agree_20, comment_20, Agree_21, comment_21, Agree_22, comment_22, Agree_23, comment_23, Agree_24, comment_24, Agree_25, comment_25, Agree_26, comment_26, Agree_27, comment_27, Agree_28, comment_28, Agree_29, comment_29, Agree_30a, comment_30a, Agree_31a, comment_31a, Agree_30b, comment_30b, Agree_31b, comment_31b, Agree_32, comment_32, Agree_33, comment_33, Agree_34, comment_34, Agree_35, comment_35, Agree_36, comment_36, Agree_37, comment_37, Agree_38, comment_38, Agree_39, comment_39, Agree_40, comment_40, Agree_41, comment_41, Agree_42, comment_42, Agree_43, comment_43, Agree_44, comment_44, Agree_45, comment_45, Agree_46, comment_46, Agree_47, comment_47, Agree_48, comment_48, Agree_49a, comment_49a, agree_49b, comment_49b, Agree_50, comment_50 FROM users WHERE id = %s", GetSQLValueString($colname_draft1b_query, "int"));$draft1b_query = mysql_query($query_draft1b_query, $NAWFIA_1) or die(mysql_error());$row_draft1b_query = mysql_fetch_assoc($draft1b_query);$totalRows_draft1b_query = mysql_num_rows($draft1b_query);
好,那麼你認爲我應該做一個主鍵?我該如何去做呢? –
請創建2個兩個表:1 /用戶(id,用戶名)和2 /評論(id,id_users,同意,評論)。 id是主鍵,可以將它設置爲int自動增量。 – hoangvu68
我正在使用dream weaver,上面的代碼工作正常,但是當我使用2或3的id登錄並且向數據庫註釋或插入記錄時,它仍然會更新1的用戶標識之一。請幫助我 –