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

php code not executing. Checked config files already

本文关键字:检查 配置文件 执行 代码 php      更新时间:2023-09-26

我在一个单独的文件中有一些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代码如下:

<?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是否已安装和配置

检查您的MS SQL Connection并使用$_GET['Username']代替$_GET(USERNAME)

 $query = "SELECT COUNT(*) FROM Users 
         WHERE Username='".$_GET['Username']."'"; 

您的问题在这里:

"...myQuoteString('$_GET(USERNAME)')'";

这是不正确的PHP语法。就在这一小段代码中,大约有五个单独的错误。

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

哎哟。

我假设myQuoteString()是您编写的一个函数,它对SQL查询中使用的变量进行转义并添加引号?

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

$query = "SELECT COUNT(*) FROM Users WHERE Username=".myQuoteString($_GET['USERNAME']); 

如果myQuoteString()没有做到这一切,你需要确保它做到了,或者你以其他方式逃离你的输入变量,否则你很容易受到黑客攻击。

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

希望能有所帮助。