开发者

MySQL Query is not processing whereas PHP Email code is?

开发者 https://www.devze.com 2023-03-21 00:59 出处:网络
I have a form s开发者_高级运维etup in html php and javascript. I set the form to run a process() function upon the click of the submit button. In this process function, I send myself an email and inse

I have a form s开发者_高级运维etup in html php and javascript. I set the form to run a process() function upon the click of the submit button. In this process function, I send myself an email and insert the data from the form into a mysql query and sendout that query.

However the email code works, and I receive an email, but the query code doesn't and therefore I receive no new rows in my database. I also receive no mysql_error() output either.

Please can you tell me where I am going wrong?

function process()
    {
        mysql_connect("localhost", "username", "password");
        mysql_select_db("db");
        $device = mysql_real_escape_string($_POST['Device_Type']);
        $name = mysql_real_escape_string($_POST['Name']);
        $job = mysql_real_escape_string($_POST['DD']);
        $username = mysql_real_escape_string($_POST['Username']);
        $email = mysql_real_escape_string($_POST['Email']);
        $website = mysql_real_escape_string($_POST['Website']);
        $UDID = mysql_real_escape_string($_POST['UDID']);
        mysql_query("INSERT INTO Beta_Testers (`Name`, `Username`, `Email Address`, `Website`, `Job`, `Device_Type`, `UDID`) VALUES ('$name','$username','$email','$website','$job','$device','$UDID'))") or die(mysql_error());  
          $msg = "Form Contents: \n\n";
          foreach($this->fields as $key => $field)
                $msg .= "$key :  $field \n";
          $to = 'beta@socialpic.org';
          $subject = 'Beta Form Submission';
         $from = 'Beta Sign up';
          mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
    }


Since mysql_query() is a boolean function in the context you're using it in, you can do the following:

function process()
    {
        mysql_connect("localhost", "username", "password");
        mysql_select_db("db");
        $device = mysql_real_escape_string($_POST['Device_Type']);
        $name = mysql_real_escape_string($_POST['Name']);
        $job = mysql_real_escape_string($_POST['DD']);
        $username = mysql_real_escape_string($_POST['Username']);
        $email = mysql_real_escape_string($_POST['Email']);
        $website = mysql_real_escape_string($_POST['Website']);
        $UDID = mysql_real_escape_string($_POST['UDID']);
        $query = "INSERT INTO Beta_Testers (`Name`, `Username`, `Email Address`, `Website`, `Job`, `Device_Type`, `UDID`) VALUES ('$name','$username','$email','$website','$job','$device','$UDID'))";
        if (mysql_query($query)) {
            $msg = "Form Contents: \n\n";
            foreach($this->fields as $key => $field)
                $msg .= "$key :  $field \n";
            $to = 'beta@socialpic.org';
            $subject = 'Beta Form Submission';
            $from = 'Beta Sign up';
            mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
        } else {
            echo $query;
        }
    }

But looking your code, is your email address column called "Email Address" or "Email_Address"?

0

精彩评论

暂无评论...
验证码 换一张
取 消