Insert data through ajax into mysql database

后端 未结 6 1179
灰色年华
灰色年华 2020-11-30 06:33

Newsletter:

\">
6条回答
  •  借酒劲吻你
    2020-11-30 06:50

    The ajax is going to be a javascript snippet that passes information to a small php file that does what you want. So in your page, instead of all that php, you want a little javascript, preferable jquery:

    function fun()
    {
        $.get('\addEmail.php', {email : $(this).val()}, function(data) {
            //here you would write the "you ve been successfully subscribed" div
        });
    }
    

    also you input would have to be:

    
    

    last the file addEmail.php should look something like:

    mysql_connect("localhost","root","");
    mysql_select_db("eciticket_db");
    
    error_reporting(E_ALL && ~E_NOTICE);
    
    $email=mysql_real_escape_string($_GET['email']);
    $sql="INSERT INTO newsletter_email(email) VALUES ('$email')";
    $result=mysql_query($sql);
    if($result){
    echo "You have been successfully subscribed.";
    }
     if(!$sql)
    die(mysql_error());
    
    mysql_close();
    

    Also sergey is right, you should use mysqli. That's not everything, but enough to get you started.

提交回复
热议问题