Jump to content

Form submit only once


vgamemaster

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.