Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts

    PHP: Get input box value

    Hi I am trying to see if a username is already taken in my table.

    The following code calls the Java function when the user clicks out of the textbox.. It works great but I have to manually enter a username where it says 'HERE!?'

    I would like it to use the value of the textbox 'text'.

    How would I go about doing this?

    <script type="text/javascript">
    function test(){
    include 'config.inc';
    $dbunames = mysql_query("SELECT * FROM users WHERE username='HERE!?'");
    if(mysql_num_rows($dbunames) > 0 ) {
    echo "Already taken";
    echo "available!";
    <input name="text" onchange="test(); return false;" id="text" length="20">
    <input name="text2" id="text2">
    <span id="php_code"> </span>

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Behind the Wall
    Thanked 369 Times in 365 Posts
    completely wrong approach. PHP is executed on the server before the HTML/JS is displayed in the browser.

    hence you cannot mix JS and PHP like that.

    what you can do is ask a PHP script via AJAX, whether a certain username exists. and of course the DB table needs to be unique on the username field.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts