我对php和mysql还不熟悉,我正在尝试使用这些代码来学习这些语言。
我有这个密码:
<?php
class Cerca extends dbh{
public function cercaArt(){
$dbh = new dbh;
$dbh->connect();
if(isset($_POST['barcode']) || isset($_POST['codice']) || isset($_POST['descrizione'])){
$barcode = $_POST['barcode'];
$codice = $_POST['codice'];
$descrizione = $_POST['descrizione'];
$sql = "SELECT * FROM articoli WHERE barcode = ? REGEXP \"^[$barcode]\" OR codice = ? REGEXP \"^[$codice]\" OR descrizione = ? REGEXP \"^[$descrizione]\" ";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$barcode, $codice, $descrizione]);
if($stmt->rowCount()>0){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "<tr>
<td>". $row['codice'] ."</td>
<td>". $row['descrizione'] ."</td>
<td>". $row['prezzoA'] ."</td>
<td>". $row['prezzoV'] ."</td>
<td>". $row['quantita'] ."</td>
<td>". $row['barcode'] ."</td>
<td>". $row['esaurimento'] ."</td>
<td>". $row['categoria'] ."</td>
</tr>
";
}
}
} else{
echo 'Immissione non valida!';
}
}
}
?>
这是脚本的格式代码:
<?php
include 'includes/header.php';
session_start();
include 'includes/sidebar.php';
include 'includes/dbh.php';
include 'includes/cerca-articolo.php';
?>
<!-- Header -->
<header class="w3-container" style="padding-top:22px">
<h4><b><i class="fa fa-dashboard"></i> Anagrafica articoli</b></h4>
</header>
<!-- CONTENT! -->
<!-- FIRST ROW -->
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-container w3-third">
<form class="w3-container" action="anagrafica-articoli.php" method="post">
<label class="w3-text-blue"><b>Barcode:</b></label>
<input class="w3-input w3-border" name="barcode" type="text">
<br>
<label class="w3-text-blue"><b>Codice articolo:</b></label>
<input class="w3-input w3-border" name="codice" type="text">
<br>
<label class="w3-text-blue"><b>Descrizione:</b></label>
<input class="w3-input w3-border" name="descrizione" type="text">
<br>
<button class="w3-btn w3-blue" type="submit" value="submit">Cerca</button>
</form>
</div>
</div>
<div class="w3-container">
<table class="w3-table w3-striped">
<tr>
<th>Codice</th>
<th>Descrizione</th>
<th>Prezzo Acquisto</th>
<th>Prezzo Vendita</th>
<th>Quantità</th>
<th>Barcode</th>
<th>Esaurimento</th>
<th>Categoria</th>
</tr>
<?php
$search = new Cerca;
$search->cercaArt();
?>
</table>
</div>
<?php
include 'includes/footer.php';
?>
当我运行它时,会出现以下错误:
致命错误:未捕获的pdoexception:sqlstate[42000]:语法错误或访问冲突:1139从c:\xampp\htdocs\bk\includes\cerca articolo中的regexp中的“偏移量3”处获取字符类的错误“missing terminating]。php:16 stack 跟踪:#0 c:\xampp\htdocs\bk\includes\cerca articolo.php(16):pdostatement->execute(array)#1c:\xampp\htdocs\bk\anagrafica articoli.php(49):cerca->cercaart()#2{main}在第16行的c:\xampp\htdocs\bk\includes\cerca-articolo.php中抛出
此查询用于搜索字段。这在没有regexp的情况下可以工作,但是如果我搜索的描述或条形码不完整,它不会显示数据。
如果描述为“nike air shows yellow”,并且我搜索“nike”,则不会在表中显示数据字段。对于数据,我必须搜索“耐克空气显示黄色”完全字符串。
所以我想尝试添加一个regexp来获取数据,例如,如果我只搜索描述中的一个单词,或者只搜索一段条形码来显示所有文章中都有这段条形码,但是我得到了那个错误。
暂无答案!
目前还没有任何答案,快来回答吧!