Jump to content


Photo

mysql problem...i think


  • Please log in to reply
3 replies to this topic

#1 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 23 October 2006 - 01:13 AM

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.

  $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();


#2 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 23 October 2006 - 04:28 AM

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 . "'";

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 23 October 2006 - 04:37 AM

yes, as mentioned, you need to use = not is and you need the quotes around the data.  However using a concactonated string is not necessary. simply doing this:

$query1 = "select * from rating where ip='$ip' and url='$url'";

is okay
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 23 October 2006 - 10:17 AM

oh ok thanks its working now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users