vgamemaster Posted December 9, 2008 Share Posted December 9, 2008 Hey guys, so I want a form that a user can submit only once. The form goes to a mysql database and logs the ip address. Is there any way in my page, I can put in a code that shows that form if the ip address is not there, and not show the form when the ip address is already logged. How could I go about doing this? Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/ Share on other sites More sharing options...
haku Posted December 9, 2008 Share Posted December 9, 2008 $ip_address = _____; $query = "SELECT count(ip_address) FROM table WHERE ip_address='" . $ip_address . "'"; $result = mysql_result(mysql_query($query)),0,0); if($result == 1) { // don't show form } else { //show form } Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710200 Share on other sites More sharing options...
skiingguru1611 Posted December 9, 2008 Share Posted December 9, 2008 Something along the lines of: <?php $ip=USER IP ADDRESS HERE $sql="select * $table WHERE ip='$ip'"; $result=mysql_query($sql,$connection) or die(mysql_error()); $num = mysql_numrows($result); if($num != 0){ while($row=mysql_fetch_array($result)) { MESSAGE TELLING THE PERSON THEY ALREADY SUBMITTED THE INFO }else{ FORM YOU WANT THEM TO SUBMIT ?> Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710202 Share on other sites More sharing options...
dezkit Posted December 9, 2008 Share Posted December 9, 2008 You can also use a session. Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710203 Share on other sites More sharing options...
haku Posted December 9, 2008 Share Posted December 9, 2008 A session is only good for that session. Which may be ok for the OP, but if the person closes their browser and re-opens it, they will see the form again. $sql="select * $table WHERE ip='$ip'"; Selecting * from a database isn't very efficient. Even when you want all the data from a row, it's more efficient to list off all the column names. In this case it's particularly inefficient, because the user doesn't need any of that data, he is only checking for the existence of a row, which is why count is better. But if not using count for whatever reason, it's still better to just select one column name rather than everything. Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710207 Share on other sites More sharing options...
vgamemaster Posted December 9, 2008 Author Share Posted December 9, 2008 Alright cool, I just have a few questions: What exactly am I supposed to define the $ip_address as? Do I change (ip_address) after the word count? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710845 Share on other sites More sharing options...
mrMarcus Posted December 9, 2008 Share Posted December 9, 2008 Alright cool, I just have a few questions: What exactly am I supposed to define the $ip_address as? Do I change (ip_address) after the word count? Thanks haku's initial code should work just fine as is, and is pretty self-explanatory. Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710911 Share on other sites More sharing options...
haku Posted December 10, 2008 Share Posted December 10, 2008 What exactly am I supposed to define the $ip_address as? As the IP address! Google can tell you how to find that. Stuff like that you should research on your own. Theory stuff like you asked in the first question is the kind of stuff to ask here. Do I change (ip_address) after the word count?] What? This is the first mention you have made of any kind of word count. No idea what you are talking about. Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710994 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 Alright cool, I just have a few questions: What exactly am I supposed to define the $ip_address as? Do I change (ip_address) after the word count? Thanks <?php $ip = $_SERVER['REMOTE_ADDR']; Will give you the ip address. Quote Link to comment https://forums.phpfreaks.com/topic/136162-form-submit-only-once/#findComment-710997 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.