gpt4 book ai didi

php - 更新用户个人资料时出错

转载 作者:行者123 更新时间:2023-11-29 20:58:48 26 4
gpt4 key购买 nike

用户登录时更新用户时遇到问题

我恢复错误:SQLSTATE[42000]: 语法错误或访问冲突: 1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 'SET Registered_users (fullName='test1',mobileNumber='123123',password='8eaaf462') 附近使用的正确语法抱歉,请前往最近的 NPC 进行注册。注意: undefined variable :第 43 行 C:\xampp\htdocs\xampp\bicycleTheft\test5\php\edit_data.php 中的 sql_query

管理细节.php

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();


$stmt = $user_home->runQuery("SELECT * FROM registered_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Update Data From MySql - By Cleartuts</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>

<h1>Edit Particulars</h1>

<div id="body">
<div id="content">
<table align="center" width="100%">


<tr>
<td>Full Name</td>
<td><?php echo $row["fullName"]; ?></td>

</tr>
<tr>
<td>Mobile Number</td>
<td><?php echo $row['mobileNumber']; ?></td>
</tr>

<tr>
<td>Password</td>
<td><?php echo $row ['password']; ?></td>
</tr>

<tr>
<td>Address</td>
<td><?php echo $row['address']; ?></td>
</tr>

<tr>
<td>Postal Code</td>
<td><?php echo $row['postalCode']; ?></td>
</tr>

<tr>
<td>Edit</td>
<td><a href="edit_data.php?edit_id=<?php echo $row[0]; ?>"><img src="b_edit.png" alt="Edit" /></a></td>
</tr>

</table>
</div>
</div>


</center>
</body>
</html>

编辑数据.php

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();
$reg_user = new USER();

$stmt = $user_home->runQuery("SELECT * FROM registered_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);;
if(isset($_GET['edit_id']))
{
$stmt = $user_home->runQuery("SELECT * FROM registered_users WHERE userID=:uid".$_GET['edit_id']);


}
if(isset($_POST['btn-update']))
{
// variables for input data

$fullName = $_POST['fullName'];

$mobileNumber = $_POST['mobileNumber'];

$password = $_POST['password'];
$address = $_POST['address'];
$postalCode = $_POST['postalCode'];
// variables for input data

// sql query for update data into database

if($reg_user->updateUser($fullName,$mobileNumber,$password,$address,$postalCode))
{

echo"good";
}
else
{
echo "sorry ,Pleae go to nearest NPC to register.";
}
// sql query for update data into database

// sql query execution function
if(mysql_query($sql_query))
{
?>
<script type="text/javascript">
alert('Data Are Updated Successfully');
window.location.href='home.php';
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert('error occured while updating data');
</script>
<?php
}
// sql query execution function
}
if(isset($_POST['btn-cancel']))
{
header("Location: home.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Update Data From MySql - By Cleartuts</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>

<div id="header">
<div id="content">
<label>PHP PHP Update Data From MySql - By Cleartuts</label>
</div>
</div>
<div id="body">
<div id="content">
<form method="post">
<table align="center">
<tr>
<td>Full Name</td>
<td><input type="text" name="fullName" placeholder="full Name" value="<?php echo $row['fullName']; ?>" required /></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type="text" name="mobileNumber" placeholder="mobile Number" value="<?php echo $row['mobileNumber']; ?>" required /></td>
</tr>

<tr>
<td>Password</td>
<td><input type="password" name="password" placeholder="password" value="<?php echo $row['password']; ?>" required /></td>
</tr>

<tr>
<td>Address</td>
<td><input type="text" name="address" placeholder="Blk 123 Ang Mo kio Ave 1 #12-112" value="<?php echo $row['address']; ?>" required /></td>
</tr>

<tr>
<td>Postal Code</td>
<td><input type="text" name="postalCode" placeholder="123456" value="<?php echo $row['postalCode']; ?>" required /></td>
</tr>
<tr>
<td>
<button type="submit" name="btn-update"><strong>UPDATE</strong></button>
<button type="submit" name="btn-cancel"><strong>Cancel</strong></button>
</td>
</tr>
</table>
</form>
</div>
</div>



</center>
</body>
</html>

最佳答案

public function updateUser($fullName,$mobileNumber,$password,$address,$postalCode)
{
try
{
$password = md5($password);
$stmt = $this->conn->prepare("UPDATE SET registered_users (fullName=:fullName,mobileNumber=:mobileNumber,password=:password,address=:address,postalCode=:postalCode)");


$stmt->bindparam(":fullName",$fullName);

$stmt->bindparam(":mobileNumber",$mobileNumber);

$stmt->bindparam(":password",$password);
$stmt->bindparam(":address",$address);
$stmt->bindparam(":postalCode",$postalCode);



$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}

关于php - 更新用户个人资料时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37404317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com