내 서버의 클라우드에있는 데이터베이스에서 데이터 테이블을 다시 가져 오려고하는 ibook이 있습니다. 내 서버에 main.html 파일을 놓고 내 웹 브라우저에서 찾아 보면 챔피언이 데이터 테이블을 반환하는 것처럼 작동하지만 Info.plist에이 HTML을 main.html 파일로 저장할 때 ibook에 표를 표시하십시오. 내가 뭘 놓치고 있니? 여기 온라인 데이터베이스에서 쿼리 된 데이터를 표시하는 방법은 무엇입니까?
책 여기<html>
<head>
<script type="text/javascript" src="http://myserver.com/ibook_widgets/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'post',
url: 'http://myserver.com/ibook_widgets/getdata.php?id=4',
data: 'json',
beforeSend: function() {
// before send the request, displays a "Loading..." messaj in the element where the server response will be placed
$('#resp').html('Loading...');
},
timeout: 10000, // sets timeout for the request (10 seconds)
error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
success: function(response) { $('#listhere').html(response); }
});
});
</script>
</head>
<body>
<div id="listhere" style="border: solid black 1px; background-color:red;">Replace this text with html table from php file</div>
</body>
</html>
의 페이지에 아이북의 HTML 위젯의 위젯에 내 html 파일 것은 내 서버에 내 PHP 파일입니다
<?php
/*
* Following code will list all the products
*/
$dbhostname='myserver.com';
$dbusername='usr';
$dbpassword='pwd';
$dbname='mydatabase';
$con = mysql_connect($dbhostname,$dbusername,$dbpassword);
mysql_select_db($dbname, $con);
// check for post data
if (isset($_POST["id"]))
{
$inValue = $_POST['id'];
$sql = 'select id, btn_txt from mytable where parent_id = '.$inValue.' order by btn_txt';
$result = mysql_query($sql) or die(mysql_error());
if (!empty($result))
{
// check for empty result
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
$btntxt = $row['btn_txt'];
$result1 = mysql_query($sql) or die(mysql_error());
// check for empty result
if (!empty($result1))
{
// check for empty result
if (mysql_num_rows($result1) > 0)
{
// looping through all results
// products node
$tmpStr = "<table border='1'><tr><th>Tap A Row To See Details</th></tr>";
// show select box input_select_4
while($row1 = mysql_fetch_array($result1))
{
$tmpStr = $tmpStr . "<tr><th><a href=\"http://myserver.com/ibook_widgets/getdata.php?id=". $row1["id"] . "\" target=\"_self\">" . $row1["btn_txt"] . "</a></th></tr>";
}
$tmpStr = $tmpStr . "</table>";
echo $tmpStr;
// echoing JSON response
///echo json_encode($tmpStr);
mysql_close($con);
// echoing JSON response
////echo json_encode($response);
}
}
}
}
}
?>
무엇 내가 빠졌어?
[** 새 코드 **에서 mysql_ * 함수를 사용하지 마십시오 (http://bit.ly/phpmsql). 그들은 더 이상 유지되지 않으며 [공식적으로 사용되지 않습니다] (http://j.mp/XqV7Lp). [** 빨간색 상자 **] (http://j.mp/Te9zIL)를 참조하십시오. 대신 [* prepared statements *] (http://j.mp/T9hLWi)에 대해 알아보고 [PDO] (http://php.net/pdo) 또는 [MySQLi] (http://php.net/)를 사용하십시오. mysqli) - [이 기사] (http://j.mp/QEx8IB)는 어떤 결정을 내리는 데 도움이 될 것입니다. PDO를 선택하면 [여기는 좋은 튜토리얼입니다] (http://j.mp/PoWehJ). – thaJeztah
코드가 SQL Injection에 취약합니다. SQL 문에서 값을 사용하기 전에 값을 이스케이프 처리하지 않으므로 중요한 정보와 데이터 손실이 발생할 수 있습니다. 이 사이트에서 몇 가지 예와 그 결과를 확인하십시오. http://www.unixwiz.net/techtips/sql-injection.html – thaJeztah
답변을 주셔서 감사합니다 ... 둘 다 유효한 의견이지만 질문에 대한 답변은 아닙니다. 나는 다음과 같이 CORS와 관련이 있다고 결론을 내렸다. –