php代码未执行。已检查配置文件

php代码未执行。已检查配置文件,php,javascript,apache,Php,Javascript,Apache,我在一个单独的文件中有一些php代码,它是使用javascript调用的。但是php代码不起作用。相反,它只是把代码放在div中。就像完整的代码放在div中一样。我怎样才能让这个php代码执行呢 我的javascript函数如下所示: function checklogin(){ var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } xmlh

我在一个单独的文件中有一些php代码,它是使用javascript调用的。但是php代码不起作用。相反,它只是把代码放在div中。就像完整的代码放在div中一样。我怎样才能让这个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
      $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);
      ?>
$query = "SELECT COUNT(*) FROM Users WHERE Username=".myQuoteString($_GET['USERNAME']); 
我的PHP代码如下所示:

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
      $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);
      ?>
$query = "SELECT COUNT(*) FROM Users WHERE Username=".myQuoteString($_GET['USERNAME']); 

检查您的
MS SQL连接
并使用
$\u GET['Username']
代替
$\u GET(Username)

你的问题是:

"...myQuoteString('$_GET(USERNAME)')'";
这对于PHP来说是不正确的语法。在这一小段代码中,大约有五个不同的错误

  • $\u GET
    是一个数组,不是函数,所以它需要方括号,而不是圆括号
  • USERNAME
    括号内的值是字符串,因此必须用引号括起来
  • myQuoteString()
    是一个函数调用,这意味着它不能在查询字符串中
  • 您在
    $\u GET
    周围有引号,这也是不正确的
哎哟

我假设
myQuoteString()
是您编写的一个函数,它可以转义一个变量以用于SQL查询并添加引号

在这种情况下,您的代码需要如下所示:

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
      $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);
      ?>
$query = "SELECT COUNT(*) FROM Users WHERE Username=".myQuoteString($_GET['USERNAME']); 
如果
myQuoteString()
不能做到这一切,您需要确保它能做到,或者以其他方式转义输入变量,否则您将容易受到黑客攻击

(如果不确定,请尝试使用包含引号字符的名称发布表单;如果转义不正确,将导致程序失败)


希望对您有所帮助。

您是否尝试在浏览器中打开PHP文件并查看其是否有效?浏览器是否显示任何错误消息或消息?请注意,您的代码容易受到SQL注入的攻击。。。不要在生产中使用它\如果我直接指向文件,我的代码似乎会在浏览器中执行。但是它似乎仍然没有执行javascript中的代码,我的js代码有什么问题吗?如果你只是把用户名当作字符串,它仍然容易受到SQL注入的攻击。。我想你想说你逃避了所有的角色