herghost Posted March 15, 2009 Share Posted March 15, 2009 Hi all, I am wondering if someone could help me out with some PHP code. I have a form that is meant to check if a username is available using ajax and this file: The username '<?php echo $_POST["username"]; ?>' <strong>is <?php if($_POST["username"] == "admin") { ?> not <?php } ?> </strong> available. This works fine, however instead of having to manaully update this list everytime someone registers I want it to check my php database. This is where my noobness comes into play! So far I have this: The username '<?php echo $_POST["username"]; ?>' <strong>is <?php $query = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$query) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die('Unable to select database: ' . mysql_error()); } ?> not <?php } ?> </strong> available. Which just connects to the database! I know that I am going to need to pull the values from the table, all the members names are in a coloum called members and then loop through them checking each one, I just dont know where to start Link to comment https://forums.phpfreaks.com/topic/149540-php-username-checking-help-request/ Share on other sites More sharing options...
Mikedean Posted March 15, 2009 Share Posted March 15, 2009 Just query the user name. $sql = mysql_query( "SELECT members FROM table WHERE members='" . $_POST["username"] . "'", $query ); if( mysql_num_rows( $sql ) > 0 ) echo "not"; That should do the job. I would also think about putting some SQL injection prevention in place. Link to comment https://forums.phpfreaks.com/topic/149540-php-username-checking-help-request/#findComment-785318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.