私はプログラミングの初心者です。私はPHPを学んでいます。私がやろうとしているのは、私のプロジェクト用にPHPで検索スクリプトを書くことです。私は、MySQLデータベースを検索しようとすると、それは私にエラーを与える:PHP検索コードが結果の結果を出力しない
Notice: Undefined variable: output in C:\xampp\htdocs\search.php on line 2
私は、スクリプト上のすべてをチェックして、問題を参照してください傾けます。私はそれを間違ってコード化している?
私の質問に関連するフォーラムで考えられるすべての質問をチェックしたが、私には必要な答えが表示されないようだ。助けてください。
これは、入力とHTMLスクリプトです:
<form action="search.php" method="post" id="search">
<div id="searchfield_div">
<input name="search" id="searchfield" type="text" placeholder="What you looking for?">
<input id="delete_search_button" name="delete button" type="button" value="X">
<input id="search_button" name="search button" type="submit" value="Search">
</div>
</form>
と、これは私のPHPスクリプトです:
<?php
//connection script
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "liquihub";
$output = '';
@mysqli_connect("$db_host","$db_user","$db_pass","$db_name") or die("could not connect");
//collection script
if (isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","", $searchq);
$query = mysql_query("SELECT * FROM beverage_db WHERE name LIKE '%$searchq%' OR price LIKE '%$searchq%' OR type LIKE '%$searchq%'") or die ("could not search");
$count = mysql_num_rows($query);
if ($count == 0) {
$output = 'We not stocking this particular item at present';
}else{
while($row = mysql_fetch_array($query)) {
$bevname = $row['name'];
$bevprice = $row['price'];
$bevtype = $row['type'];
$bevid = $row['id'];
$output .= '<div>'.$bevname.' '.$bevprice.' '.$bevtype.'</div>';
}
}
}
?>
別のページに結果を置くためのものだ出力スクリプト:
<?php print("$output");?>
'mysqli_'と' mysql_'関数を混在させることはできません。あなたは 'mysqli_'をつけるべきです – tkausl
私はmysqli_にそれらをすべて変更しましたが、それでも同じ問題です – user2938948
[PHP:" Notice:Undefined variable "と" Notice:Undefined index "](http://stackoverflow.com)の可能な複製。/question/4261133/php-notice-undefined-variable-and-notice-undefined-index) – matiaslauriti