Hidden TextBox Value

JavaScript related questions should go here.
Post Reply
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Hidden TextBox Value

Post by ashwood »

ive done this:
<input type='hidden' name='username' value='<?php echo $_SESSION['login_username']; ?>' />
and then my php
<?php

    mysql_connect("*****************,"*****************","**********************");
mysql_select_db("*********);

    $username = $_POST['username'];
    $message = mysql_real_escape_string($_POST['lname']);
  
    mysql_query("INSERT INTO shoutbox VALUES ('$username','$message')") or die("Problem");

?>
it goes into the database BUT the username in the database.. where in the column it should say ashwood as the username is says undefined but the message shows the message..

whats the problem? thanks
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Hidden TextBox Value

Post by jacek »

"undefined" is what javascript uses for undefined variables, are you submitting the form via AJAX ?
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

yeah its todo with the topic i have in javascript section but thats complete now it works just this bit.. should i post the ajax?

edit:
$(document).ready(function(){
    $("form#submit").submit(function() {
    var username     = $('#username').attr('value');
    var lname     = $('#lname').attr('value');
        $.ajax({  
            type: "POST",  
            url: "sbox_data.php",
            data: "username="+ username +"& lname="+ lname,
            success: function() {
                $('#lname').val('');
            }
        });  
    return false;  
    });  
});
alls ive done is changed fname to username :S?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Hidden TextBox Value

Post by jacek »

ashwood wrote:should i post the ajax?
Post the full code ;)
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

full code? all different docs dude what do u need?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Hidden TextBox Value

Post by jacek »

Does your input have the id of "username" ?
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

nope only name should ill add id and report back :)
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Hidden TextBox Value

Post by jacek »

Okay :)
data: "username="+ username +"& lname="+ lname,
also should this be
data: "username="+ username +"&lname="+ lname,
with no space.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

well what do you no them 2 little letters made a differnece sorted :)
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Hidden TextBox Value

Post by jacek »

ashwood wrote:well what do you no them 2 little letters made a differnece sorted :)
good news :)

And moved to javascript :)
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

how would i add say displayname onto the data?
I would put a signature.. BUT, i don't have the time.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Hidden TextBox Value

Post by ashwood »

DONE IT :)
I would put a signature.. BUT, i don't have the time.
Post Reply