我尝试提交表单并在同一页面上回显MySQL表中的数据,但它没有显示任何内容,我认为我的代码中有错误,但我没有&# 39;不知道它是什么。
这是我的代码:
<?php
if ( isset($_POST['consulta']) )
{
echo"
<table align='center' border='1' class='TablaConsulta'>
<tr>;
<td>Codigo Escaneado</td>
<td>Nombre Producto</td>
<td>Precio Prodcuto</td>
</tr>
";
include ("connector.php");
$con = conectar();
$tbl = "productos";
$query = "SELECT * FROM $tbl WHERE CodigoProducto =".$_POST['CoProducto'];
$resultado = mysql_query($query, $con) or die(mysql_error($con));
while($dato=mysql_fetch_array($resultado)){
echo "<tr>";
echo "<td>".$dato['CodigoProducto']."</td>";
echo "<td>".$dato['Descripcion']."</td>";
echo "<td>".$dato['Precio']."</td>";
echo "</tr>";
}
mysql_close($con);//cerrar conexion
echo"</table>";
}
?>
答案 0 :(得分:0)
我自己解决了这个问题,我在“connector.php”段上使用了mysqli,在查询段上使用了mysql。
我将代码更改为:
<?php
if ( isset($_POST['consulta']) )
{
echo"
<table align='center' border='1' class='TablaConsulta'>
<tr>;
<td>Codigo Escaneado</td>
<td>Nombre Producto</td>
<td>Precio Prodcuto</td>
</tr>
";
include ("connector.php");
$con = conectar();
$tbl = "productos";
$query = "SELECT * FROM $tbl WHERE CodigoProducto =".$_POST['CoProducto'];
echo $query;
$resultado = mysqli_query($con,$query) or die(mysqli_error($con));
while($dato=mysqli_fetch_array($resultado)){
echo "<tr>";
echo "<td>".$dato['CodigoProducto']."</td>";
echo "<td>".$dato['Descripcion']."</td>";
echo "<td>".$dato['Precio']."</td>";
echo "</tr>";
}
mysql_close($con);//cerrar conexion
echo"</table>";
}
&GT;
它现在正在运作。