2013-10-23 61 views
0

我想通過檢查他的電子郵件是否已經存在於我的'賣家'表上來檢查用戶是否已經在那裏。如果存在,我想跳過插入新記錄,否則插入新的賣家。代碼如下:mysql_num_rows()期望參數1是資源,對象

$email = $_REQUEST['semail']; 
$sql = 'SELECT Email FROM project2.sellers WHERE Email = :email'; 
$s = $pdo->prepare($sql); 
$s->bindValue(':email', $email); 
$s->execute(); 
if (!$s) { 

} 
if (mysql_num_rows($s)!=0) { 
    echo "exists"; 
} 
else 
{ 
$sql = 'INSERT INTO project2.sellers SET 
     Type = :stype; 
     Name = :sname; 
     Email = :semail; 
     Phone = :sphone; 
     Location = :location; 
     City = :city'; 
$s = $pdo->prepare($sql); 
$s->bindValue(':stype', $_REQUEST['stype']); 
$s->bindValue(':sname', $_REQUEST['sname']); 
$s->bindValue(':semail', $_REQUEST['semail']); 
$s->bindValue(':sphone', $_REQUEST['sphone']); 
$s->bindValue(':location', $_REQUEST['location']); 
$s->bindValue(':city', $_REQUEST['city']); 
$s->execute(); 
} 
header('location: ../'.$_REQUEST['category']); 

請告訴我,我要去哪裏錯了

+1

'接入到.. SET'真的嗎?我認爲這不是標準,但可以使用程序 –

回答

2

您應該使用$s->rowCount();mysql_num_rows();

瞭解更多關於在這裏:​​http://php.net/manual/en/pdostatement.rowcount.php

而作爲基督教上面評論說,你的MySQL語法看起來很時髦。
看起來應該更像是這樣的:

INSERT INTO table_name (column1, column2, column3,...) 
VALUES (value1, value2, value3,...) 
+0

$ s = $ pdo-> prepare(「INSERT INTO products(adDate,Category,Subcat,Title,Description,Photo,Price,sellerEmail) VALUES(CURDATE() (':category',$ _REQUEST ['category']); $ s-> bindParam(':':');} (':title',$ _REQUEST ['title']); $ s-> bindParam(':description',$ _REQUEST ['desc',$ _REQUEST ['subcat']); $ s-> bindParam ']); $ s-> bindParam(':file',$ _FILES [「file'] [」name「]); $ s-> bindParam(':price',$ _REQUEST ['price']) ; $ s-> bindParam(':semail',$ _REQUEST ['semail']); $ s-> execute(); –

+0

當我按照喲u,它在最後一行給我一個錯誤,例如$ s-> execute();它表示語法錯誤或訪問衝突:1064 –

+0

您錯過了語句的VALUES()部分的右括號。 –

相關問題