Jump to content

Archived

This topic is now archived and is closed to further replies.

Renlok

mysql problem...i think

Recommended Posts

For a rating system i made this wassuposed to stop people voting on the same thing twice but it dusnt work. When you send a rating it enters you ip address correctly but it doesnt stop you from sending it as meny times as you want.

[code]  $query1 = "select * from rating where ip is $ip and url is $url";
  $result1 = $db->query($query1);
  $num_results = $result1->num_rows;
  if ($num_results > 0)
  {
      echo 'You have already voted for '.$url;
  }
  else
  {
  $query = "insert into rating (ratingValue, URL, ip) values
            ('".$rate."', '".$url."', '".$ip."')";
  $result = $db->query($query) or die ($db->error);
  if ($result)
      echo  $db->affected_rows.' You have rated '.$url.'as a '.$rate;
      echo '<br>your ip address has been logged as '.$ip.'<br>Thankyou for using our site';
  }
  $db->close();[/code]

Share this post


Link to post
Share on other sites
try changing this:
$query1 = "select * from rating where ip is $ip and url is $url";

to this:
$query1 = "select * from rating where ip='" . $ip . "' and url='" . $url . "'";

Share this post


Link to post
Share on other sites
yes, as mentioned, you need to use [b]=[/b] not [b]is[/b] and you need the quotes around the data.  However using a concactonated string is not necessary. simply doing this:

[code]
$query1 = "select * from rating where ip='$ip' and url='$url'";
[/code]

is okay

Share this post


Link to post
Share on other sites

×

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.