[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 10-26-2004, 03:34 PM   #1 (permalink)
NamePros Regular
 
QBert's Avatar
 
Join Date: Apr 2004
Location: Australia
Posts: 775
72.00 NP$ (Donate)

QBert has a spectacular aura aboutQBert has a spectacular aura about


250np$ For simple php script

Hey, i need a script that checkes a value what somones typed up to see if its = to somthing in the database. just like checking for a username to put to a password.

Thanks

QBert
QBert is offline  
Old 10-26-2004, 04:54 PM   #2 (permalink)
Senior Member
 
Crusader's Avatar
 
Join Date: Aug 2003
Location: Canada
Posts: 1,293
1,264.40 NP$ (Donate)

Crusader is just really niceCrusader is just really niceCrusader is just really niceCrusader is just really nice


This would be form.html
Code:
<form name="checker" method="POST" action="domain.com/check.php">
  <p>Username: <input type="text" name="username" size="20" value="<?php echo $username; ?>"><br>
  <input type="submit" value="Check" name="doit"></p>
</form>
This would be check.php
PHP Code:
<?php

$username
= $_POST['username'];

if(
$username != " "){
    
$username = str_replace("<?", "&nbsp;", $username);
    
$username = str_replace("?>", "&nbsp;", $username);
    
    
$sql_username_check = mysql_query("SELECT username FROM usernames WHERE username='$username'");
    
$username_check = mysql_num_rows($sql_username_check);

    if(
$username_check > 0){
        echo
"That username already exists.";
        unset(
$username);
    } else {
        echo
"That username does not exist.";
    }
}

include (
"form.html");

?>
I think that should work. Note you'd need a table called usernames with a field called username.
__________________

Near Fantastica
| Matthew Good - Vancouver
>> Do you Frawlik? <<
Crusader is offline  
Old 10-26-2004, 05:28 PM   #3 (permalink)
₪NamePros Elite™
 
PolurNET's Avatar
 
Join Date: Jul 2004
Location: Kingston, Canada
Posts: 2,963
365.30 NP$ (Donate)

PolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant futurePolurNET has a brilliant future

Alzheimer's Cancer Survivorship Third World Education Autism Save a Life Cystic Fibrosis Parkinson's Disease Lou Gehrig's Disease (ALS) Autism Multiple Sclerosis SIDS
remember to connect to a DB first m8, you need to use

Code:
mysql_connect('localhost', 'mydb', 'mypass');
__________________
PolurNET Communications Avoid the Freeze, Enjoy the Breeze!
= A very special day, February 12th =
Proudly #1 on NamePros and WebHostingJury for over 3 years!
||LawPoint.org •• GREAT UK HOSTING DEALS NOW AT: ExcellentHost.com ••
PolurNET is offline  
Old 10-26-2004, 05:34 PM   #4 (permalink)
québécois libre
 
peaudecastor's Avatar
 
Join Date: Oct 2003
Location: Trois-Rivieres, Québec
Posts: 563
353.91 NP$ (Donate)

peaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nice


Hi Crusader,

Why are you checking for <? and ?> ?
PHP Code:
$username = str_replace("<?", "&nbsp;", $username);
Unless you prove me otherwise they are harmless what you should always do to be secure are :
$username = addslashes($username);

With your code I could post in the username field something like '; DELETE FROM usernames

And break you

Matt

Quote:
Originally Posted by Crusader
This would be form.html
Code:
<form name="checker" method="POST" action="domain.com/check.php">
  <p>Username: <input type="text" name="username" size="20" value="<?php echo $username; ?>"><br>
  <input type="submit" value="Check" name="doit"></p>
</form>
This would be check.php
PHP Code:
<?php

$username
= $_POST['username'];

if(
$username != " "){
    
$username = str_replace("<?", "&nbsp;", $username);
    
$username = str_replace("?>", "&nbsp;", $username);
    
    
$sql_username_check = mysql_query("SELECT username FROM usernames WHERE username='$username'");
    
$username_check = mysql_num_rows($sql_username_check);

    if(
$username_check > 0){
        echo
"That username already exists.";
        unset(
$username);
    } else {
        echo
"That username does not exist.";
    }
}

include (
"form.html");

?>
I think that should work. Note you'd need a table called usernames with a field called username.
peaudecastor is offline  
Old 10-26-2004, 05:36 PM   #5 (permalink)
Senior Member
 
Crusader's Avatar
 
Join Date: Aug 2003
Location: Canada
Posts: 1,293
1,264.40 NP$ (Donate)

Crusader is just really niceCrusader is just really niceCrusader is just really niceCrusader is just really nice


Err. Yeah, you're right. Ignore the <? ?> and strip out special characters instead.
__________________

Near Fantastica
| Matthew Good - Vancouver
>> Do you Frawlik? <<
Crusader is offline  
Old 10-26-2004, 09:50 PM   #6 (permalink)
NamePros Regular
 
QBert's Avatar
 
Join Date: Apr 2004
Location: Australia
Posts: 775
72.00 NP$ (Donate)

QBert has a spectacular aura aboutQBert has a spectacular aura about


Thanks everyone,

NP$'s sent Crusader. Thanks!
QBert is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 09:40 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85