Ajax adding content to a database

Source: Internet
Author: User

$("#add"). Click (function(){    varcode=$ ("#code").Val (); //val must be bracketed after varname=$ ("#name").Val (); $.Ajax ({URL: "Ajax_tianjiachu.php",Data: {C:code,n:name},type: "POST",//Submit methodDataType: "TEXT",//return string, T uppercaseSuccessfunction(data) {if(Data.Trim() = = "OK")//data.trim to remove the space to prevent error alert ("Add Success"); ElseAlert ("Add Failed");        }        }); })</script>
1<?PHP2 $code=$_post["C"];3 $name=$_post["N"];4 require"DBDA.class.php";5 $db=NewDbda ();6 $sql= "INSERT into nation values (' {$code}‘,‘{$name}‘)";//add quotation marks, plus brackets7 if($db->query ($sql, 0) //0 is added and deleted, 1 is add8 {9     Echo"OK";Ten     } One Else A{Echo"NO"; -}

Ajax adding content to a database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.