Jump to content

Checking to see if record exists.


JSHINER

Recommended Posts

How can I check to see if a record is already in the database?  Here what I'm using for code:

if (isset($_POST['submit'])) {

$password = md5($_POST['password']);

foreach ($_POST as $key => $value) {

	$_POST[$key] = $db->escape($value);

}

$query = '';

	$query .= 'INSERT INTO';

$query .= " users

	SET
		username 			= '{$_POST['username']}',
		password 			= '{$password}',
		email 		= '{$_POST['email']}'
		";

if (!$db->query($query)) {

	$page['error'][] = 'Could not save user information.';

} 

if (!isset($page['error'])) {

	header('Location: register.php?status=created');

	exit();
}
}

 

 

Link to comment
Share on other sites

function checkUnique($table, $field, $compared){
if (get_magic_quotes_gpc()) {
$table = stripslashes($table);
$field = stripslashes($field);
$compared = stripslashes($compared);
}
$table = mysql_real_escape_string($table);
$field = mysql_real_escape_string($field);
$compared = mysql_real_escape_string($compared);

$result = mysql_query("SELECT $field FROM $table WHERE $field = '$compared'");
if(mysql_num_rows($result)==0) {
return TRUE;
}
else {
return FALSE;
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.