I want to know how to create a file from user inputs on a form in PHP

45 views Asked by At

I want to know how to set user input conditions on a form in PHP. The condition are: If a user types in a name and a drink and it does not match from a file called drinks.txt which contains name, drinks tigerwoods, coke jay,sprite

it should append to and or create a file called newdrinks.txt which stores a) names and b) drinks c) ipaddress of the user

The code I have written is below but is not working.Note that I haven't posted my form code here just the php code I created. This form uses $_POST method.

   $as = file('drinks.txt');  
 foreach ($as as $line){

    $m = preg_split("/,/", $line);
}

if(!isset($_POST["u"]) && ($_POST["p"]) !== $m) {


echo " We don't have the drink Mr.$_POST[u] but we will make sure to get it next time";
$fp = fopen("drinks.txt", "a+");
$fwrite($fp, "newdrinks.txt");
fclose(($fp);
?>

Thank-you

0

There are 0 answers