【发布时间】:2018-05-10 07:55:39
【问题描述】:
我知道 php 是一种服务器端语言,而 html 是一种客户端语言,为此我会使用 javascript,但我不知道该怎么做。 有人可以帮我编写名为 changeFunction() 的脚本吗?
这是我在 index.php 中的表单:
<form method="POST">
<div class="row"style="margin-top: 5%;">
<div class="col-3">
</div>
<div class="col-6">
<label for="inputUsername">Insert username</label>
<input type="text" class="form-control" name="inputUser" style="margin-bottom: 2%">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Convert account type to: </label>
</div>
<select class="custom-select" id="inputGroupSelect01" name="inputSelected">
<option selected>Choose...</option>
<option value="admin">Admin</option>
<option value="user">User</option>
</select>
<button type="button" class="btn btn-outline-primary" onclick="changeFunction()">Submit</button>
</div>
</div>
<div class="col-3">
</div>
</div>
</form>
这是我在 query.php 中的查询:
<?php
$var1= $_POST["inputGroupSelect01"];
$var2= $_POST["inputUser"];
require 'connection.php';
$sql = "UPDATE user SET typeAcc =".$var1." WHERE username=".$var2;
?>
【问题讨论】:
-
请注意 SO 不是教程服务
-
您不需要 JavaScript。添加 PHP 页面作为其操作。提交表格。然后您可以使用 $_POST 中的变量。 de2.php.net/manual/en/reserved.variables.post.php
标签: javascript php html mysql sql