Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/136162-form-submit-only-once/
Share on other sites

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

?>

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.