在JSON数据中的空格之后,PHP不会在HTML文本框中获取JSON值

时间:2013-10-01 04:32:31

标签: php html json

if(isset($_POST['files'])){

echo $name=$_POST['files'];
$name1=$_POST['path'];
if(isset($_POST['edit']))
{
$jsonString = file_get_contents("./events/$name1/data.json");
$data = json_decode($jsonString,true);


foreach ($data as $key => $value) {
   if ($value['sub_event_name'] == $name) {
    $id=$value['sub_event_id'];
$name=$value['sub_event_name'];
    $Description=$value['sub_event_description'];
 $Fees=$value['sub_event_entryfees'];
 $Prize=$value['sub_event_prizemoney'];
 $Location=$value['sub_event_location'];
 $Time=$value['sub_event_time'];
 $Head=$value['sub_event_head_name'];
 $Contact=$value['sub_event_head_contact'];
}
}


echo '<form action="editsubmit.php" method="post">';
echo 'Main Event:<input type="hidden" name="path" value='.$name1.' readonly />';
echo 'Id: <input type="text" name="id" id="id" value='.$id.' readonly /><br />';
echo 'Event Name : <input type="text" name="eventname" id="id" value='.$name.' required      /><br />'; 
echo 'Event Description:<input type="text" name="description" id="id"          value='.$Description.' required /><br />';
echo 'Entry Fees:<input type="text" name="fees" id="id" value='.$Fees.' required /><br />';
echo 'Prize:<input type="text" name="prize" id="prize" value='.$Prize.' required /><br />';
echo 'Location Of Event:<input type="text" name="location" id="id" value='.$Location.' required /><br />';
echo 'Time and date of Event:<input type="datetime-local" name="time" id="id" value='.$Time.' required /><br />';
echo 'Event Head Name:<input type="text" name="head" id="head" value='.$Head.' required /><br />';
echo 'Event Head Contact:<input type="text" name="contact" id="id" value='.$Contact.' required /><br />';

echo '<input type="submit"/>';
echo '</form>';
    }

data.json

 [{"sub_event_id":"270CA7507EBE029BC6638437F83105C0","sub_event_name":"counter-       strike","sub_event_description":"1st person action game.","sub_event_entryfees":"150Rs","sub_event_prizemoney":"1st-4000Rs ,2nd-     3000Rs,3rd-2000Rs,","sub_event_location":"IT department","sub_event_time":"2013-10-  30T09:00","sub_event_head_name":"Abhishek","sub_event_head_contact":"787xxxx7"},

现在例如 - &gt;

"sub_event_description":"1st person action game."

所以在html文本框中只提取'1st'。所以我应该做更改。所有这些代码都在编辑按钮上..

1 个答案:

答案 0 :(得分:0)

在输入文本框的value属性中使用双引号value="'.$value.'"。可以在没有引号的情况下分配单词,但是字符串(具有多个单词)不能在没有引号的情况下分配。