![](/img/trans.png)
[英]I'm having a problem with the blog post edit button of the Admin panel I made with React.js
[英]I want to enable or disable a “blog post” by dropdown from admin panel
我想通過單擊下拉值來啟用或禁用發布。 我怎樣才能做到這一點?
<script>
function disable(post)
{
if(post=="0")
document.getElementById("status").disabled=true;
else
document.getElementById("status").disabled=false;
}
</script>
<select name="status" id=<?= $row["id_post"] ?> onChange="disable(this.value)">
<option value="0">Status</option>
<option name="enable" id="enable" value="1">Enable</option>
<option name="disable" id="disable" value="0">Disable</option>
</select>
我的數據庫表名稱為“ r_post”,列名稱為“ status int(1)”,
無需根據您的代碼使用JavaScript啟用和禁用。
<select name="status">
<option>Status</option>
<option value="1" <?php ($row["status"]==1)?'selected':'' ?>>Enable</option>
<option value="0" <?php ($row["status"]==0)?'selected':'' ?>>Disable</option>
</select>
編輯您的代碼首先,您需要創建一個php操作頁面,如果您想創建此頁面,則可以將代碼寫下到相同的php文件中。 然后在選擇框上選擇,您需要提交表格。 然后操作將在同一頁面上進行,您的更新查詢將更新您的博客記錄。 您需要在隱藏的輸入類型中添加表ID,以便查詢將獲得確切的地址。
<html>
<head>
<?php
if(isset($_POST['status']))
{
$sql=mysql_query("update blog set status='".$_POST['Status']."' where id='".$_POST['id']."'");
echo ("blog updated successfully");
}
?>
<title>Your Page name</title>
</head>
<body>
<form name="myform" action="" method="post">
<input type="hidden" name="id" value="<?php echo $row['id'];?>">
<select name="status" id="status1" onchange="this.form.submit()">
<option value="0">Status</option>
<option name="enable" id="1enable" value="1">Enable</option>
<option name="disable" id="1disable" value="0">Disable</option>
</select>
</form>
</body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.