Excuse me: PHP JS implementation of complex button function

Source: Internet
Author: User
Ask: PHP JS to implement complex button functions
Ask you prawns: I want to make a page with a button, click this button to achieve the following several functions:

First determine if the name given on the page already exists in the SQL database. If it exists, give it a box and jump out. If it doesn't exist, save the content on the page (such as name, gender, Email, phone, etc.) into the SQL database, and then prompt to write to the database and jump to another page.

The buttons I defined are as follows (a.php file):



Then plan to implement the function of the button in the A.js file Data_send (), and now give the prompt box and jump page I know how to implement, but how to determine whether to write to the database, and how to write the database in JS, I am not sure.

I am a newcomer to the first, but also hope that you have a lot of advice, thank you for your help!


------Solution--------------------
Ajax detection and storage, and then jump
------Solution--------------------
Using AJAX to request PHP, PHP to check whether the name exists.
------Solution--------------------
I have also been researching and sharing the following:
The file 1, (conn.php) code is as follows:
$conn = mysql_connect (' localhost ', ' Database user name ', ' Database Password ');
mysql_select_db (' database name ', $conn);
?>

The file 2, (a.html) code is as follows:



The file 3, (a.php) code is as follows:

Include "conn.php";
$sql = ' SELECT * from user ';//user for your database name, modify it Yourself
$res = mysql_query ($sql);
while ($row =mysql_fetch_assoc ($res)) {
$u _name[]= $row [' name '];//$row [' name '] inside the name of your database field name

}
$name = $_get[' n '];
if (In_array ($name, $u _name)) {
echo "This username has been registered Please enter a new username!" ";
}else{
echo "can be used";
  • 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.