我有一个HTML表单(Datadisplay.html),该表单使用POST方法提供(datadisplay.php)变量名称和模型,这些变量和模型已集成到SQL查询($ sql)中。问题是php不会显示任何错误,但是我的查询在HTML中仅显示空白。

我知道一个事实,其余的工作正常,因为当我将$this->name$this->model替换为字符串时,它确实提取了信息。任何帮助,将不胜感激。

MYSQL TABLE AS
 id int(11)
 nombre varchar(100)
fecha_remision date
modelo varchar(100)
serial varchar(100)
numero_arraigo varchar(100)


数据显示PHP

<?php
//ERROR_REPORTING( E_ALL | E_STRICT );
 if(isset($_POST['type'])){
class DataDisplay
{
//Variable for MySql connection
  private $hookup;
 private $sql;
    private $tableMaster;
private $name;
      private $model;


 public function __construct()
 {
    //Get table name and make connection

    $this->table=$_POST['type'];
    $this->hookup=UniversalConnect::doConnect();
    $this->doDisplay();
    $this->hookup->close();
    $this->name=$_POST['name'];
    $this->model=$_POST['model'];
}

 private function doDisplay()
{
        //Create Query Statement
    $this->sql ="SELECT * FROM $this->table WHERE modelo='$this->model' AND

  nombre='$this->name'";

    try
    {
    $result = $this->hookup->query($this->sql);

    while ($row = $result->fetch_assoc())
    {
         echo "<tr>";
 echo "<td>id " . $row['id'] . "</td></br>";
 echo "<td>Nombre " . $row['nombre'] . "</td></br>";
 echo "<td>fecha de remision " . $row['fecha_remision'] . "</td></br>";
 echo "<td>serial " . $row['serial'] . "</td></br>";
 echo "<td>modelo " . $row['modelo'] . "</td></br>";
 echo "<td>numero de arraigo " . $row['numero_arraigo'] . "</td></br>";
 echo "</tr></br>";


     }

    $result->close();
    }
    catch(Exception $e)
    {
      echo "Here's what went wrong: " . $e->getMessage();
    }

 }
}
}
else
    {
    echo"<script>alert('selecciona tipo de activo');</script>";
    }
?>


数据显示html

<!doctype html>
 <html>
 <head>
 <link rel="stylesheet" type="text/css" href="css/easy.css">
 <meta charset="UTF-8">
 <title>SCAF</title>
 </head>
 <body>
 <header>
 </header>
 <div>
 <h2>Consulta</h2>
 </div>
 <form action="Client.php" method="post" target="feedback">
 <div><strong>informacion del activo:</strong><br />
   <label for="name">Name:</label>
 <input type="text" name="name" id="name">
 <br />
 <!--cambiar modelo por proyecto(propiedad de tabla), tambien cambiar por radios de
 nombre de proyectos-->
 <label for="model">modelo:</label>
 <input type="text" name="model" id="model">
 <br />
 <p />
 </div>
  <div><strong>categoria</strong><br />
<label for="cs2">transporte:</label>
<input type="radio" name="type" id="cs2" value="transporte">
<br/>
<label for="cs1">maquinaria:</label>
<input type="radio" name="type" id="cs1" value="maquinaria">
<br/>
<label for="cs">maquinaria pesada:</label>
<input type="radio" name="type" id="cs" value="maquinaria pesada">
<br />
 </div>
 <br />
   <div>
   <input type="submit" name="all" value="buscar">
  </div>
 </form>
 <p />
 <div><strong></strong>
  <p />
  </div>

  <iframe name="feedback" seamless width="300" height="200">PHP</iframe>
 <div>
 <p>
 <a href="EasyUpdateOOP.html">Update and Drop Files</a>
 </p>
 </div>
 </body>
 </html>

最佳答案

如果要将对象属性解析在双引号中,则需要将它们括在花括号中:

$this->sql =
   "SELECT *
    FROM {$this->table}
    WHERE modelo='{$this->model}' AND nombre='{$this->name}'";

关于php - MySQL查询无法读取PHP变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26288798/

10-14 15:08
查看更多