function memory($user,$ayat){
    sqlconnection();
    $user = mysql_real_escape_string($user);
    $ayat = mysql_real_escape_string($ayat);

if((checkmemory($user,$ayat)==0) || !(checkmemory($user,$ayat)==0)){
    $sql="INSERT INTO `mark` (
`user_id` ,
`ayat`
)
VALUES (
'".$user."', '".$ayat."'
)";
mysql_query($sql);
return $sql;    
}
}
function checkmemory($user,$ayat){
        sqlconnection();
    $user = mysql_real_escape_string($user);
    $ayat = mysql_real_escape_string($ayat);
    $sqlmemory="SELECT *
FROM `mark`
WHERE `user_id` = '".$user."'
AND `ayat` =".$ayat;
$sqlmemoryresult=mysql_num_rows(mysql_query($sqlmemory));
return $sqlmemoryresult;
    }

http://localhost/quran/index.php?link=mark&totalayat=30 this link is not working.

I mean when totalayat is 10,20,30,40,50,60 then its not working. But other value say 5,8,26,65 is working well. What is the problem?

only odd number is working, even number is not working

Actually I am not sure why you did something like this:

if((checkmemory($user,$ayat)==0) || !(checkmemory($user,$ayat)==0))

It is always true right?

So you are always trying to insert user_id and ayat without considering what function checkmemory($user,$ayat) returns

If user_id is the primary key your INSERT will fail when trying to insert existing user id.

i would echo out the queries ran:

function memory($user,$ayat){
    sqlconnection();
    $user = mysql_real_escape_string($user);
    $ayat = mysql_real_escape_string($ayat);
if((checkmemory($user,$ayat)==0) || !(checkmemory($user,$ayat)==0)){
    $sql="INSERT INTO `mark` (
`user_id` ,
`ayat`
)
VALUES (
'".$user."', '".$ayat."'
)";
echo $sql;
mysql_query($sql);
return $sql;    
}
}
function checkmemory($user,$ayat){
        sqlconnection();
    $user = mysql_real_escape_string($user);
    $ayat = mysql_real_escape_string($ayat);
    $sqlmemory="SELECT *
FROM `mark`
WHERE `user_id` = '".$user."'
AND `ayat` =".$ayat;
echo $sqlmemory;
$sqlmemoryresult=mysql_num_rows(mysql_query($sqlmemory));

return $sqlmemoryresult;
    }

I can only imagine its mysql_real_escape_string() doing something, could try putting the $ayat value in quotes in the mysql query. I notice the insert has quotes and the checkmemory doesnt, does the insert work?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.