我在一個單獨的文件中有一些php代碼,並使用javascript調用它。但PHP代碼沒有工作。相反,它只是把代碼放在div中。像完整的代碼在div中。我怎樣才能使這個PHP代碼執行php代碼不能執行。檢查配置文件已經
我的JavaScript函數如下所示:
function checklogin(){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText='FAILED')
{alert('failed');};
}
}
var Usrname
Usrname=document.getElementById("edtLoginUsername").text;
xmlhttp.open("GET","DatabaseFunctions.php?Username="+Usrname,true);
xmlhttp.send();};
和我的PHP代碼如下所示:
<?php
$myServer = "example.com";
$myUser = "dbuser";
$myPass = "dbpass";
$myDB = "efarm";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT COUNT(*) FROM Users WHERE Username=myQuoteString('$_GET(USERNAME)')'";
//execute the SQL query and return records
$result = mssql_query($query);
echo 'FAILED';
//close the connection
mssql_close($dbhandle);
?>
我已經檢查了我的httpd.conf文件並檢查php是否已安裝和配置
您是否嘗試在瀏覽器中打開PHP文件並查看是否有效? – HMR
瀏覽器是否顯示任何錯誤消息或任何消息? – sanj
而且要非常小心你的代碼容易受到SQL注入的影響......不要在生產環境中使用它!\ – Freelancer