Jump to content

Creating a like system


mdmartiny

Recommended Posts

I am in the process of creating a like system for a personal website that I am working on. I am trying to pull information from one database and use that to place info into another database. When I do I get resource error #15.

 

This is my code that I have so far

 

function like_add() {
    $last = $_GET['l'];
    $first = $_GET['f'];
    $ip = $_SERVER['REMOTE_ADDR'];

    $like_sql = "Select * from `counter` where first = ' $first ' and last = '$last '";
    $like_result = mysql_query($like_sql);

    $likes = '<p class="like_button"> Likes ';
    while ($like_row = mysql_fetch_assoc($like_result)) {
        $like = $like_row['likes'];

        $likes .= " $like";
    }
    $likes .= '</p>';
    echo "$likes";
    echo '<form name="like_add_form" action="" method="POST" class="like_add">
<input type="submit" name="like_add" class="like_add_button" value="Like Me" />
</form>';

    if (isset($_POST['like_add'])) {
        $page_id = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'";
        $page_id_result = mysql_query($page_id);
        echo $page_id_result; <----- Here I am trying to pull information from a field in my database to use as a variable and to place in the second database

        $voted = mysql_query("Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id_result'"); <----- Here I want to use the information from the first table to place in the second one

        if (mysql_num_rows($voted) != 0) {
            echo "You have all ready liked this post";
        } else {
            mysql_query("INSERT into `liked_ip`(id,page_id,ip) VALUES ('$page_id_result','$ip')");
        }
        if (mysql_num_rows($voted) == 0) {
            mysql_query("UPDATE counter SET `likes` = `likes` + 1 where first = '$first' AND last = '$last'");
        }
    }
}

 

I know that I have to be doing something so simple that I am just not seeing it this late at night. I may even be completely wrong in all of this. If someone could please help me out I would appreciate it very much.

Link to comment
Share on other sites

Let's see if I hot this right. From what I read from  foing some searching. I run the query and it its everything in a array. Using the mysql_fetch_assoc makes it an associative one. Will that work if I only want info from one row on table

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.