drtsd7864 2014-10-09 22:14
浏览 41
已采纳

MySQL查询无法读取PHP变量

I have a HTML form (Datadisplay.html) which uses the POST method to give (datadisplay.php) variables name and model, which are integrated into the SQL query ($sql). The problem is that php doesn't display any errors, but my query displays just blank, in the HTML.

I know for a fact the rest works since when I replace $this->name and $this->model for strings it does pull up the info. any help would be appreciated.

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

DATA DISPLAY 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>";
    }
?>

data display 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>
  • 写回答

3条回答 默认 最新

  • 普通网友 2014-10-09 22:40
    关注

    You need to enclose object properties into curly braces if you want them parsed inside the double quotes:

    $this->sql = 
       "SELECT * 
        FROM {$this->table} 
        WHERE modelo='{$this->model}' AND nombre='{$this->name}'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮