<?php   include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'header.php';?>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])){
    $user=$_GET['user'];
}else{
    $user=$_SESSION['user_id'];
}
$my_id = $_SESSION['user_id'];
$username=getuser($user,'username');
?>
<h3> <?php echo $username;   ?>  </h3>
<?php
if($user != $my_id){
    $check_frnd_query=mysql_query("select id from frnds where (user_one='$my_id' and user_two='$user') or (user_one='$user' and user_two='$my_id')");
    if(mysql_num_rows($check_frnd_query) == 1){
        echo "<a href=''>already frnd</a> | <a href='actions.php?action=unfrnd&user'> Unfrnd $username</a>";
    }else {
            $from_query = mysql_query("SELECT 'id' FROM 'frnd_req' WHERE 'from'='$user' AND 'to'='$my_id'");
        $to_query = mysql_query("SELECT 'id' FROM 'frnd_req' WHERE 'from'='$my_id' AND 'to'='$user'");
        if (mysql_num_rows($from_query) == 1)
        {
            echo "<a href=''>ignore </a>   | <a href='actions.php?action?action=accept&user=$user'>    accept </a>";
        } else if (mysql_num_rows($to_query)  == 1)
        {
            echo "<a href='actions.php?action=cancel1&user=$user'>cancel</a>";
        }else{
            echo "<a href='actions.php?action=send&user=$user'> send req</a>";
        }
}}
?>
//// i have error in two lines is  if (mysql_num_rows($from_query) == 1)  &  else if (mysql_num_rows($to_query)  == 1) plz help me

Recommended Answers

All 12 Replies

What are the errors you are gettings?

From a cursory glance, it looks like you are getting a cursor error due to not freeing the resource after your initial query...

i have error in two lines is if (mysql_num_rows($from_query) == 1) & else if (mysql_num_rows($to_query) == 1)

according to

http://www.php.net/mysql_query

mysql_query will return false if the connection does not have permission to access the table.

It would seem your user for the database may not have correct privilege.

As the error says, instead of having a mysql resource, it is getting a boolean, which is why you are getting the error.

nthng happnd@ryantroop ..plz hlp

As a standard practice you should be testing your queries before you try doing anything with them. Ideally this would be with an if statement so but at the very least you should add a die statement to your query. Add this and see what gets outputted:

$from_query = mysql_query("SELECT 'id' FROM 'frnd_req' WHERE 'from'='$user' AND 'to'='$my_id'") or die ("Error in query: ".mysql_error());
$to_query = mysql_query("SELECT 'id' FROM 'frnd_req' WHERE 'from'='$my_id' AND 'to'='$user'") or die ("Error in query: ".mysql_error());

when i used it . It shows error in query you have an error in your sql syntax. Check manual that corresponds to your mysql version for right syntax to use near ,frnd_req' where 'from'='4' and 'to'='1' at line 1

you can not put quotes around column name (I assume from and to are column names)

write as

where from='4' and to='1' 

i tried this bt same error has show

No quotes on table or column name. Try this:

$from_query = mysql_query("SELECT id FROM frnd_req WHERE from='$user' AND to='$my_id'");
$to_query = mysql_query("SELECT id FROM frnd_req WHERE from='$my_id' AND to='$user'");

nthng hapned same error occurd @GliderPilot

Sorry I didn't even clue into this when I first looked. The words to and from are reserved words in MySQL and serve functions. When using reserved words as an identifier you need to quote them using the ` character (Left of the top "1" key, not the single quote). As below:

$from_query = mysql_query("SELECT id FROM frnd_req WHERE `from`='$user' AND `to`='$my_id'");
$to_query = mysql_query("SELECT id FROM frnd_req WHERE `from`='$my_id' AND `to`='$user'");

See here for more info: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

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.