Padgoi Posted February 21, 2008 Share Posted February 21, 2008 Ok, so right now I have this code: $sql= htmlspecialchars ("INSERT INTO Ratings (username, profile, registration, ip) VALUES ('$_POST[username]','$_POST[prof]','$_POST[registration]','$_SERVER[REMOTE_ADDR]')"); As you can see, the last column is logging ip addresses for everyone who submits information. I need an if statement or something that will limit one submission per ip so that if someone tries to make 2 submissions from the same ip, they won't be able to. Can anyone help me with this? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
axiom82 Posted February 21, 2008 Share Posted February 21, 2008 Make the IP field a UNIQUE index...that's the lazy way. Quote Link to comment Share on other sites More sharing options...
burnside Posted February 21, 2008 Share Posted February 21, 2008 Try : $ip = $_SERVER[REMOTE_ADDR]; $check = mysql_query("SELECT * FROM Ratings WHERE ip = '$ip'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if($info['ip'] == $_SERVER[REMOTE_ADDR]) { echo " No poste "; } else { echo " okay to post"; } Quote Link to comment Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 <?php $query = "SELECT * from Ratings where ip = '$_SERVER[REMOTE_ADDR]'"; $result = mysql_query($query); $n_results = mysql_num_rows($result); if($n_results){ // already submitted. throw error }else{ // run your sql injection } ?> Quote Link to comment Share on other sites More sharing options...
axiom82 Posted February 21, 2008 Share Posted February 21, 2008 Or you could do this... if (mysql_num_rows (mysql_query ("SELECT * FROM `Ratings` WHERE `ip` = '{$_SERVER['REMOTE_ADDR']}'")) == 0){ mysql_query (" INSERT INTO `Ratings` SET `username` = '{$_POST['username']}', `profile` = '{$_POST['prof']}', `registration` = '{$_POST['registration']}', `ip` = '{$_SERVER['REMOTE_ADDR']}' "); } Quote Link to comment Share on other sites More sharing options...
Padgoi Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks fellas, got it working now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.