0

We have a feedback form in PHP which adds data to Oracle DB. We have noticed that some users are sending the same feedback multiple times which we want to avoid.

The best way for us is to check for some common fields already present in the Oracle table, if data is found, then just don't enter the data and pop up a message to the user.

I have used if condition to check if the query returned any values and did a lot of trials and errors but didn't succeed. Below is my code, please check and suggest a suitable way to accomplish what I want.

$connect = oci_connect("ppusr", "welcome", "XX.XX.XX.XX/TR11",'AL32UTF8');
$sqlchk = "Select * FROM CUSTOMER_FEEDBACK WHERE CT_CUST_NAME=:CT_CUST_NAME , CT_CUST_NUMBER=:CT_CUST_NUMBER, CT_CUST_COMMENTS=:CT_CUST_COMMENTS ,CT_CUST_FEEDBACK_TYPE=:CT_CUST_FEEDBACK_TYPE, CT_CUST_LOCATION=:CT_CUST_LOCATION, CT_IP=:CT_IP";
$win12561 = iconv('windows-1256', 'utf-8', $sqlchk);
$stidchk = oci_parse($connect, $win12561);
oci_bind_by_name($stidchk, ':CT_CUST_NAME', $_POST['CustomerName']);
oci_bind_by_name($stidchk, ':CT_CUST_NUMBER',$_POST['CustomerMobile']);
oci_bind_by_name($stidchk, ':CT_CUST_COMMENTS',$_POST['Comments']);
oci_bind_by_name($stidchk, ':CT_CUST_FEEDBACK_TYPE', $_POST['Type']);
oci_bind_by_name($stidchk, ':CT_CUST_LOCATION', $_POST['Area']);
oci_bind_by_name($stidchk, ':CT_IP', $_SERVER['REMOTE_ADDR']);
oci_execute($stidchk);
$rowchk = oci_fetch_all($stidchk);
$ttno1 = $rowchk['CT_CUST_TTNO'];
if(empty($rowchk)) {
 //...... insert data .........
}
else
{
//...... display message box .........
    function function_alert($message) { 
    echo "<script>alert('$message'); location='https://www.google.com';</script>"; 
} 
function_alert("Thank you but you have already submitted the feedback"); 
}

Thanks.

user3625561
  • 305
  • 5
  • 25
  • There are similar questions answered on SO, e.g. https://stackoverflow.com/questions/34645765/prevent-duplicate-insert-data-in-oracle Some pro tips: add error checking to your oci_* calls. Why do you have to convert the query string character set? Is something in your environment mis-configured? – Christopher Jones Apr 08 '21 at 22:54
  • sorry guys, my select query itself was wrong, i used commas instead of AND. Anyway, as suggested by @ChristopherJones to look for the other question, I created a procedure and did my validations in it. – user3625561 Apr 11 '21 at 09:08

0 Answers0