我尝试的是update
我的数据库中使用Json数据的列。我开始解码数据,它显示了特定数据的价值,我只是坚持下一步应该做的事情。
登录代码
if(strtolower($_GET['action']) == "login")
{
$username = $_POST['username'];
$password = md5($_POST['password']);
if (!$_POST['username'] | !$_POST['password'] )
{
die("<div style='text-indent: 10px;color: #FF0000;margin-top: -27px;'>Error - Please fill out the required fields to login</div>");
}
if($username == null) return;
if($password == null) return;
if(!$conn) die("MySQL Error.");
$result = $conn->prepare("SELECT * FROM `users` WHERE username= :Player AND password= :Pass");
$result->bindParam(':Player', $username);
$result->bindParam(':Pass', $password);
$result->execute();
if(!$result) die("An Error has occured");
$rows = $result->fetch(PDO::FETCH_ASSOC);
$c = unserialize($rows['addons']);
$profileData = $rows['profile'];
#gets json data from $profileData
$json_a=json_decode($profileData,true);
$json_o=json_decode($profileData);
foreach($json_o->profile as $p)
if(!$rows) die("<div style='text-indent: 10px;color: #FF0000;margin-top: -27px;'>Error - Username or Password was incorrect</div>");
if($c['powers']['profile']['has'] == 0) die("<div style='text-indent: 10px;color: #FF0000;margin-top: -27px;'>Error - You don't have the available permission to edit your profile</div>");
echo ("<div style='text-indent: 350px;position: absolute; margin-top: 33px;'>Login as <b><a target='_blank' href='http://localhost/uprofile.php?u=$username'> $username </a></b></div>");
?>
这是我解码配置文件数据的地方
$json_a=json_decode($profileData,true);
$json_o=json_decode($profileData);
foreach($json_o->profile as $p)
更新代码:
<?php
}
else
if(strtolower($_GET['action']) == "publish")
{
$username = $_POST['myname'];
$value = $_POST['value'];
if(!$conn) die("MySQL Error.");
$q = $conn->prepare("UPDATE users SET profile = :Profile WHERE username= :Player ");
$q->bindParam(':Player',$username);
$q->bindParam(':Profile',$value);
if($q->execute()){
echo "<div style='text-indent: 10px;color: #008000;margin-top: -27px;'>Profile has been updated</div>";
} else {
echo "Couldn't update Profile";
}
}
else
{
?>
输出值$p->detail
如下所示
<form action='?action=publish' method='post'>
<textarea rows="30" cols="90" name="value" style="margin: 0px 0px 10px; width: 655px; height: 394px;">
<?php echo $p->detail; ?>
</textarea>
</form>