Hello, I have a function to insert a new user into the database and it returns an empty data from the page I use to post it with."Undefined" actually... Here is the code:

//insert new user into database

 $("#insert_new_btn").live('click', function(){
     var user_username = $("#insert_new_user").val;
     $.ajax({
     type: "POST",   
     url:"insert_nw_usr_script.php",
     data:{insert_new_usr:user_username},
     success:function(insert_a_user)
     {$('#inserted_user').html(insert_a_user).show();}
     });
     });

This is the the php page, I haven't written the mysql script yet.I'm just printing the user on the screen, but I'm getting an empty response

<?php
$insert_new_usr = $_REQUEST['insert_new_usr'];
echo $insert_new_usr;

?>

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

This is the the php page, I haven't written the mysql script yet.I'm just printing the user on the screen, but I'm getting an empty response

Why you are using $_REQUEST?

Where you in your PHP code that has a insert_new_usr?

Undefined in javascript means that you didn't define the variable.

In PHP it goes like this:

mitch is undefine in my PHP code

To define it

I have to do this:

$mitch = $_POST['mitch'];

that will make sure that it is available for my query or code to function.

Without it ... it won't and most likely it will be undefine until I define it.

Damn it I missed one letter in the input field's id insert_new_user was insert_new_usr.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.