gpt4 book ai didi

php - MySQL查询无法读取PHP变量

转载 作者:行者123 更新时间:2023-11-29 23:38:41 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com