Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
Doulos
Life Cycles Becoming CPU Cycles



Joined: Jun 06, 2005
Posts: 732

PostPosted: Sun Oct 01, 2017 3:46 pm Reply with quote

I have a form from which the data is posted to a db table but it is allowing duplicate forms to be posted from the same user.


I have tried ON DUPLICATE KEY UPDATE forumname = VALUES(forumname)")
Code:
$result = $db->sql_query('INSERT INTO `members` VALUES '."(NULL, '$forumname', '$firstname', '$lastname', '$gamename', '$address', '$city', '$state', '$zipcode', '$country', '$phone', '$email', '$comments') ON DUPLICATE KEY UPDATE forumname = VALUES(forumname)");


    include_once 'header.php';
    OpenTable();
   
    if ($result) {
        header ("Location: /modules.php?name=Member_Info_Thanks");
    } else {
        echo '<div class="text-center">Failed!<br /><br />' , _GOBACK , '</div>' , PHP_EOL;
    }
    CloseTable();
it stops duplicate entries but ... I would very much like to know...
    1. the best way to stop duplicate entries into the database, and
    2. how would I send the user to a "Duplicate entry found for <forumname>" message instead of the successful entry thank-you message.
 
View user's profile Send private message
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1772

PostPosted: Mon Oct 02, 2017 4:18 am Reply with quote

I would start at first a check with SELECT on the same db-table to compare the required fields with the incoming input values. Don't forget to filter the incoming data to prevent SQL-injections! Maybe to check: $forumname, $firstname, $lastname and $gamename. And only if no entry is found in the db-table then I would start the INSERT. In this case you could delete completeley: ON DUPLICATE KEY UPDATE forumname = VALUES(forumname).

You could replace:

php Code:
header ("Location: /modules.php?name=Member_Info_Thanks");


with

php Code:
echo '<div class="text-center">Thank you!<br /><br />' , _GOBACK , '</div>' , PHP_EOL;
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©