hye there.. i'm sure u are in a blur stage in solving ur problem there.. i can give a sample of mine, where i can check the existed record in a database by inserting a few line of codes..
//at first u need to connect ur sql to the database
//i used a pre-define variable to connect my database
//hope u could modify it to where it is suitable
$conn = phpmkr_db_connect(HOST, USER, PASS,DB);
//i have a few actions with some conditions- but i only show the display record
switch ($sAction)
{
//this is the code to check an ecisting record in database
case "I": // Get a record to display
if (LoadData($sKey,$conn)) { // Load Record based on key
//this is the msg that will prompt out if it existed
$HTTP_SESSION_VARS["ewmsg"] = "Existed Record for Key = " . $sKey;
phpmkr_db_close($conn);
header("Location: CustomerList.php");
exit();
}
//this code is to check whether the record has not yet been added
if (!LoadCusData($sKey,$conn)) { // Load Record based on key
$HTTP_SESSION_VARS["ewmsg"] = "No Record Found for Key = " . $sKey;
phpmkr_db_close($conn);
header("Location: CustomerList.php");
exit();
}
break;
}
then i have the function which is called LoadData to check whether the record is existed..
//-------------------------------------------------------------------------------
// Function LoadData
// - I Load the Data based on a Key selected at a page before the display page (Value sKey is passed to this page)
// - Variables setup: field variables
function LoadData($sKey,$conn)
{
global $HTTP_SESSION_VARS;
$sKeyWrk = "" . addslashes($sKey) . "";
$sSql = "SELECT bla bla bla
FROM table";
$sWhere .= "(CustomerID = " . $sKeyWrk . ")";
$sGroupBy = "";
$sHaving = "";
$sOrderBy = "";
$sSql .= " WHERE " . $sWhere;
if ($sGroupBy <> "") {
$sSql .= " GROUP BY " . $sGroupBy;
}
if ($sHaving <> "") {
$sSql .= " HAVING " . $sHaving;
}
if ($sOrderBy <> "") {
$sSql .= " ORDER BY " . $sOrderBy;
}
$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query: " . phpmkr_error() . '<br>SQL: ' . $sSql);
if (phpmkr_num_rows($rs) == 0) {
$LoadData = false;
}else{
$LoadData = true;
$row = phpmkr_fetch_array($rs);
// Get the field contents
// U must retrieve fields for the record
// these are my examples - to help u
$GLOBALS["x_CustomerID"] = $row["CustomerID"];
$GLOBALS["x_JobName"] = $row["JobName"];
$GLOBALS["x_AgencyName"] = $row["AgencyName"];
$GLOBALS["x_JobName"] = $row["JobName"];
$GLOBALS["x_TrainingName"] = $row["TrainingName"];
}
phpmkr_free_result($rs);
return $LoadData;
}
this is how i do my checking.. BUT, correct me if i'm wrong.. 😃
my situation is: i have a page to list all of the records.. each of it has a link to add records' details and edit the record.. for a record which is existed, when the user click add records' details, a msg will prompt out telling the record is exist in database.. and if u noticed, i have another condition to check whether the record is existed or not.. say the user click edit to a non-existed record, a msg will prompt out saying the record is not existed yet..
another things that u need to know about my coding.. my codes are actually comprises of 5 tables which links up together.. that is why my database checking is a bit fuzzy.. u might be confused.. did u?
emm.. for sure i didnt paste the full complete codes here.. but if u are interested to see the real example, and wanted to understand better, you can request it and ask from me later..
hope i dont confused u.. and i also hope that this code can help u..
Regards, videxx 🆒