繁体   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