请教PHP怎么修改json数据

小黑帽子 2016-10-09 05:53:20
请教PHP怎么修改json数据:

1:数据库表结构是这样的:


2.数据内容是这样的:

主要是 text 字段用的是json存储,我不知道怎么改


3.修改的页面代码是这样的:

<form action="messages_sp_ajax.php?step=change2" method="post"><input type="hidden" name="id" value="<?php echo $id ?>" /><input type="hidden" name="page" value="<?php echo $page ?>" />
<table class="table table-bg">
<tbody>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> ID:</th>
<td><?php echo $rst[id]; ?></td>
</tr>

<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 公司名:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $rst[title]; ?>" placeholder="" name="title"></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 公司地址:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $text[address]; ?>" placeholder="" name="address"></td>
</tr>

<tr>
<th width="100" style="text-align:left;" colspan="2"><h2>项目物流</h2></th>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 标题:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $rst[topic]; ?>" placeholder="" name="topic"></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 内容:</th>
<td><textarea type="text" style="width:400px;" class="input-text" placeholder="" name="pci"><?php echo $text[pci]; ?></textarea></td>
</tr>


<tr>
<th width="100" style="text-align:left;" colspan="2"><h2>项目物流案例</h2></th>
<td></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 标题:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $rst[topic2]; ?>" placeholder="" name="topic2"></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 内容:</th>
<td><textarea type="text" style="width:400px;" class="input-text" placeholder="" name="pcase"> <?php echo $text[pcase]; ?></textarea></td>
</tr>

<tr>
<th width="100" style="text-align:left;" colspan="2"><h2>公司信息</h2></th>
<td></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 公司简介:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $text[Company_p]; ?>" placeholder="" name="Company_p"></td>
</tr>

<tr>
<th width="100" style="text-align:left;" colspan="2"><h2>联系方式</h2></th>
<td></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 名字:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $text[firstname]; ?>" placeholder="" name="firstname"></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 姓:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $text[surname]; ?>" placeholder="" name="surname"></td>
</tr>
<tr>
<th width="100" class="text-r"><span class="c-red">*</span> 职位:</th>
<td><input type="text" style="width:400px;" class="input-text" value="<?php echo $text[job]; ?>" placeholder="" name="job"></td>
</tr>




<tr>
<th></th>
<td><button class="btn btn-success radius" type="submit"><i class="icon-ok"></i> 确定</button></td>
</tr>
</tbody>
</table>
</form>

4.messages_sp_ajax.php?step=change2 页面是这样的:
if($step == "change2")
{
if($_POST)
{
$data = $_POST;
if(empty($_POST[title])){ ShowMessages('messages_sp_change.php?page='.$data[page].'&id='.$data[id],'有内容为空');}else{
$where[id] = $_POST[id];


$tb = "tb_messages_sp";
$datano = array("id","page");
$sql = ChangeSql($data,$where,$tb,$datano);
if($sql[MessageID]==1){
// operationLog("修改-".$_POST[title],$rst_user[id],1,'link');
ShowMessages('messages_sp_list.php?page='.$page);
}else
{
ShowMessages('messages_sp_change.php?page='.$data[page].'&id='.$data[id],'含有非法字符');
}
}
}
}

text 字段完全改不了,该怎么改啊?

...全文
440 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
小黑帽子 2016-10-09
  • 打赏
  • 举报
回复
引用 3 楼 fdipzone 的回复:

$json = '{"name":"fdipzone","date":"2016-10-10"}';
echo $json; // 原始数据

$data = json_decode($json, true);
$data['name'] = 'abc';
$data['date'] = '2017-10-10';
$data['ext'] = 'ext';

$result = json_encode($data);
echo $result; // 修改后数据
在我的代码里改啊
傲雪星枫 2016-10-09
  • 打赏
  • 举报
回复

$json = '{"name":"fdipzone","date":"2016-10-10"}';
echo $json; // 原始数据

$data = json_decode($json, true);
$data['name'] = 'abc';
$data['date'] = '2017-10-10';
$data['ext'] = 'ext';

$result = json_encode($data);
echo $result; // 修改后数据
小黑帽子 2016-10-09
  • 打赏
  • 举报
回复
引用 1 楼 jam00 的回复:
json_decode($text , true); 解析成数组,修改数组内的数据后再 json_encode($text); 存入 数据字段 text 中就行了
能帮忙写出来吗?不太懂啊
果酱很好吃 2016-10-09
  • 打赏
  • 举报
回复
json_decode($text , true); 解析成数组,修改数组内的数据后再 json_encode($text); 存入 数据字段 text 中就行了

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧