我有一个包含ID,FRNZ,MSTR,TES,DEN,PRT
列的表:
- ID = id
- FRNZ =我们的供应商
- MSTR = catalouges的2位数代码
- TES =要搜索的代码
- DEN =对象的名称
- PRT =价格
对于每个CODE,有3行(文章:一个适合一个夹克一条裤子)。我想显示所有3行,其中包含搜索代码的所有详细信息。我编写了这段代码,但我收到了一个错误。
Warning: mysqli_query(): Empty query on line 20
Warning: mysqli_error() expects exactly 1 parameter, 0 given in line 20
我的代码是
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$TES=$_POST['name'];
$db=mysqli_connect ("localhost","root","") or die ('I cannot connect to the database because: ' . mysqli_error());
$mydb=mysqli_select_db($db,"prices");
$sql=`SELECT * FROM PRICES WHERE TES LIKE '%" . $TES . "%' `;
mysqli_real_escape_string($db,$TES);
$result=mysqli_query($db,$sql) or die(mysqli_error().'<br>'.$sql);
while($row=mysqli_fetch_array($result) or die(mysqli_error())){
$FRNZ=$row['FRNZ'];
$MSTR=$row['MSTR'];
$TES=$row['TES'];
$DEN=$row['DEN'];
$PRT=$row['PRT'];
}
echo "<ul>\n";
echo "<li>" . "Furnizor :" .$FRNZ . " Mostrar :" . $MSTR ." Cod tesatura :" .$TES . "Denumire :" . $DEN ."Pret :".$PRT . " </a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Te rog scrie codul de tesatura</p>";}
?>
答案 0 :(得分:1)
您需要修复反引号并引用查询。你有 -
$sql=`SELECT * FROM PRICES WHERE TES LIKE "%" . $TES . "%" `;
应该是 -
$sql="SELECT * FROM PRICES WHERE TES LIKE '%" . $TES . "%' ";
您只需要在运行查询时检查一次查询错误,请更改此项 -
while($row=mysqli_fetch_array($result) or die(mysqli_error())){
到此 -
while($row=mysqli_fetch_array($result)){