1

Im trying to get a row, But it does not return anything on my site, But it works perfectly on local host.

public function GetVote($rel)
    {
        include 'config.php';

        $stmt = $dbh->prepare("SELECT updown FROM user_votes WHERE UID = :id AND rel = :rel");
        $stmt->bindParam(":id", $this->id);
        $stmt->bindParam(":rel", $rel);
        $stmt->execute();

        $row = $stmt->fetch(PDO::FETCH_ASSOC);

        return $row['updown'];
    }

Running SQL on phpmyadmin, Site: enter image description here

Running SQL on phpmyadmin, Local:

enter image description here

  • I dont know why its saying there is no unique colum, VID is unique and auto-increment.

Table structure:

enter image description here

14
  • Can you show an Image of your Table Structure of your Server DB? Commented Sep 16, 2013 at 6:39
  • 1
    VID is unique, but you are only SELECTing the updown field... Therefore, you cannot edit the data being returned. Commented Sep 16, 2013 at 6:43
  • could you try localhost instead of 127.0.0.1 (or viceversa in your PHP script)? I had a similar problem, and traced it back to the mysqli_connect..., 127.0.0.1 was failing (no data was returned as script could not even connect to DB) but localhost was ok. Commented Sep 16, 2013 at 6:44
  • what type of you UID column ? Commented Sep 16, 2013 at 6:44
  • 1
    try using select * from user_votes Commented Sep 16, 2013 at 6:44

2 Answers 2

3

VID is unique, but your are only SELECTing the updown field. Therefore, phpMyAdmin can't let you edit the data and it produces that warning.

Also, try following query:

SELECT *
FROM `user_votes`
WHERE `UID`='76561197996836099'
AND `rel`='5'
LIMIT 0,30

I've noticed the UID and ref fields are varchar, but you're sending an integer (way to big, btw)...

Sign up to request clarification or add additional context in comments.

3 Comments

Its varchar because im using Steam 64 ID's, they sometimes start with a 0 that would be lost if it was integer, also i have a local UID that starts with "la". And ive tried * and still returns nothing. I only need updown returned on the script.
TristanCunningham, Marty has suggested correct way to compare String id. You were using as an Integer whereas UID is a VARCHAR
This looks good, even the fields are contained in (`). You can use single quotes (') for number values also.
1

just try this and tell..any output or not??

public function GetVote($rel)
{
include 'config.php';

$stmt = $dbh->prepare("SELECT * FROM user_votes WHERE rel = :rel");

$stmt->bindParam(":rel", $rel);
$stmt->execute();

$row = $stmt->fetch(PDO::FETCH_ASSOC);

return $row['updown'];
}

2 Comments

That returns the rows.
Yeah, Its been fixed now. There was a confict with the UID veriable somewhere else that was causing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.