-2

When the result exists it's not going to the if condition, it will go to else. In query result $num>0 I want an alert like "receipt number already exists".

$.post("acceptajax.php?confirm1="+confirm+'&receipt='+receipt+'&amount='+amount,function(result,status){
    //$('#divsub'+confirm).html(data);
    if(result == 'exist'){
        alert('Receipt number Alerady Exit');
    } else {
        $('#accept_'+confirm).hide();
        $('#unaccept_' +confirm).show();
    }
});

acceptajax.php:

$img_id=$_GET['confirm1'];
$receipt=$_GET['receipt'];
$receipt='HYD'.$receipt;
$amount=$_GET['amount'];
$sql=mysql_query("SELECT receipt FROM user WHERE receipt=$receipt");
$num=mysql_num_rows($sql);
if($num==0){
    echo "suc";
} else {
    echo "exist";
}
Antti29
  • 2,953
  • 12
  • 34
  • 36

2 Answers2

0

You are missing ' around $receipt. Try this :

"SELECT receipt FROM user WHERE receipt='$receipt'"

Side note :

1) Please dont use mysql_. It is deprecated and removed from PHP 7.Use mysqli_* or PDO.

2) Your query is open for sql injection. Read this : How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Mr. Engineer
  • 3,522
  • 4
  • 17
  • 34
0

use query like this:

$sql=mysql_query("SELECT receipt FROM user WHERE receipt='".$receipt."'");

and instead of using this because this is not right way to code, because you are using post method to send data and sending it using get method.

$.post("acceptajax.php?confirm1="+confirm+'&receipt='+receipt+'&amount='+amount,function(result,status)

you should use it like this:

$.post("acceptajax.php", {confirm1:confirm, receipt: receipt, amount: amount}, function(result, status){
   //your script
 });

and get the data on acceptajax.php using $_POST[]; method. Hope it Helps.

Sonu Bamniya
  • 1,095
  • 1
  • 13
  • 29