iMakeAngry Posted February 13, 2011 Share Posted February 13, 2011 So, to keep this as short as possible, I am almost done making a website that lets visitors send already-made text messages to people. I just paid for hosting for the site, and they told me that I can only send 100 messages in one hour. This is fine as I was already intending on setting limits per ip address. So, I've set up MySQL and everything else works correctly. My only problem is that on the test script I've been working on over the weekend doesn't successfully check to see if an ip address exists in the database. Let me try and better explain what I need to do: I need the visitor's ip address to be logged on to the database the first time that they send a message in a day. (This part works.) But before it logs their ip address, it needs to check to see if it was already logged for the day. If their ip IS there then it will check to see how many messages they've sent today, if it is less than 5 then it will let them send the message and add 1 to the log. Otherwise it won't let them send the message. Tell me if it sounds too complicated. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 Post the problematic code, and the table structure. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 13, 2011 Share Posted February 13, 2011 I would do something like this: $ip = $_SERVER['REMOTE_ADDR']; $sql = mysql_query("SELECT count(*) as total FROM messages WHERE date(sent_date) = curdate() AND ip = INET_ATON('$ip')"); $row = mysql_fetch_assoc($sql); if($row['total'] == 5){ // max messages sent } Quote Link to comment Share on other sites More sharing options...
iMakeAngry Posted February 14, 2011 Author Share Posted February 14, 2011 Sorry about the late reply, since I couldn't get it to work I didn't feel the need to save the code, but this is basically what I used last <?php $username="imakeang_angry"; $password="tpark701234"; $database="imakeang_records"; mysql_connect(localhost,$username,$password); mysql_select_db($database); $ip = $_SERVER['REMOTE_ADDR']; $query="SELECT * FROM ip WHERE address='$ip'" or die(mysql_error()); $result=mysql_query($query) or die("mysql_error() 1"); $ip_rec_address=mysql_result($result,$i,"address"); $ip_rec_sent=mysql_result($result,$i,"sent"); if ( $ip_rec_address == $ip ) { if ( $ip_rec_sent == 2 ) { echo "You have sent too many messages today, wait until tomorrow to send another."; } else { $query = "INSERT INTO global_sent VALUES ('$result + 1')"; mysql_query($query); echo "$result messages sent."; } } mysql_close(); ?> This returns "Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5" on line 27 and 18. The Little Guy - I'll try that out right now. Quote Link to comment Share on other sites More sharing options...
stijnvb Posted February 14, 2011 Share Posted February 14, 2011 Did you honestly just put your DB username and PW here!? Have you tried running the SQL quiry through say phpmyadmin? You might have an error (like a wrong field name?) Also try adding `` round your field names in the quiry, and remove the '' around $ip just a few ideas that probably won't solve the problem! Good luck Quote Link to comment Share on other sites More sharing options...
stijnvb Posted February 14, 2011 Share Posted February 14, 2011 Little advise, change your password right away, as I can log into your cpanel with it ... Quote Link to comment Share on other sites More sharing options...
iMakeAngry Posted February 14, 2011 Author Share Posted February 14, 2011 Yeah right after I posted it I realized it and changed the password. Quote Link to comment Share on other sites More sharing options...
stijnvb Posted February 14, 2011 Share Posted February 14, 2011 Yeah right after I posted it I realized it and changed the password. Seriously?? I can still login to your cPanel as of 2 seconds ago ... 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.