【发布时间】:2015-08-07 04:54:10
【问题描述】:
这是我对php mysql 数据插入应用程序的 android json 响应。请帮我从这个返回响应中获取原始 json
或如何从返回响应中跳过返回 Web (HTML) 表
(data success fully inserting to the data base table)
<br />
<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\AndroidFileUpload\db_connect.php on line <i>28</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>252784</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\AndroidFileUpload\upload_news.php' bgcolor='#eeeeec'>..\upload_news.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>263888</td><td bgcolor='#eeeeec'>DB_CONNECT->__construct( )</td><td title='C:\wamp\www\AndroidFileUpload\upload_news.php' bgcolor='#eeeeec'>..\upload_news.php<b>:</b>26</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>263976</td><td bgcolor='#eeeeec'>DB_CONNECT->connect( )</td><td title='C:\wamp\www\AndroidFileUpload\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>11</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>264792</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysql-connect' target='_new'>mysql_connect</a>
( )</td><td title='C:\wamp\www\AndroidFileUpload\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>28</td></tr>
</table></font>
{"success":1,"message":"Product successfully created."}
在响应的最后一行需要 json 结果。 任何帮助表示赞赏。 提前致谢。
这是我的php 代码
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['news_Title']) && isset($_POST['news_Details']) && isset($_POST['news_Image'])&& isset($_POST['news_Video']) && isset($_POST['reporter_Name']) && isset($_POST['reporter_Email']) && isset($_POST['reporter_Phone'])) {
$news_Title = $_POST['news_Title'];
$news_Details = $_POST['news_Details'];
$news_Image = $_POST['news_Image'];
$news_Video = $_POST['news_Video'];
$reporter_Name = $_POST['reporter_Name'];
$reporter_Email = $_POST['reporter_Email'];
$reporter_Phone = $_POST['reporter_Phone'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO news(news_Title, news_Details, news_Image, news_Video, reporter_Name, reporter_Email , reporter_Phone) VALUES('$news_Title', '$news_Details', '$news_Image', '$news_Video', '$reporter_Name', '$reporter_Email', '$reporter_Phone')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
【问题讨论】:
-
也发布您的 php 代码。
-
响应的 html 部分是否始终相同?
-
您的服务存在问题,有一些关于不推荐使用的方法的警告,请先解决。
-
在
db_connect.php文件中更改为mysqli_connect(),同样在生产中通过设置error_reporting(0);关闭错误报告