Click here to Skip to main content
14,665,492 members
Rate this:
Please Sign up or sign in to vote.
See more:
i'm validating the user input data using jquery but i can't figure out how to save this data into my database after validation, is it posible.?
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Submit your data, open a database connection through your service and save the database.
   
Comments
careLess - Eric 14-Oct-13 2:13am
   
thanks, but how can i do that? this is my current code in jquery..


$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );

bValid = bValid && checkLength( username, "username", 3, 16 );
bValid = bValid && checkLength (password, "password", 3, 100);
bValid = bValid && checkLength( accesslvl, "accesslvl", 1, 5 );

bValid = bValid && checkRegexp( username, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
bValid = bValid && checkRegexp( username, /^[a-z]([A-Z])+$/i, "Access Level must be consist of letters only." );

if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + username.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"<td>" + accesslvl.val() + "</td>" +

"</tr>" );

$.ajax({
type: 'POST',
cache: false,
contentType: "application/json; charset=utf-8",
url: 'functions.php/f1',
data: "{'var1':'" + document.getElementById('username').value + "', 'var2':'" + document.getElementById('password').value + "', 'var3':'" + document.getElementById('accesslvl').value + "'}",
async: false,
success: function (response) {
$('#username').val('');
$('#password').val('');
$('#accesslvl').val('');
alert("Record Has been Saved in Database");
},
error: function ()
{ console.log('there is some error'); }
});

$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});

this is my code in functions.php:

Abhinav S 14-Oct-13 2:45am
   
You are using PHP, so you will open a connection in the PHP script.
http://php.net/manual/en/function.mysql-connect.php is an example using PHP with mySQL.
careLess - Eric 14-Oct-13 8:44am
   
yah of course i open a mysql connection and selecting dbase just dont know how can i pass this validated data through my functions.php: for me to insert.

can you help me with this part of jquery:

$.ajax({
type: 'POST',
cache: false,
contentType: "application/json; charset=utf-8",
url: 'functions.php/f1',
data: "{'var1':'" + document.getElementById('username').value + "', 'var2':'" + document.getElementById('password').value + "', 'var3':'" + document.getElementById('accesslvl').value + "'}",
async: false,
success: function (response) {
$('#username').val('');
$('#password').val('');
$('#accesslvl').val('');
alert("Record Has been Saved in Database"); },

error: function ()
{ console.log('there is some error'); } });
Abhinav S 14-Oct-13 12:14pm
   
Use a form instead of directly passing data.
Form.Submit should help you.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100