250np$ For simple php script

SpaceshipSpaceship
Watch

QBert

Established Member
Impact
10
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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:
<?php

$username = $_POST['username'];

if($username != " "){
	$username = str_replace("<?", " ", $username);
	$username = str_replace("?>", " ", $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.
 
0
•••
remember to connect to a DB first m8, you need to use

Code:
mysql_connect('localhost', 'mydb', 'mypass');

:)
 
0
•••
Hi Crusader,

Why are you checking for <? and ?> ?
PHP:
$username = str_replace("<?", " ", $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

Crusader said:
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:
<?php

$username = $_POST['username'];

if($username != " "){
	$username = str_replace("<?", " ", $username);
	$username = str_replace("?>", " ", $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.
 
0
•••
Err. Yeah, you're right. Ignore the <? ?> and strip out special characters instead.
 
0
•••
Thanks everyone,

NP$'s sent Crusader. Thanks!
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back