Forums

PHP

This topic is locked

Checking for duplicates

Posted 07 Jul 2003 17:14:22
1
has voted
07 Jul 2003 17:14:22 Saeed Abdi posted:
I would like to check that the "CompName" doesn't have any duplicates, and as I understand it I need to query the db and filter it with the Compname that is been entered into the form and if the result is not 0 then return and error message stating that the comp name is in db and user should select different name, so my question is how do I do this as I'm using dreamweaver MX and my php knowledge is "very" limited.



<pre id=code><font face=courier size=2 id=code>
-------------------------------------------------------------
&lt;?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO compname (CompName) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['CompName'], "text");

mysql_select_db($database_password_entry, $password_entry);
$Result1 = mysql_query($insertSQL, $password_entry) or die(mysql_error());
}
?&gt; </font id=code></pre id=code>

Reply to this topic