簡體   English   中英

從選擇選項字段中獲取ID並在所選用戶中對其進行更新

[英]Grab id from a select option field and update it in the selected user

嗨,我在創建程序時遇到一些問題,我有一個選擇字段,該字段顯示表用戶中的所有用戶,我希望當我選擇一個用戶並按鏈接時,我希望它可以將用戶userid更新為puserid。表屬性

php代碼:

//connect with the database
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("ocm2inf_ocm",$con);
$get=mysql_query("SELECT * FROM users WHERE PortalId = '14'");
$option = '';

//create rows of the users
while($row = mysql_fetch_assoc($get))
{
  $option .= '<option value = "'.$row['UserId'].'">'.$row['firstName']. str_repeat('&nbsp;', 1). $row['UserId'].'</option>';
}

//update the row in the database after pressing the button
if(isset($_POST['linkownersandproperties']))
{
  $UserId = $_POST['UserIdOwner'];

  $sql = "UPDATE properties SET puserId='$UserId' WHERE propertyId=$id";
}

html代碼:

<form class="create section" action="" method="post">
  <select class="form-control" name="UserIdOwner">
    <?php echo $option; ?>
  </select>
  <br />
  <button style="width:110px; margin-left:10px;" type="submit" name="linkownersandproperties" value="Submit" class="btn btn-primary btn-lg submit-button1" required="required">Link</button>
  </form>

提前致謝 :)

更改此規則
$sql = "UPDATE properties SET puserId='$UserId' WHERE propertyId=$id";

遵守這條規則

$sql = mysql_query("UPDATE properties SET puserId='$UserId' WHERE propertyId='$id'");

將其放在if語句的$sql

$query = mysql_query($sql, $db);
if (!$sql) {
    echo "Failed";
} else {
    echo "Executed";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM