Question about forms

Hello

I want to run a contest on my website and i am asking visitors to post their names and BTC addresses and i’ll use random.org’s list randomizer to pick one from the list

what i did so far:

[embed=425,349[php]]<?php
if ($_POST) {
$name = $_POST[‘commentName’];
$txt = $_POST[‘commentBTC’];
$handle = fopen(“comments.html”,“a”);
fwrite($handle, “” . $name . " : " . $txt . “
”);
fclose($handle);
}
?>
[/php]

and

[php]
Some Name:


BTC Address:

[/php]

so i get a html list, which is great. the problem is that some visitors are signing up multiple times :frowning:

is there a way to check ‘comments.html’ for ‘commentBTC’ and if exists, to deny signing up?

i can drop the ‘commentName’ field if it’s easier to have only a bitcoin address list.

help? thank you!

If you store the entries in a database or NoSQL table, it would easily be fixed. Using a flat file like you have, you would need to search through the file looking if the entry is currently there; and if so, ignore the entry.

it’s just something temporary. i got to this:

I have this messages.txt file containing rows like this:

ip.address bitcoin.address

I want to display only bitcoin.address and only once for every duplicate entry. this code will only display the bitcoin address but, unfortunately, will also list any duplicate bitcoin addresses.

<[php]?php

$lines = file(‘messages.txt’);
foreach ($lines as $line) {
$parts = explode(’ ', $line);
echo isset($parts[1]) ? $parts[1] : ‘N/A’;
echo “
”;
}

?>[/php]

I know i’m supposed to use array_unique but i can’t find any example on google that works with explode (and that i understand :))

A little help, please. Thank you!

array_unique is a separate function.

[php]explode( ‘//DELIMITER//’, array_unique($original_array));[/php]

Ditch the text file and use a proper database. Set the column to unique and no duplicates will be possible.

Sponsor our Newsletter | Privacy Policy | Terms of Service