MySQL을 쿼리하는 PHP 파일에 "국가 코드"를 보내는 드롭 다운 메뉴를 만듭니다. 이렇게하면 html 테이블이 생성됩니다. $ _GET은 항상 아무것도받지 않는다는 점을 제외하면 모든 것이 작동하는 것 같습니다. 심지어 쿼리 문자열에 코드를 하드 코딩 할 때도 마찬가지입니다. 내가 뭘 놓치고 있니?
HTML :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript">
function showCountry(str) {
if (str == "") {
document.getElementById("SurveyContainer").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("SurveyContainer").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getSurveys.php?q=" + str, true);
xmlhttp.send();
}
</script>
</head>
<body>
<select name="countries" onchange="showCountry(this.value)">
<option value="">Select Country:</option>
<option value="WW">WW</option>
<option value="AU">AU</option>
<option value="USA">USA</option>
</select>
<div id="SurveyContainer"><b>Survey table</b></div>
</body>
</html>
getSurveys.php : 사전에
<?php
//Get Country Code
$q = (isset($_GET['q']) && is_numeric($_GET['q'])) ? intval($_GET['q']) :'WW';
$con = mysqli_connect('localhost','myusername','mypassword','mydatabase');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"mydatabase");
$sql="SELECT * FROM tblSurveys WHERE country = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table class='surveytable'>";
echo "<tr><th width='61'>Country</th><th>Link To Join Paying Survey Panel Web Site</th><th>About Survey Panel</th><th width='93'>Survey Incentives</th></tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr><td><b>$row[country]</b></td><td><a href='$row[link]' target='_blank'>$row[name]</a></td><td>$row[description] </td><td>$row[incentives]</td></tr>";
}
echo "</table>";
mysqli_close($con);
?>
감사합니다!
브라우저 URL 표시 줄에서 직접 스크립트를 호출하는 경우 작동합니까? –
참고로 양식 태그가 없습니다. HTML이 유효하지 않습니다. –
'getSurveys.php' 콘텐츠를 수정하십시오. 나는'mypassword '를 의미합니다. –