Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显然,更新查询中没有错误,但记录没有更新_Php_Mysql_Sql_Html - Fatal编程技术网

Php 显然,更新查询中没有错误,但记录没有更新

Php 显然,更新查询中没有错误,但记录没有更新,php,mysql,sql,html,Php,Mysql,Sql,Html,这是我的usersedit.php代码,另一个是users-edit-action.php代码 更新后,它表示数据已成功更新,但mysql中没有任何更改。。请帮我解决这个问题,谢谢 users-edit.php <?php include("../includes/config.php"); ?> <?php if ($_SESSION["isadmin"]) { $con=mysql_connect($dbserver,$dbusername,$dbpassword); i

这是我的usersedit.php代码,另一个是users-edit-action.php代码 更新后,它表示数据已成功更新,但mysql中没有任何更改。。请帮我解决这个问题,谢谢 users-edit.php

<?php include("../includes/config.php"); ?>
<?php
if ($_SESSION["isadmin"])
{

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);
$accountid=$_GET["id"];
$result = mysql_query("SELECT * FROM accounts WHERE (id='".$accountid."')");
while($row = mysql_fetch_array($result))
{
$id=$row['id'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email=$row['email'];
$type=$row['type'];
}
mysql_close($con);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Edit User</title>
<link rel="StyleSheet" href="../admin/css/style.css" type="text/css" media="screen">
</head>


<body>
<?php include("../admin/includes/header.php"); ?>
<?php include("../admin/includes/nav.php"); ?>
<?php include("../admin/includes/manage-users-aside.php"); ?>
<div id="maincontent">

<div id="breadcrumbs">
<a href="">Home</a> >
<a href="">Manage Users</a> >
<a href="">List Users</a> >
Edit User
</div>
<h2>Edit User</h2>

<form method="post" action="users-edit-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email;     ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo     $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo      $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo     'checked="checked"'; ?> />Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo 'checked="checked"'; ?> /> Teacher<br />

<input type="submit" value="Edit" />
</form>
</div>
</body>
<?php include("../admin/includes/footer.php"); ?>
</html>
<?php

}    else
{
header("Location: ".$fullpath."login/unauthorized.php");
}
?>


转义为

$query=("UPDATE accounts 
         SET firstname='" . $firstname . "'   ,
             lastname='" . $lastname . "      ,
              `password`='" . $password . "'  ,          
              email='" . $email . "'          ,            // <== forgot comma
              type='" . $type . "' WHERE (id='".$id."')
        ");

这将允许您插入带有单引号的记录。

转义列名,即

$query=("UPDATE accounts 
         SET firstname='" . $firstname . "'   ,
             lastname='" . $lastname . "      ,
              `password`='" . $password . "'  ,          
              email='" . $email . "'          ,            // <== forgot comma
              type='" . $type . "' WHERE (id='".$id."')
        ");

这将允许您插入带有单引号的记录。

您能在这里发布
$result
的值吗?您没有转义任何用于构造查询的变量,它们是否包含引号?请转储并检查$query。您能在这里发布
$result
的值吗?您没有转义构建查询的任何变量,它们是否包含引号?请转储并检查$query.addresult检查
mysql\u query()
echo(!$result)?“错误”:“用户已成功更新!!”这是我按u所说的方式存储代码。但它仍然没有更新数据库中的记录…我以前从未遇到过这个问题..请帮助$con=mysql\u connect($dbserver,$dbusername,$dbpassword);如果(!$con){die('cannotconnect:'.mysql_error());}mysql_select_db($dbname,$con)$结果=(“更新帐户集firstname=””、“$firstname.”、lastname=”、“$lastname.”、“$password'=”、“$password.”、email=”、“$email.”、type=”、“$type.”,其中(id=”、“$id.”);echo“用户已成功更新!!”;mysql_close($con);?>为
mysql\u query()
添加结果检查:
echo(!$result)?“错误”:“用户已成功更新!!”这是我按u所说的方式存储代码。但它仍然没有更新数据库中的记录…我以前从未遇到过这个问题..请帮助$con=mysql\u connect($dbserver,$dbusername,$dbpassword);如果(!$con){die('cannotconnect:'.mysql_error());}mysql_select_db($dbname,$con)$结果=(“更新帐户集firstname=””、“$firstname.”、lastname=”、“$lastname.”、“$password'=”、“$password.”、email=”、“$email.”、type=”、“$type.”,其中(id=”、“$id.”);echo“用户已成功更新!!”;mysql_close($con);?>
<?php

    $query = "UPDATE accounts 
               SET firstname = ?,
                   lastname = ?,
                   `PassWord` = ?,          
                   email = ?,          
                   type = ? 
            WHERE id = ?
        ";

    $stmt = $dbh->prepare($query);
    $stmt->bindParam(1, $firstname);
    $stmt->bindParam(2, $lastname);
    $stmt->bindParam(3, $password);
    $stmt->bindParam(4, $email);
    $stmt->bindParam(5, $type);
    $stmt->bindParam(6, $id);

    $stmt->execute();
    echo ($stmt) ? "Successful" : "Error Occured";

?>