2016-10-14 9 views
0

ここでは、php.netとmysql.comを検索しました。私は何が間違っているのか分かりません。誰も私のコードでエラーを見ることができますか?PHP mysql複数の条件を持つすべての行

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home4/vernsouthern/public_html/testsites/winenotes/main.php on line 47

<!DOCTYPE html> 
<html> 
<body> 
<?php 
$servername = "localhost"; 
$username = "myusername"; 
$password = "mypassword"; 
$dbname = "mydatabase"; 
// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 
if(!isset($_POST['country_type']) || 
    !isset($_POST['region_type']) || 
    !isset($_POST['wine_type']) || 
    !isset($_POST['vintage_type'])) { 
    died('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>'); 
} 
$country_type = $_POST['country_type']; 
$region_type = $_POST['region_type']; 
$wine_type = $_POST['wine_type']; 
$vintage_type = $_POST['vintage_type']; 
$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type; 
$result = $conn->query($sql); 
if ($result->num_rows > 0) { 
    // output data of each selected row 
    while($row = $result->fetch_assoc()) { 
     $wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']); 
     $note = iconv('ASCII', 'UTF-8//IGNORE', $row['Note']); 
     echo "<br> id: ". $row['id']. " - Wine: " . $wine . "<br>Note: " . $note . "<br>"; 
    } 
} else { 
    echo "0 results"; 
} 
$conn->close(); 
?> 
</body> 
</html> 

これは最初のエラーです:

$wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']); 
+2

問題は、問題のハイライト表示の色から明らかです。 – Barmar

答えて

0

あなたはセミコロンの前に二重引用符( ")を追加するのを忘れ(;)ここに:ここにある

$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type; 

完全な固定コード:

<!DOCTYPE html> 
<html> 
<body> 
<?php 
$servername = "localhost"; 
$username = "myusername"; 
$password = "mypassword"; 
$dbname = "mydatabase"; 
// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 
if(!isset($_POST['country_type']) || 
    !isset($_POST['region_type']) || 
    !isset($_POST['wine_type']) || 
    !isset($_POST['vintage_type'])) { 
    die('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>'); 
} 
$country_type = $_POST['country_type']; 
$region_type = $_POST['region_type']; 
$wine_type = $_POST['wine_type']; 
$vintage_type = $_POST['vintage_type']; 
$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type"; 
$result = $conn->query($sql); 
if ($result->num_rows > 0) { 
    // output data of each selected row 
    while($row = $result->fetch_assoc()) { 
     $wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']); 
     $note = iconv('ASCII', 'UTF-8//IGNORE', $row['Note']); 
     echo "<br> id: ". $row['id']. " - Wine: " . $wine . "<br>Note: " . $note . "<br>"; 
    } 
} else { 
    echo "0 results"; 
} 
$conn->close(); 
?> 
</body> 
</html> 

EDIT

編集で修正されたコードで見つかった別のタイプミス、。

died('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>'); 

は次のようになります。

die('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>'); 
+0

はい私は今それをeeします。私はまた別の間違いを見つけた。 –

+0

が死亡しました( '

申し訳ありませんが、送信したフォームに問題があるようです。)

'); 死んでいるはずです( –

+0

)あなたは正しいです!答えを更新しています。 –

関連する問題