0
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?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Biiim
1

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.

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.