我想通过检查他的电子邮件是否已经存在于桌面上来检查用户是否已经在我的'卖家'桌子上。如果它存在,我想跳过插入新记录,否则插入新卖家。代码如下:
$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']);
请告诉我哪里出错了
答案 0 :(得分:2)
您应该使用$s->rowCount();
而不是mysql_num_rows();
在此处详细了解:http://php.net/manual/en/pdostatement.rowcount.php
正如Christian上面所说,你的MySQL语法看起来很时髦 应该看起来像这样:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)