TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   username checker (http://www.talkphp.com/mysql-databases/4720-username-checker.html)

khile 07-11-2009 11:54 PM

username checker
 
hi pps im wanting to create a username checker where a user enter there name in say username field and that is checked against mysql database to see if it exist but is done instant like Ajax ive seen some out there but non seem to work right

any help would be great

adamdecaf 07-12-2009 05:15 PM

Well, once you grab the username you can do a simple mysql query.

PHP Code:

<?php
// connect
  
$connect mysql_connect("host""username""password");
  
$result mysql_query("SELECT * FROM ‘database‘.‘users‘ WHERE ‘user-id‘ = $submittedID");
  
// Then check if a row was returned.
if (mysql_num_rows($result) > 0) {
   echo 
"User(s) Found!";
} else {
   echo 
"Sorry, the user was not found.";
}
?>

Keep in mind this is an oversimplified chunk of code, but it should get you started.

Enfernikus 07-12-2009 05:52 PM

Don't use backticks, makes your query more portable. And while Adamn said it was oversimplified also keep in mind to try and not use the asterisk as it slows down the query

adamdecaf 07-12-2009 07:27 PM

Quote:

Originally Posted by Enfernikus (Post 26926)
Don't use backticks, makes your query more portable. And while Adamn said it was oversimplified also keep in mind to try and not use the asterisk as it slows down the query

Your correct, you could just grab the user-id field where it matches the input. It would be a faster solution but more knowledge of the subject area would be required.

Also, both of my PHP/MySQL Distributions require backticks, the query fails without them.

Enfernikus 07-12-2009 08:59 PM

Thats very odd, bad practice as well.

adamdecaf 07-12-2009 09:34 PM

Quote:

Originally Posted by Enfernikus (Post 26936)
Thats very odd, bad practice as well.

I know it's bad, but I haven't found a fix yet.

khile 07-13-2009 02:10 PM

ive tried the method mentioned above but keeps returning username not found even when it is say i enter admin is registration field it then checks database and should come back saying username unavailable but if i put say khile it should come back and say available as no one has registered with that name

khile 07-13-2009 02:40 PM

below is the textbox i want to include lookup in

PHP Code:

<label><strong><?php echo  $lang['Username'?></strong><br /><input type="text" class="textbox" name="req_username" size="40" maxlength="25" /><br /></label>


Hightower 07-13-2009 02:52 PM

Show us the query as well :-)

adamdecaf 07-13-2009 05:47 PM

Quote:

Originally Posted by khile (Post 26956)
ive tried the method mentioned above but keeps returning username not found even when it is say i enter admin is registration field it then checks database and should come back saying username unavailable but if i put say khile it should come back and say available as no one has registered with that name


below is the textbox i want to include lookup in

PHP Code:

<label><strong><?php echo  $lang['Username'?></strong><br /><input type="text" class="textbox" name="req_username" size="40" maxlength="25" /><br /></label>


Well, you need to get the HTTP responce before you query. Also you need to change the "host", "username", "password" to a database with populated tables.

PHP Code:

<?php
// You will need to format, and secure this code before the query.
   
$data $_POST['req_username'];

// Now use the code from above...

?>

Oh, don't forget to change the tables that the query looks at.

rguy84 07-14-2009 06:24 AM

Adam I am getting an error for your query (after I put in my info)

EDIT I take that back, sql issues on my end.

khile 07-14-2009 04:20 PM

could someone help me what im wanting to do is add username lookup to his forum for a friends forum i said yes ill do it but not sure how lol here code

PHP Code:

<?php
require dirname(__FILE__).'/../include/init.php';
if (!
$forum_user['is_guest'])
{
        
header('Location: index.php');
        exit;
}
$redirect_url = (isset($_SERVER['HTTP_REFERER'])) ? BB_Input::Htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';
if (
bb_regs_allow == '0'BB_Functions::Message($lang['No new regs']);
if (isset(
$_GET['cancel'])) BB_Functions::Redirect('index.php'$lang['Reg cancel redirect']);
else if (
bb_rules == '1' && !isset($_GET['agree']) && !isset($_POST['form_sent']))
{
        
$page_title BB_Input::Htmlspecialchars($lang['Register']);
        require 
FORUM_ROOT.$forum_folder.'/header.php';
?>
<div class="blockform">
        <h2><span><?php echo $lang['Forum rules'?></span></h2>
        <div class="box">
                <form method="get" action="register.php">
                        <div class="inform">
                                <h2><?php echo $lang['Rules legend'?></h2>
                                <div class="infldset file" style="padding:10px">
                                        <?php echo bb_rules_message ?></p>
                                </div>
                        </div>
                        <div><input type="submit" class="b1" name="agree" value="<?php echo $lang['Agree'?>" /><input class="b1" type="submit" name="cancel" value="<?php echo $lang['Cancel'?>" /></div>
                </form>
        </div>
</div>
<?php
        
require FORUM_ROOT.$forum_folder.'/footer.php';
}
else if (isset(
$_POST['form_sent']))
{
        
BB_Input::Confirm_Referrer('register.php');
        
$username BB_Input::Trim($_POST['req_username']);
        
$email1 strtolower(trim($_POST['req_email1']));
        if (
bb_regs_verify == '1')
        {
                
$email2 strtolower(trim($_POST['req_email2']));
                
$password1 BB_Input::Random_Pass(8);
                
$password2 $password1;
        }
        else
        {
                
$password1 trim($_POST['req_password1']);
                
$password2 trim($_POST['req_password2']);
        }
        
$username preg_replace('#\s+#s'' '$username);
        if (
strlen($username) < 2BB_Functions::Message($lang['Username too short']);
        else if (
BB_Input::Strlen($username) > 25BB_Functions::Message($lang['Bad request']);
        else if (
strlen($password1) < 4BB_Functions::Message($lang['Pass too short']);
        else if (
$password1 != $password2BB_Functions::Message($lang['Pass not match']);
        else if (!
strcasecmp($username'Guest') || !strcasecmp($username$lang['Guest'])) BB_Functions::Message($lang['Username guest']);
        else if (
preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/'$username)) BB_Functions::Message($lang['Username IP']);
        else if ((
strpos($username'[') !== false || strpos($username']') !== false) && strpos($username'\'') !== false && strpos($username'"') !== falseBB_Functions::Message($lang['Username reserved chars']);
        else if (
preg_match('#\[b\]|\[/b\]|\[u\]|\[/u\]|\[i\]|\[/i\]|\[color|\[/color\]|\[quote\]|\[quote=|\[/quote\]|\[code\]|\[/code\]|\[img\]|\[/img\]|\[url|\[/url\]|\[email|\[/email\]#i'$username)) BB_Functions::Message($lang['Username BBCode']);
        if (
bb_censoring == '1')
        {
                if (
BB_Input::Censor_Words($username) != $usernameBB_Functions::Message($lang['Username censor']);
        }
        if (
bb_regs_verify_image == '1')
        {
                
session_start();
                if (
trim($_POST['req_image']) == ''BB_Functions::Message($lang['Text mismatch']);
                if (
strtolower(trim($_POST['req_image'])) != strtolower($_SESSION['text'])) BB_Functions::Message($lang['Text mismatch']);
                
        }
        
$result $db->query('SELECT username FROM '.$db->prefix.'users WHERE UPPER(username)=UPPER(\''.$db->escape($username).'\') OR UPPER(username)=UPPER(\''.$db->escape(preg_replace('/[^\w]/'''$username)).'\')') or BB_Functions::Error($lang['error_29'], __FILE____LINE__$db->error());
        if (
$db->num_rows($result))
        {
                
$busy $db->result($result);
                
BB_Functions::Message($lang['Username dupe 1'].' '.BB_Input::Htmlspecialchars($busy).'. '.$lang['Username dupe 2']);
        }
        if (!
BB_Email::Is_Valid_Email($email1)) BB_Functions::Message($lang['Invalid e-mail']);
        else if (
bb_regs_verify == '1' && $email1 != $email2BB_Functions::Message($lang['E-mail not match']);
        if (
BB_Email::Is_Banned_Email($email1))
        {
                if (
bb_allow_banned_email == '0'BB_Functions::Message($lang['Banned e-mail']);
                
$banned_email true;
        }
        else 
$banned_email false;
        
$dupe_list = array();
        
$result $db->query('SELECT username FROM '.$db->prefix.'users WHERE email=\''.$db->escape($email1).'\'') or BB_Functions::Error($lang['error_29'], __FILE____LINE__$db->error());
        if (
$db->num_rows($result))
        {
                if (
bb_allow_dupe_email == '0'BB_Functions::Message($lang['Dupe e-mail']);
                while (
$cur_dupe $db->fetch_assoc($result)) $dupe_list[] = $cur_dupe['username'];
        }
      if (isset(
$_POST['language']))
      {
            
$language preg_replace('#[\.\\\/]#'''$_POST['language']);
            if (!
file_exists(FORUM_ROOT.'include/languages/'.$language.'/main.php')) BB_Functions::Message($lang_common['Bad request']);
      }
      else 
$language bb_default_lang;
        
$timezone intval($_POST['timezone']);
        
$save_pass = (!isset($_POST['save_pass']) || $_POST['save_pass'] != '1') ? '0' '1';
        
$email_setting intval($_POST['email_setting']);
        if (
$email_setting || $email_setting 2$email_setting 1;
        
$now time();
        
$initial_gid = (bb_regs_verify == '0') ? bb_default_user_group USER_UNVERIFIED;
        
$password_hash BB_Input::Hash($password1);
        
$result $db->query('SELECT 1 FROM '.$db->prefix.'users WHERE registration_ip=\''.$db->escape(BB_Input::Get_Remote_Address()).'\' AND registered>'.(time() - bb_timeout_flood)) or BB_Functions::Error($lang['error_29'], __FILE____LINE__$db->error());  
        if (
$db->num_rows($result)) BB_Functions::Message($lang['antiflood_msg']);
        
$db->query('INSERT INTO '.$db->prefix.'users (username, gid, password, email, email_setting, save_pass, timezone, language, template, registered, registration_ip, last_visit) VALUES(\''.$db->escape($username).'\', '.$db->escape($initial_gid).', \''.$db->escape($password_hash).'\', \''.$db->escape($email1).'\', '.$db->escape($email_setting).', '.$db->escape($save_pass).', '.$db->escape($timezone).' , \''.$db->escape($language).'\', \''.bb_default_style.'\', '.$now.', \''.BB_Input::Get_Remote_Address().'\', '.$now.')') or BB_Functions::Error($lang['error_29'], __FILE____LINE__$db->error());
        
$new_uid $db->insert_id();
        if (
$banned_email && bb_mailing_list != '')
        {
                
$mail_subject $lang['arlet'].' - '.$lang['banned_email_address'];
                
$mail_message $lang['user'].' \''.$username.'\' '.$lang['registered_with_banned_email'].': '.$email1."\n\n".$lang['user_profile'].': '.bb_forum_url.'/member.php?id='.$new_uid."\n\n".'-- '."\n".'Forum Mailer'."\n".'('.$lang['do_not_reply_to_this_message'].')';
                
BB_Email::Mail(bb_mailing_list$mail_subject$mail_message);
        }
        if (!empty(
$dupe_list) && bb_mailing_list != '')
        {
                
$mail_subject $lang['arlet'].' - '.$lang['duplicate_email_address'];
                
$mail_message $lang['user'].' \''.$username.'\' '.$lang['registered_with_duplicate_email'].': '.implode(', '$dupe_list)."\n\n".$lang['user_profile'].': '.bb_forum_url.'/member.php?id='.$new_uid."\n\n".'-- '."\n".'Forum Mailer'."\n".'('.$lang['do_not_reply_to_this_message'].')';
                
BB_Email::Mail(bb_mailing_list$mail_subject$mail_message);
        }
        if (
bb_regs_report == '1')
        {
                
$mail_subject $lang['arlet'].' - '.$lang['new_registration'];
                
$mail_message $lang['user'].' \''.$username.'\' '.$lang['registered_in_the_forums_at'].' '.bb_forum_url."\n\n".$lang['user_profile'].': '.bb_forum_url.'/member.php?id='.$new_uid."\n\n".'-- '."\n".'Forum Mailer'."\n".'('.$lang['do_not_reply_to_this_message'].')';
                
BB_Email::Mail(bb_mailing_list$mail_subject$mail_message);
        }
        if(isset(
$_COOKIE["aeon_referrer"]))
        {
                
$referral_id $_COOKIE["aeon_referrer"];
                
$result $db->query('SELECT referral_count FROM '.$db->prefix.'users WHERE id='.intval($referral_id)) or BB_Functions::Error($lang['error_86'], __FILE____LINE__$db->error());
                list(
$referral_val) = $db->fetch_row($result);
                
$rval $referral_val[0] + 1;
                
$db->query('UPDATE '.$db->prefix.'users SET referral_count='.$rval.' WHERE id='.intval($referral_id)) or BB_Functions::Error($lang['error_86'], __FILE____LINE__$db->error());
        }
        if (
bb_welcoming_post == '1' && bb_welcoming_post_msg != '' && bb_welcoming_post_poster != '' && bb_welcoming_post_title != '' && bb_welcoming_post_fid != '')
        {
                
// Post
                
$query $db->query('SELECT id FROM '.$db->prefix.'users WHERE username = \''.$db->escape(bb_welcoming_post_poster).'\' LIMIT 1');
                
$poster_id $db->result($query);
                
$post_message str_replace('<username>'$usernamebb_welcoming_post_msg);
                
$post_title str_replace('<username>'$usernamebb_welcoming_post_title);
                
$query $db->query('SELECT id FROM '.$db->prefix.'posts ORDER BY id DESC LIMIT 1');
                
$post_last_post_id $db->result($query);
                
$post_last_post_id++;
                
$db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_post_id, last_poster, forum_id) VALUES(\''.$db->escape(bb_welcoming_post_poster).'\', \''.$post_title.'\', \''.$now.'\', \''.$now.'\', \''.$post_last_post_id.'\', \''.$db->escape(bb_welcoming_post_poster).'\', '.bb_welcoming_post_fid.')') or BB_Functions::Error($lang['unable_insert_into_table'].' '.$db->prefix.'topics. '.$lang['check_config_and_try_again']);
                
$new_tid $db->insert_id();
                
$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES (\''.$db->escape(bb_welcoming_post_poster).'\', '.$poster_id.', \''.$db->escape(BB_Input::Get_Remote_Address()).'\', \''.$post_message.'\', '.$now.', '.$new_tid.')') or BB_Functions::Error($lang['unable_insert_into_table'].' '.$db->prefix.'posts. '.$lang['check_config_and_try_again']);
                
BB_Core::Update_Forum(bb_welcoming_post_fid);
                
BB_Core::Update_Topic($new_tid);
        }
        if (
bb_welcoming_pm == '1' && bb_welcoming_pm_sender != '' && bb_welcoming_pm_msg != '' && bb_welcoming_pm_title != '')
        {
                
// PM
                
$query $db->query('SELECT id FROM '.$db->prefix.'users WHERE username = \''.$db->escape(bb_welcoming_pm_sender).'\' LIMIT 1');
                
$pm_sender_id $db->result($query);
                
$pm_message str_replace('<username>'$usernamebb_welcoming_pm_msg);
                
$pm_title str_replace('<username>'$usernamebb_welcoming_pm_title);
                
$db->query('INSERT INTO '.$db->prefix.'messages (owner, subject, message, sender, sender_id, sender_ip, smileys, showed, status, posted) VALUES(\''.$new_uid.'\', \''.$pm_title.'\', \''.$pm_message.'\', \''.bb_welcoming_pm_sender.'\', \''.$pm_sender_id.'\', \''.$db->escape(BB_Input::Get_Remote_Address()).'\', \''.$db->escape($smilies).'\', \'0\', \'0\', \''.time().'\')') or BB_Functions::Error($lang['unable_to_send_message'], __FILE____LINE__$db->error());
        }
        if (
bb_regs_verify == '1')
        {
                
$mail_tpl trim(file_get_contents(FORUM_ROOT.'include/languages/'.$forum_user['language'].'/mail_templates/welcome.tpl'));
                
$first_crlf strpos($mail_tpl"\n");
                
$mail_subject trim(substr($mail_tpl8$first_crlf-8));
                
$mail_message trim(substr($mail_tpl$first_crlf));
                
$mail_subject str_replace('<board_title>'bb_board_title$mail_subject);
                
$mail_message str_replace('<base_url>'bb_forum_url$mail_message);
                
$mail_message str_replace('<username>'$username$mail_message);
                
$mail_message str_replace('<password>'$password1$mail_message);
                
$mail_message str_replace('<login_url>'bb_forum_url.'login.php'$mail_message);
                
$mail_message str_replace('<board_mailer>'bb_board_title.' '.$lang['Mailer'], $mail_message);
                
BB_Email::Mail($email1$mail_subject$mail_message);
                
BB_Functions::Message($lang['Reg e-mail'].' <a href="mailto:'.bb_admin_email.'">'.bb_admin_email.'</a>.'true);
        }
        
BB_Input::Set_Cookie($new_uid$password_hash, ($save_pass != '0') ? $now 31536000 0);
        
BB_Functions::Redirect(BB_Input::Htmlspecialchars($_POST['redirect_url']), $lang['Reg complete']);
}
$page_title BB_Input::Htmlspecialchars(bb_board_title).' :: '.$lang['Register'];
$required_fields = array('req_username' => $lang['Username'], 'req_password1' => $lang['Password'], 'req_password2' => $lang['Confirm pass'], 'req_email1' => $lang['E-mail'], 'req_email2' => $lang['E-mail'].' 2');
$focus_element = array('register''req_username');
require 
FORUM_ROOT.$forum_folder.'/header.php';
?>
<div class="blockform">
        <h2><span><?php echo $lang['Register'?></span></h2>
        <div class="box">
                <form id="register" method="post" action="register.php?action=register" onsubmit="this.register.disabled=true;if(process_form(this)){return true;}else{this.register.disabled=false;return false;}">
                        <div class="inform">
                                <div class="forminfo">
                                        <h3><?php echo $lang['Important information'?></h3>
                                        <p><?php echo $lang['Desc 1'?></p>
                                        <p><?php echo $lang['Desc 2'?></p>
                                </div>
                                <h2><?php echo  $lang['Username legend'?></h2>
                                <div class="infldset file" style="padding:10px">
                                        <input type="hidden" name="form_sent" value="1" />
                                        <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                                        <label><strong><?php echo  $lang['Username'?></strong><br /><input type="text" input id="username" class="textbox" name="req_username" onkeyup="timeoutUsernameCheck()" name="username" size="40" maxlength="25" /><br /></label>
<?php
if (bb_regs_verify == '0')
{
?>
                                        <label class="conl"><strong><?php echo $lang['Password'?></strong><br /><input class="textbox" type="password" id="password" name="req_password1" size="20" maxlength="16" /><br /></label>
                                        <label class="conl"><strong><?php echo $lang['Confirm pass'?></strong><br /><input class="textbox" type="password" id="password2" name="req_password2" size="20" maxlength="16" /></label>
                                        <p class="clearb"></p>
<?php
}
if (
bb_regs_verify_image == '1')
{
?>                        
                                        <img src="../include/functions/Captcha.php" alt="Image validation" /><br />
                                        <label class="conl"><strong><?php echo $lang['Image text'?></strong><br /><input class="textbox" type="text" name="req_image" size="22" maxlength="20" />&nbsp;&nbsp;<img src="<?php echo bb_forum_url ?>img/admin/tooltip.png" alt="tooltip" onmouseover="return xBB_Show_Tooltip('<?php echo $lang['Image info'?>');" onmouseout="return nd();" /></label>
                                        <p class="clearb"></p>
<?php
}
?>
                                        <label><strong><?php echo $lang['E-Mail'?></strong><br />
                                        <input type="text" class="textbox" name="req_email1" size="40" maxlength="50" /><br /></label>
<?php
if (bb_regs_verify == '1')
{
?>
                                        <label><strong><?php echo $lang['Confirm e-mail'?></strong><br />
                                        <input type="text" class="textbox" name="req_email2" size="40" maxlength="50" /><?php if (bb_regs_verify == '1'BB_Template::Print_Tooltip($lang['E-mail info']) ?></label>
<?php
}
?>
                                </div>
                        </div>
                        <div class="inform">
                                <h2><?php echo  $lang['Localisation legend'?></h2>
                                <div class="infldset file" style="padding:10px">
                                        <label><?php echo  $lang['Timezone info'?><br /><br /><?php echo  $lang['Timezone'?>: <select id="time_zone" name="timezone">
                                                <option value="-12"<?php if (bb_server_timezone == -12) echo ' selected="selected"' ?>>(GMT-12:00) International Date West</option>
                                                <option value="-11"<?php if (bb_server_timezone == -11) echo ' selected="selected"' ?>>(GMT-11:00) Midway Island, Samoa</option>
                                                <option value="-10"<?php if (bb_server_timezone == -10) echo ' selected="selected"' ?>>(GMT-10:00) Hawaii</option>
                                                <option value="-9"<?php if (bb_server_timezone == -9) echo ' selected="selected"' ?>>(GMT-09:00) Alaska</option>
                                                <option value="-8"<?php if (bb_server_timezone == -8) echo ' selected="selected"' ?>>(GMT-08:00) Pacific</option>
                                                <option value="-7"<?php if (bb_server_timezone == -7) echo ' selected="selected"' ?>>(GMT-07:00) Mountain</option>
                                                <option value="-6"<?php if (bb_server_timezone == -6) echo ' selected="selected"' ?>>(GMT-06:00) Central</option>
                                                <option value="-5"<?php if (bb_server_timezone == -5) echo ' selected="selected"' ?>>(GMT-05:00) Eastern</option>
                                                <option value="-4"<?php if (bb_server_timezone == -4) echo ' selected="selected"' ?>>(GMT-04:00) Atlantic</option>
                                                <option value="-3.5"<?php if (bb_server_timezone == -3.5) echo ' selected="selected"' ?>>(GMT-03:30) Newfoundland</option>
                                                <option value="-3"<?php if (bb_server_timezone == -3) echo ' selected="selected"' ?>>(GMT-03:00) Brazil, Buenos Aires</option>
                                                <option value="-2"<?php if (bb_server_timezone == -2) echo ' selected="selected"' ?>>(GMT-02:00) Mid-Atlantic</option>
                                                <option value="-1"<?php if (bb_server_timezone == -1) echo ' selected="selected"' ?>>(GMT-01:00) Azores</option>
                                                <option value="0"<?php if (bb_server_timezone == 0) echo ' selected="selected"' ?>>(GMT-00:00) Greenwich, West. Europe</option>
                                                <option value="1"<?php if (bb_server_timezone == 1) echo ' selected="selected"' ?>>(GMT+01:00) Central European</option>
                                                <option value="2"<?php if (bb_server_timezone == 2) echo ' selected="selected"' ?>>(GMT+02:00) Eastern European</option>
                                                <option value="3"<?php if (bb_server_timezone == 3) echo ' selected="selected"' ?>>(GMT+03:00) Moscow, Baghdad</option>
                                                <option value="3.5"<?php if (bb_server_timezone == 3.5) echo ' selected="selected"' ?>>(GMT+03:30) Iran</option>
                                                <option value="4"<?php if (bb_server_timezone == 4) echo ' selected="selected"' ?>>(GMT+04:00) Abu Dhabi, Dubai</option>
                                                <option value="4.5"<?php if (bb_server_timezone == 4.5) echo ' selected="selected"' ?>>(GMT+04:30) Kabul</option>
                                                <option value="5"<?php if (bb_server_timezone == 5) echo ' selected="selected"' ?>>(GMT+05:00) Islamabad, Karachi</option>
                                                <option value="5.5"<?php if (bb_server_timezone == 5.5) echo ' selected="selected"' ?>>(GMT+05:30) India</option>
                                                <option value="5.75"<?php if (bb_server_timezone == 5.75) echo ' selected="selected"' ?>>(GMT+05:45) Kathmandu</option>
                                                <option value="6"<?php if (bb_server_timezone == 6) echo ' selected="selected"' ?>>(GMT+06:00) Astana, Dhaka</option>
                                                <option value="6.5"<?php if (bb_server_timezone == 6.5) echo ' selected="selected"' ?>>(GMT+06:30) Rangoon</option>
                                                <option value="7"<?php if (bb_server_timezone == 7) echo ' selected="selected"' ?>>(GMT+07:00) Bangkok, Jakarta</option>
                                                <option value="8"<?php if (bb_server_timezone == 8) echo ' selected="selected"' ?>>(GMT+08:00) Western Australia</option>
                                                <option value="9"<?php if (bb_server_timezone == 9) echo ' selected="selected"' ?>>(GMT+09:00) Japan, Korea</option>
                                                <option value="9.5"<?php if (bb_server_timezone == 9.5) echo ' selected="selected"' ?>>(GMT+09:30) Central Austrailia</option>
                                                <option value="10"<?php if (bb_server_timezone == 10) echo ' selected="selected"' ?>>(GMT+10:00) Eastern Austrailia</option>
                                                <option value="11"<?php if (bb_server_timezone == 11) echo ' selected="selected"' ?>>(GMT+11:00) Magadan, Solomon Is.</option>
                                                <option value="12"<?php if (bb_server_timezone == 12) echo ' selected="selected"' ?>>(GMT+12:00) New Zealand, Fiji</option>
                                                <option value="12.75"<?php if (bb_server_timezone == 12.75) echo ' selected="selected"' ?>>(GMT+12:45) Chatam Island, NZ</option>
                                                <option value="13"<?php if (bb_server_timezone == 13) echo ' selected="selected"' ?>>(GMT+13:00) Tonga, Phoenix Islands</option>
                                                <option value="14"<?php if (bb_server_timezone == 14) echo ' selected="selected"' ?>>(GMT+14:00) Christmas Islands</option>
                                                </select>
                                                <br /></label>
<?php
                $languages 
= array();
                
$d dir(FORUM_ROOT.'include/languages');
                while ((
$entry $d->read()) !== false)
                {
                        if (
$entry != '.' && $entry != '..' && is_dir(FORUM_ROOT.'include/languages/'.$entry) && file_exists(FORUM_ROOT.'include/languages/'.$entry.'/main.php')) $languages[] = $entry;
                }
                
$d->close();
                if (
count($languages) > 1)
                {
?>
                                        <label><?php echo $lang['Language'?> :
                                        <select name="language">
<?php
                        
while (list(, $temp) = @each($languages))
                        {
                                if (
bb_default_lang == $temp) echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$temp.'</option>'."\n";
                                else echo 
"\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$temp.'</option>'."\n";
                        }
?>
                                        </select>
                                        <br /></label>
<?php
                
}
?>
                                </div>
                        </div>
                        <div class="inform">
                                <h2><?php echo $lang['Privacy options legend'?></h2>
                                <div class="infldset file" style="padding:10px">
                                        <p><?php echo  $lang['E-mail setting info'?></p>
                                        <div class="rbox">
                                                <label><input type="radio" name="email_setting" value="0" /><?php echo $lang['E-mail setting 1'?><br /></label>
                                                <label><input type="radio" name="email_setting" value="1" checked="checked" /><?php echo $lang['E-mail setting 2'?><br /></label>
                                                <label><input type="radio" name="email_setting" value="2" /><?php echo $lang['E-mail setting 3'?><br /></label>
                                        </div>
                                        <p><?php echo $lang['Save user/pass info'?></p>
                                        <div class="rbox">
                                                <label><input type="checkbox" name="save_pass" value="1" checked="checked" /><?php echo $lang['Save user/pass'?><br /></label>
                                        </div>
                                </div>
                        </div>
                        <div><input type="submit" class="b1" name="register" value="<?php echo $lang['Register'?>" /><input type="reset" class="b1" name="reset" value="<?php echo $lang['Clear'?>" /></div>
                </form>
        </div>
</div>
<?php
require FORUM_ROOT.$forum_folder.'/footer.php';
?>


Village Idiot 07-15-2009 05:57 PM

You're going to have to be more specific, we are willing to help you but we will not just take a piece of code and do something for you (especially code that large and messy). What part are you having trouble with?

khile 07-15-2009 09:48 PM

ive inserted the code into the above but when i run query always returns with username unavailable even when it is available

dschreck 07-27-2009 04:25 AM

It's pretty straight forward, just break it down into these steps:

1) Accept a posted user name

ie:

Code:

<form method='post' action='validate_username.php' name='validate_username'>
  <input type='text' name='username' id='username' value="" />
  <input type='submit' value='Check Name' />
</form>

PHP Code:

<?php

$userName 
$_POST['username'];

2. Hit the DB to see if that name is available.

PHP Code:


$userName 
$_POST['username'];

$clean['username'] = mysql_real_escape_string($userName);

$sql "SELECT 1 FROM users WHERE username = '{$clean['username']}'";

$get mysql_query($sql) or die(mysql_error()); // remove the die() command after testing

if(mysql_num_rows($get) > 0)
{
  
// user is not available.
}
else
{
 
// user is available.



3. Add output for those 2 cases, if their name is available, if their name isn't.


and boom, you have a proof of concept.

Now as a developer your role is to take that proof of concept and apply it to whatever you need to do.


One note:
I'm using "SELECT 1 FROM" syntax because I don't actually want any data, I'm just trying to see if a row exists. This is the cheapest way to run live row check queries.


good luck :p


All times are GMT. The time now is 10:31 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0