dopod0901 2016-08-27 13:49
浏览 71

检查数据库中是否存在电子邮件地址并发送消息

Im trying to check if the email exist in the ddbb, so my code is:

<?php
include 'connection.php';
$email=addslashes ($_POST['cEmail']);
$sqlEmail = "select cEmail from Client where cEmail = '$email'";
$exist = mysql_fetch_row($sqlEmail); 

if (isset($_POST['submit']))
    {
        if($exist == false){
            $name = addslashes ($_POST['cName']);   
            $surname=addslashes ($_POST['cSurname']);
            $email=addslashes ($_POST['cEmail']);
            $phone=addslashes ($_POST['cPhone']);
            $otherPhone=addslashes($_POST['cOtherPhone']);
            $languages=implode(' | ', $_POST['cLanguages']);
            $address=addslashes ($_POST['cAddress']);
            $neighborhood=addslashes ($_POST['cNeighborhood']);
            $pswd=addslashes($_POST['cPswd']);
            $service= addslashes ($_POST['cService']);

            $sql = "INSERT INTO Client(cName, cSurname, cEmail, cPhone, cOtherPhone, cLanguages, cAddress, cNeighborhood, cPswd, cService) 
                VALUES ('$name', '$surname', '$email', $phone, $otherPhone, '$languages', '$address', '$neighborhood', '$pswd', '$service')";

            if ($conn->query($sql) === TRUE) {
                echo "New record created successfully";
            }
        }else{
            echo "the email exists";
        }
    }

?>

So the problem becomes when the email address exist in the database, is not giving any message. Any ideas?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongzhi4690 2016-08-27 14:29
    关注

    Hi @AlguienEnEsteMundo,

    Your code is incorrect so it is generating warning "mysql_fetch_row() expects parameter 1 to be resource, string given"(please check your php ini setting to display the warning message). Following is the correct code, please update your code with:

    include 'connection.php';
    $email=addslashes ($_POST['cEmail']);
    $sqlEmail = "select cEmail from Client where cEmail = '$email'";
    $res = mysql_query($sqlEmail);
    $exist = mysql_fetch_row($res); 
    

    Hope this may fix your issue...

    评论

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导