function main() { if (!isset($_COOKIE['username']) or !isset($_COOKIE['password']) or !validate($_COOKIE['username'], $_COOKIE['password'])) { header('Location:login.php'); return; } if (empty($_GET['username'])) { // nothing return; } // else username set if (empty($_POST['newcontent'])) { $username = $_GET['username']; $sql = "select * from content where username=\"{$username}\""; $result = exec_sql_on_db('weibo', $sql); $row = mysql_fetch_array($result, MYSQL_ASSOC); $data = json_decode($row['weibo_content']); echo '<div class="InputsWrapper">'; foreach ($data as $this_weibo) { echo '<div>'; echo '<font class="num_of_input" color="#000000"> 0 </font>'; echo '<br> </br>'; echo '<textarea class="newcontent" cols="60" rows="10" >'; echo $this_weibo; echo '</textarea>'; echo '<a href="#" class="removeclass">del</a>'; echo '</div>'; echo '<br></br>'; } echo ' <button type="button" id="addmoreweibo">Add more weibo</button> <button type="button" id="postnewcontent">Submit</button> </div>'; } else { $username = $_GET['username']; $newcontent = $_POST['newcontent']; $sql = "update content set weibo_content=\"{$newcontent}\" where username=\"{$username}\""; $result = exec_sql_on_db('weibo', $sql); echo $_POST['newcontent']; echo "edit ok."; } }
function main() { if (!isset($_COOKIE['username']) or !isset($_COOKIE['password']) or !validate($_COOKIE['username'], $_COOKIE['password'])) { header('Location:login.php'); return; } $json = file_get_contents("php://input"); $data = json_decode($json, true); # $data is a php object $username = $data['username']; $newcontent = json_encode($data['newcontent'], JSON_UNESCAPED_UNICODE); ##debug # $fp = @fopen("/tmp/weibo", "w+"); # $result = @fwrite($fp, $newcontent); # @fclose($fp); ##debug $username = addslashes($username); $newcontent = addslashes($newcontent); $sql = "update content set weibo_content=\"{$newcontent}\" where username=\"{$username}\""; $result = exec_sql_on_db('weibo', $sql); }