2017-07-03 91 views
1

我陷入了一個小錯誤,我試圖從mysql獲取值。從mysql數組獲取值並從字段中匹配

數組和匹配字段的值,但我得到一個錯誤。

能否請你檢查我的代碼:

<?php 

if(isset($_POST['newsletter'])){ 
$email=$_POST['email']; 
$check=mysql_query("select email from newsletter"); 
while($row=mysql_fetch_array($query)) 
{ 
    if($row['email'])==$email){ 
    echo "<script> alert('You are already Subscribed');</script>"; 
} else { 
$sql_news=mysql_query("insert into newsletter(email) values('$email')"); 
    echo "<script> alert('You are successfully Subscribed');</script>"; 
}}} ?> 

在此先感謝!

+0

那是什麼')'如果($行後'在那裏做什麼[ '電子郵件' ] ...''? –

+0

不要使用'mysql_ *'函數,它們從PHP 5.5開始不推薦使用,並且在PHP 7.0中完全刪除。使用['mysqli'](http://php.net/manual/en /book.mysqli.php)或['pdo'](http://php.net/manual/en/book.pdo.php)。[**這就是爲什麼你不應該使用'mysql_ *'功能**](https://stackoverflow.com/questions/128599 42 /爲什麼-不應該-I-使用MySQL的函數式的PHP)。 –

+0

改用PDO。 –

回答

1

更新這一行,因爲你使用$校驗值,以便在MySQL中獲取使用此

while($row=mysql_fetch_array($query)) 

while($row=mysql_fetch_array($check)) 
+0

ops !!那是愚蠢的高度! –

+0

它好,繼續 –

相關問題