Jump to content

Recommended Posts

The id isn't being assigned to the link mouse over and you will see it is not there. You click on one of the links to vote and you get

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

<?php

// MAKE CONNECTION
   include ('db_connect.php');

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT * FROM users WHERE id = $id;";
  if ($result = mysql_query($sql)) {
    if (mysql_fetch_assoc($result)) {
    $votes = $row['votes'];
    $total = $row['total'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }
}

//We only run this code if the user has just clicked a voting link
if (isset($_GET['mode']) && $_GET['mode']=="vote")
{

//If the user has already voted on the particular thing, we do not allow them to vote again $cookie = "Mysite$id";
if(isset($_COOKIE[$cookie]))
{
Echo "Sorry You have already ranked that site <p>";
}

//Otherwise, we set a cooking telling us they have now voted
else
{
$month = 2592000 + time();
setcookie(Mysite.$id, Voted, $month); 

//Then we update the voting information by adding 1 to the total votes and adding their vote (1,2,3,etc) to the total rating
mysql_query ("UPDATE users SET total = total+$voted, votes = votes+1 WHERE id = $id");
Echo "Your vote has been cast <p>";
}
} 

//This calculates the sites ranking and then outputs it - rounded to 1 decimal
if (!$rating['votes'] || !$rating['total']){
   $current = 0;
  echo "Unrated";
} else {
   $current = $ratings['total'] / $ratings['votes']; 
   echo "Rated " . round($current, 1). " from $votes people";
} 
echo " | <b>Rate This Display</b>: "; 

//This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item

Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id=".$ratings[id].">1</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&id=".$ratings[id].">2</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&id=".$ratings[id].">3</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id=".$ratings[id].">4</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&id=".$ratings[id].">5</a><p>";

?>

I see a few issues. Here...

 

$votes = $row['votes'];

 

You use an array called $row which is not defined anywhere. Most likely, you want to define it using the result from mysql_fetch_assoc().

 

Further down your script you start using another undefined array. $ratings[], where does this come from?

 

You should really put this...

 

<?php ini_set('display_errors','1') ; error_reporting(E_ALL) ; ?>

 

at the top of all your scripts (at least while devloping), this way you actually see all your errors.

You use an array called $row which is not defined anywhere.

 

I don't know what you mean by defined but it is use to show the results in the echo here

 

 echo "Rated " . round($current, 1). " from $votes people";

 

I am using this tutorial below as the guide so any questions as to why I am using what and where is because of this tutorial.

 

http://php.about.com/od/finishedphp1/ss/rating_script.htm

 

I have very little php experience and don't use it often and really don't have the time to sit down and learn it. Just need to get this down and learn enough to do what I need to do.

 

Here can view the errors from the error reporting on this page

 

http://www.mesquitechristmas.com/local/display.php?id=81

 

 

-Thanks

 

I have very little php experience and don't use it often and really don't have the time to sit down and learn it. Just need to get this down and learn enough to do what I need to do.

 

Simply put, I don't really have time to sort through all your code and fix all your errors either. As I stated, you use two variables $row and $ratings in your code. Both of which are not defined anywhere.

 

The code you posted in your last post has absolutely nothing to do with anything I've said.

Man how rude, I wasn't specifically asking YOU to sort through all my code. I was just giving you some background information. The guy that was suppose to do the php didn't have time to do it after all. I don't have the money to pay someone even though I have someone but trying to get as much of it done myself so I won't have to spend as much.

 

Like I have said already $votes = $row['votes']; is defined in the code if you read my last post you would see where it is used. As far as $ratings goes my last post explains that I am going by a tutorial and that is where that came from.

 

Instead of quoting me and being a prick you could be a little more helpful since this is a support/help forum which you have not done ether. If you don't have time for me then please don't respond to my thread taking the focus away from my problem where maybe someone else can help me.

 

-Thanks

 

This line....

 

$votes = $row['votes']

 

defines $votes. However, nowhere in your code is $row defined. I told you in my original reply how I assume you should define it.

 

most likely, you want to define it using the result from mysql_fetch_assoc().

 

Hence your code should be....

 

<?php

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT * FROM users WHERE id = $id;";
  if ($result = mysql_query($sql)) {
    if ($row = mysql_fetch_assoc($result)) { // <-- here $row is now defined.
    $votes = $row['votes'];
    $total = $row['total'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }
}

 

As for the rest of your undefined variables. I can't help. You simply have variables appearing from nowhere.

dada what thorpe is trying to say is that $row needs to be defined before you define $votes.

 

in the code that thorpe gave u just before

 

if ($row = mysql_fetch_assoc($result)) { // <-- here $row is now defined.

 

he defined $row for you so now

 

$votes = $row['votes']; will be correctly defined and will work properly..

 

In php when using variables they have to be defined first.

 

Eg:

I have $apples apples.

 

will not work because apples isn't defined.

 

$apples = 3;

I have $apples apples

..

Explains itself

he id isn't being assigned to the link mouse over and you will see it is not there. You click on one of the links to vote and you get

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

I can see you can't read.

 

What? Read my answers. Ive pointed out your issues several times as simply as I can. What do you want from me?

 

he id isn't being assigned to the link mouse over and you will see it is not there.

 

Because as Ive said. $ratings is not defined anywhere in your code!

 

If your not going to read the answers provided, why bother asking questions? And having digs at me because you don't understand the answers is pretty well unhelpfull.

if (!$rating['votes'] || !$rating['total']){
   $current = 0;
  echo "Unrated";
} else {
   $current = $ratings['total'] / $ratings['votes']; 
   echo "Rated " . round($current, 1). " from $votes people";
} 

 

the id isn't showing because none of the above code is assigned.

 

What do you want from me?

 

For you not to reply anymore.

 

 

Because as Ive said. $ratings is not defined anywhere in your code!

 

No shit really? I think I have already stated this problem.

 

the id isn't showing because none of the above code is assigned.

 

Really? You came to that conclusion on your own? I think I know this already and I think I have already stated my issue. I posted here for help with this not for people to point out the obvious.

 

Geez....

 

Is their anyone out there who can suggest how to fix this?

 

 

 

 

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.