Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:07:20+00:00 2026-05-26T09:07:20+00:00

I have this PHP contact form which disallows a submission from an existing IP.

  • 0

I have this PHP contact form which disallows a submission from an existing IP. I am trying to add the feature to submit one entry per IP, per day.

I have a column in my db table called Date which is datestamping every row. I know I need to create my if statement with 2 conditions… I am just not sure how to check the DB before submitting a new entry. Any help is appreciated. Thanks.

CODE SNIPPET:

$ip = gethostbyname($_SERVER['REMOTE_ADDR']);

mysql_select_db($database, $connection);
$QUERY = "SELECT COUNT(IP) AS `count` FROM `contest` WHERE IP = '$ip'";
$RESULT = mysql_query($QUERY) or die(mysql_error());

// Read the firs row
$row = mysql_fetch_assoc($RESULT);

// Check how many rows MySQL counted
if($row['count'] > 0) {
header ('Location: valueexists.html');
}
else {

//save the data on the DB

mysql_select_db($database, $connection);

$insert_query = sprintf("INSERT INTO contest (Name, Email_Address, Phone, Company_Name, Company_Address, Date, ip) VALUES (%s, %s, %s, %s, %s, NOW(), %s)",
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:07:20+00:00Added an answer on May 26, 2026 at 9:07 am

    Your structure is correct, to make a query with two conditions, simply add a AND to it:

    $query = "SELECT COUNT(ip) AS count FROM contest WHERE ip = '$ip' AND DATE(date) = CURDATE()";
    

    This will count all rows in the contest table with that IP and which have been submitted on that specific date. Note that I took “date” as your fieldname as I’m unaware of your table structure, so adapt it to the one you created.

    Edit
    I just noticed you are using NOW() to store your datetime in your database, so I changed my query to make use of the DATE() function. This extracts the date part of the date or datetime expression of the value as can be seen here.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm trying to add some another field to this php contact form I
I have this php code, with which I am trying to generate a popup
I have this PHP script which i'm grabbing images from a directory and displaying
I have a contact form, the values of which I'm passing to a php
I have a form like the one below which is posted to contacts.php ,
I have this form: <form action=contact.php method=post id=contactform> <ol> <li> <label for=name>First Name *
I have a simple contact form which uses jquery to post to a php
I have a spammer that use my PHP e-mail contact form and write this
I have the following JQuery to submit a contact form with jquery ajax. This
I have two files the one which hosts my actual contact form and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.