我是网络服务的初学者。这是我在静态网络服务中使用php,json和mysql的代码,以便更新用户状态。即使我无法将用户信息更新到数据库..plz帮助我出去...... !!
<?php
//content header-type
//header('content-type: application/json');
// connect to data-base
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
//on submit action
if(isset($_PUT['update']))
{
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$id = isset($_SERVER['HTTP_ID']) ?
mysql_real_escape_string($_SERVER['HTTP_ID']) : "";
$status = isset($_SERVER['HTTP_STATUS']) ?
mysql_real_escape_string($_SERVER['HTTP_STATUS']) : "";
// validations of code
if(!empty($id)){
$qur = mysql_query("UPDATE `miisky`.`register` SET `status` = '$status' WHERE `register`.`ID` ='$id';");
if($qur){
$json = array("status" => 1, "msg" => "Status updated!!.");
}else{
$json = array("status" => 0, "msg" => "Error updating status");
}
}else{
$json = array("status" => 0, "msg" => "User ID not define");
}
}else{
$json = array("status" => 0, "msg" => "User ID not define");
}
@mysql_close($conn);
/* Output header */
header('Content-type: application/json');
echo json_encode($json);
}
?>
听到我的html验证部分,验证用户以便从用户接收输入并更新特定用户的状态。
<body>
<form method = "POST" action = "update2.php">
<h1>Please enter your user id to update your other details</h1>
<label>ID</label>
<input type = "text" name = "ID"><br/>
<label>Status</label>
<input type = "text" name = "status">
<br/>
<input type = "submit" name = "update">
</form>
</body>
答案 0 :(得分:0)
HTML表单仅支持GET和POST。只有方法属性允许以html格式提供GET和POST请求。所以你不能在method属性中设置PUT方法类型。在方法属性中更改方法类型。 根据HTML标准,你不能。
<form method = "PUT" action = "update2.php">
更改您的方法属性,例如GET或POST。
<form method = "GET" action = "update2.php">
由于错误的mehtod属性值,您的if条件不会成立。你总是得到GET值: -
if($_SERVER['REQUEST_METHOD'] == "PUT")