2017-04-03 1 views
0

PHP와 MYSQL을 사용하는 AJAX에 대한 입문서를 보았습니다.이 내용은 AJAX와 PHP에서의 첫 번째 시도이며 NetBeans에서 실행하고 싶습니다. 실행 방법을 알지 못합니다. NetBeans에서 어떻게 실행합니까? 주 파일을 ajax.html로 설정하고 녹색 화살표를 사용하여 실행하려고했지만 유효한 데이터를 입력하고 "Query MySQL"단추를 클릭하면 HTML 페이지가 나타나지 않습니다.NetBeans에서 AJAX PHP 예제 실행

여기 ajax.html 파일

<html> 
<body> 
<script language="javascript" type="text/javascript"> 
<!-- 
// Browser support code 
function ajaxFunction(){ 
var ajaxRequest; // the variable that makes AJAX possible 
try{ 
    // Opera 8.0+, Firefox, Safari 
    ajaxRequest = new XMLHttpRequest(); 
} catch(e){ 
// internet explorer browsers 
    try{ 
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
    }catch(e){ 
    try{ 
     ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
     } catch(e) { 
     // something wrong in creating XMLHttpRequest 
     alert("Browser didn't create XMLHttpRequest"); 
     return false; 
     } 
    } 
} 

// Now get the value from user and pass it to 
// server script 
var age = document.getElementById('age').value; 
var wpm = document.getElementById('wpm').value; 
var sex = document.getElementById('sex').value; 

var queryString = "?age=" + age; 
queryString += "&wpm=" + wpm +"&sex=" + sex; 
ajaxRequest.open("GET", "ajax-example.php" + queryString, true); 
ajaxRequest.send(null); 
} 
// --> 
</script> 

<form name='myForm'> 
<br /> 
    Max Age: <input type='text' id='age' /> <br /> 
<br /> 
    Max WPM: <input type='text' id='wpm' /> 
<br /> 
<br /> 
Sex: <select id='sex'> 
<option value="m">m</option> 
<option value="f">f</option> 
</select> 
<input type='button' onClick='ajaxFunction()' value='Query MySQL' /> 
</form> 
<div id='ajaxDiv'>Your result will be displayed here</div> 
</body> 
</html> 

다음은 ajax-example.php 파일입니다. 내 컴퓨터에 MySQL은 "localhost3306"와 포트 번호 7777가 넷빈즈

이이

를 사용하여 PHP 프로젝트를 실행하는 방법에 대한 자습서를 표시 할 공식적으로 그물 콩 웹 사이트 netbeans.org

<?php 

$dbhost = "localhost3306:7777"; 
$dbuser = "root"; 
$dbpass = "password"; 
$dbname = "web_prof_tracker"; 

// Connect to MySQL server 
mysql_connect($dbhost, $dbuser, $dbpass); 

// Select database 
mysql_select_db($dbname) or die(mysql_error); 

// Retrieve the data from Query String 
$age = $_GET['age']; 
$sex = $_GET['sex']; 
$wpm = $_GET['wpm']; 

// Escape user input to help prevent SQL injection 
$age = mysql_real_escape_string($age); 
$sex = mysql_real_escape_string($sex); 
$wpm = mysql_real_escape_string($wpm); 

// Build query 
$query = "SELECT * FROM ajax_example WHERE sex = '$sex'"; 
if(is_numeric($age)) 
    $query .= " AND age <= $age"; 
if(is_numeric($wpm)) 
    $query .= " AND wpm <= $wpm"; 

// Execute query 
$qry_result = mysql_query($query) or die (mysql_error()); 

// Build result string 
$display_string = "<table>"; 
$display_string .= "<tr>"; 
$display_string .= "<th>Name</th>"; 
$display_string .= "<th>Age</th>"; 
$display_string .= "<th>Sex</th>"; 
$display_string .= "<th>WPM</th>"; 
$display_string .= "</tr>"; 

// Insert a new row in the table for each person returned 
while($row = mysql_fetch_array($sql_result)){ 
$display_string = "<tr>"; 
$display_string .= "<td>$row[name]</td>"; 
$display_string .= "<td>$row[age]</td>"; 
$display_string .= "<td>$row[sex]</td>"; 
$display_string .= "<td>$row[wpm]</td>"; 
$display_string .= "</tr>"; 
} 
echo "Query: " . $query . "<br />"; 

$display_string .= "</table>"; 
echo $display_string; 
?> 
+0

, 당신이 바로 거기 중지하고 * '도 만들 감가 상각'mysql_로를 사용하지 않는 튜토리얼을 찾을 제안 자습서가 SQL 주입 방지를 다루는 지 확인하십시오 –

+0

PHP 실행을 위해 웹 서버가 있어야합니다. – webDev

+0

@webDev Netbeans은 보통 tomcat이 있습니다. –

답변

2

를 사용하는 것으로 나타납니다 steps,

아파치가 있고 PHP 프로젝트를 실행하는 데 사용했던 것처럼 PHP 환경 설정을 건너 뛸 것입니다.

  1. 시작 IDE, 프로젝트 창으로 전환을하고, 파일> 새로 프로젝트를 선택 : 당신의 넷빈즈에

    이 당신이해야 할 것입니다. 프로젝트 선택 패널이 열립니다.

  2. 범주 목록에서 PHP를 선택하십시오.
  3. 프로젝트 영역에서 PHP 응용 프로그램을 선택하고 다음을 클릭하십시오. 새로운 PHP 프로젝트> 이름 및 위치 패널이 열립니다. enter image description here

는 소스 폴더가 XAMPP에서 내부 htdocs에가 있는지 확인합니다. 때 다음

다음 다음 프로젝트의 URL을 다음

enter image description here

당신이 다음 프로젝트를 열 필요가

사용자 설정 구성했을를 지정 파일 다음을 클릭하고 로컬 웹 사이트로 실행을 선택 완료 메뉴에서 실행을 선택

enter image description here

T 암탉 귀하의 프로젝트는 기본 netbeans 프로젝트 브라우저에 표시됩니다. 이 도움이 될 것입니다

희망, 행운을 빌어

출처 : https://netbeans.org/kb/docs/php/quickstart.html 당신은 단지 학습을 시작한 경우