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
https://forums.phpfreaks.com/topic/90947-checking-to-see-if-record-exists/
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;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.