I've decided to create a comment script for a beginning project. Right now, I'm working on the registering part of the script. My problem is checking to see if the username already exists within the database. Here's the code I'm using right now:
PHP Code:
<?
$user = $_POST['username'];
$pass = $_POST['password'];
$check = $_POST['passcheck'];
$conn = mysql_connect(/* connect to mysql */);
if(!$conn){
echo("Unable to connect to MySQL: ". mysql_error());
exit;
}
$db = mysql_select_db(/* try to connect to database */);
if(!$db){
echo("Unable to select database: ". mysql_error());
exit;
}
/* ::: LOOK BELOW ::: */
$result = mysql_query("SELECT * FROM information WHERE user = '". $user ."'");
if($result != ""){
echo("Username already exists in database. Please choose a different username to continue.");
exit;
}
/* ^^^^ LOOK ABOVE ^^^^ */
?>
I can connect to MySQL and the database just fine.