2013-02-01 44 views
0

我想通過一個簡單的表單更新用戶級別,但它顯示我未定義的索引,而不是更新級別會有人幫我做到這一點?更新用戶級別

<h3>Update User Level</h3> 
<form action="" method="POST"> 
UserID:<br/> 
<input type="text" name="upduser" maxlength="30"> <br/> 
Designation code:<br> 
<?php 
//require 'config.php'; 
$options = ''; 
$filter=mysql_query("select`user_dsgntn_code` from `hr_user`"); 
while($row = mysql_fetch_array($filter)) { 
    $options .="<option>" . $row['user_dsgntn_code'] . "</option>"; 
} 
      $dropdown="<form id='designation' name='designation' method='POST' action=''> 
       <select name='updlevel' onchange='showUser(this.value)'> 
        " . $options . " 
       </select> 
      </form>"; 
     echo $dropdown; 
     //do_alert("$options"); 
     ?> 
<br> 
<input type="submit" value="Update Level"> 
</form> 
<? 
//require 'config.php'; 

if (isset($_POST['upduser']) && ! empty ($_POST['upduser'])&& 
isset ($_POST['updlevel'])); 
{ 
$updtuser=$_POST['upduser']; 
$updtlevel=$_POST['updlevel']; 
$sql_upd="update `hr_user` set user_dsgntn_code='$updtlevel' WHERE user_id='$updtuser'"; 
$result = mysql_query($sql_upd) or die(mysql_error()); 
} 
+1

[**請不要在新代碼**中使用'mysql_ *'函數](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO, [這裏是一個很好的教程](http://www.brightmeup.info/article.php?a_id=2)。 –

+0

你有兩種形式,當你點擊提交按鈕時,只有其中一個被提交。將它們組合成一種形式。 – Barmar

+0

@Barmar我可以如何組合他們? – user2031407

回答

0

刪除<select>附近的多餘表格。

<h3>Update User Level</h3> 
<form action="" method="POST"> 
UserID:<br/> 
<input type="text" name="upduser" maxlength="30"> <br/> 
Designation code:<br> 
<?php 
//require 'config.php'; 
$options = ''; 
$filter=mysql_query("select`user_dsgntn_code` from `hr_user`"); 
while($row = mysql_fetch_array($filter)) { 
    $options .="<option>" . $row['user_dsgntn_code'] . "</option>"; 
} 
      $dropdown="<select id='designation' name='updlevel' onchange='showUser(this.value)'> 
        " . $options . " 
       </select>"; 
     echo $dropdown; 
     //do_alert("$options"); 
     ?> 
<br> 
<input type="submit" value="Update Level"> 
</form> 
+0

未定義的索引:upduser 未定義的索引:updlevel – user2031407

+0

在if(isset()...);'語句結尾處有一個額外的';'。 – Barmar

+0

你救了我非常感謝:) – user2031407