...

View Full Version : PHP: Get input box value



penny94
10-31-2012, 03:15 AM
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(){
document.getElementById("php_code").innerHTML="<?php


include 'config.inc';



$dbunames = mysql_query("SELECT * FROM users WHERE username='HERE!?'");

if(mysql_num_rows($dbunames) > 0 ) {
echo "Already taken";
}
else
{
echo "available!";
}


?>";
}

</script>


<input name="text" onchange="test(); return false;" id="text" length="20">
<input name="text2" id="text2">
<span id="php_code"> </span>




Thanks

Dormilich
10-31-2012, 08:49 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum