How to login and signup using ajax in php

hi Good Morning FRIENDS…
Can anyone tell how to create login and signup page with database using AJAX in php…


This question is too general.
There are lots of tutorials on how to use AJAX with PHP. You can easily google it.
It would be waste of time trying to write yet another one here.
But we’ll try to help if you tell what have you already tried and what problem have you encountered.

I’ve done login page , i dont no how to create SIGNUP page…

So what is the exact problem?

Basically, there is not a big difference between login and signup pages.
Both of them is just forms where user types some data and then you do something with that data.
The only difference is that with login data you’re reading from database (searching for the user), but with signup data you’re storing it into the database (creating new user).

Its not storing in database…

Can anyone tell anything wrong in this code…
Plzzzz tell me…


require_once 'dbconfig.php';

if ($_POST) {
    $shopname = $_POST['shopname'];
    $ownername = $_POST['ownername'];
    $mobileno = $_POST['mobileno'];
    $address = $_POST('address');

    try {

            $stmt = $db_con->prepare("INSERT INTO tbl_users1(shopname,ownername,mobileno,address) VALUES(:shopname, :ownername, :mobileno, :address)");
            $stmt->bindParam(":shopname", $shopname);
            $stmt->bindParam(":ownername", $ownername);
            $stmt->bindParam(":mobileno", $mobileno);
            $stmt->bindParam(":address", $address);

            if ($stmt->execute()) {
                echo "registered";
            } else {
                echo "Query could not execute !";
    } catch (PDOException $e) {
        echo $e->getMessage();

$_POST is always defined. and it’s not a function.

This should be $address = $_POST['address'] as @Dormilich mentioned. And if ($_POST) will always return true. Try something like if (isset($_POST['shopname'])) if shopname is a required field to see if the values have been posted. (I am quite happy to accept a better suggestion from a php expert).

If you’re checking for whether a form has been submitted then the recommended check is

1 Like

Thank u all :slight_smile:

@WebMachine Just a small comment (a bit offtopic)

This is not true, $_POST is empty if you do not send a request and if ($_POST) can return false.
As @Dormilich said, it’s defined. This does not mean it is not empty.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.