Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi all

i am not able to get control into the register-inserting.php from the below script.
pls guide me whats wrong in it?.

When i click on the button, the alert "All not empty is working".

HTML
<script type="text/javascript" >
    $(document).ready (function() {
    $("#btnSubmit").click(function(e) {
    var username = $("#username").val();
    var email = $("#email").val();
    var password = $("#password").val();
    var firstname = $("#firstname").val();
    var lastname = $("#lastname").val();
    var subscribe = $("#subscribe").val();
    var terms = $("#terms").val();
     alert(username);
    var dataString = 'username='+ username + '&email=' + username + '&password=' + password + '&firstname=' + firstname + '&lastname=' + lastname + '&subscribe=' + subscribe + '&terms=' + terms;
    alert(dataString);

    if(username=='' || email=='' || password=='' || firstname=='' || lastname=='' || subscribe=='' || terms=='')
    {
        $('.message').fadeOut(200).hide();
        $('.error').fadeOut(200).show();
    alert("all empty");

    }
    else
    {
    alert("all not empty");
        e.preventDefault();
        $.ajax(
        {
        url: "register-inserting.php",
        data: dataString,
        cache: false,
        type: "POST",
        success: function()
            {
            $('.message').fadeIn(200).show();
            $('.error').fadeOut(200).hide();
            }
        });
        e.preventDefault();
    }
    return false;
    });
    });
    </script>


thanks
jim
Posted
Comments
Suvendu Shekhar Giri 6-Dec-15 9:06am
   
Try to read your question yourself. Isn't it very confusing?
"All not empty is working" means what?
Is it "all not empty" is working?
or "all not empty" is not working? or what else?
jim1972 6-Dec-15 9:13am
   
ys pls, its a typo.
"All not empty" working.

1 solution

Do you wan't to make ajax request when u're field is not empty?
If is this, check your data string,
it isn't the valid format for transmit data on jquery,
make data like this:

data:{key1 : value1, key2: value2}

take a look at:
https://api.jquery.com/jQuery.ajax/

you'll see data is a JSON object, and if it a string, make it at the same format (not GET param)

var dataString = "{var1 : "+ value1 + ", var2:"+value2+"}";

And normally u will show ur $(".message).fadein().show()

take a llok for this and answer me
   
Comments
jim1972 6-Dec-15 10:08am
   
i changed the dataString as below.
var dataString='{username:"jim1972",email:"sdfasd@gmail.com",password:"aaa",firstname:"jim",lastname:"john",subscribe:"2",terms:"3"}'

even, the success message is displayed.
How can i check using some breakpoint in my inserting page?

this is my pho inserting page.

alert("reached at configure!");</script>';
$sql="Select Count(*) from users where username='" . $user . "'" ;
$query=sqlsrv_fetch_array(sqlsrv_query(CN,$sql));
if ($query=== false){ exit("<pre>".print_r(sqlsrv_errors(), true));}

if ($query[0]==0) /*here, $query[0]) returns the number of rows*/
{
$datetime_variable = new DateTime();
$requestedDate = date_format($datetime_variable, 'Y-m-d H:i:s');
$createdDate=CURRENT_TIMESTAMP;
$gender=3;

$sql="Insert Into Users(UserName,Email,Pwd,FirstName,LastName,Gender,RequestActivationOn,ReceiveNews,CreatedOn)
Values('$username','$email','$password','$firstname','$lastname',
'$gender','$requestedDate','$subscribe','$createdDate')";
$query=sqlsrv_query(CN,$sql);
if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}
}
}
?>

thanks
Member 10269884 7-Dec-15 0:21am
   
sorry, i don't understand what you want to do?!!
when i look a ur code, u want to insert ur form data in a sql database right?
but u want some "checkpoints" for connection/statement/validation?
when if do an AJAX call, u might be to return some data, right? (if an error, if config not load,etc ???)

then, when u call some server function and validate it with js, maybe u resend data from server to client?
something like
{'statut': 200, 'message': "success", 'dataToResend': {//all the data u want}}

but u can't do any JSON array in php.
So u might encode a php array representating ur data and encode it to js...

take a look at:

https://jonsuh.com/blog/jquery-ajax-call-to-php-script-with-json-return/
http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php
http://forums.phpfreaks.com/topic/224278-jquery-ajax-success-return-variable/
http://stackoverflow.com/questions/8823925/how-to-return-an-array-from-an-ajax-call
http://www.php.net/manual/en/function.json-encode.php
http://www.php.net/manual/en/function.json-decode.php

if i answer u right, the next step is to format ur data in ur html passing by javascript.

might i help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900