mercredi 29 avril 2015

PHP fopen not working

I just can't figure this out, I keep getting Unable To Create Group.

What I'm attempting to do is you submit a forum, and it creates a file with some info in it. If the group name already exist(the file) then tell them that. Though I keep getting as I stated "Unable To Create Group" as my die message.

This is the PHP part:

if($_POST['ownername'] && $_POST['groupname']){

$ownername = htmlspecialchars($_POST["ownername"]);
$groupname = htmlspecialchars($_POST["groupname"]);

echo 'Owner is ' . $ownername . ' and the group is ' . $groupname;
$groupfile = '/groups/' . $groupname . '.txt';

if(file_exists($groupfile) == false){
    $newgroup = fopen($groupfile, 'w') or die("Unable to create group");
    $txt = "Users:" . $ownername;
    fwrite($newgroup, $txt);
    echo "<font style='color:green'>The group has been created! You may access it <a href='chat.php?group=" . $groupname . "'>here</a></font>";
} else {
    echo "<font style='color:red'>The group name is taken, please use another name or wait for it to be released</font>";

Then this is my HTML part:

<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
<input type="text" name="ownername" placeholder="Username"/>
<input type="text" name="groupname" placeholder="Group Name"/>
<input type="submit" value="Create"/>

Any and all help is appreciated, thank you very much!

Aucun commentaire:

Enregistrer un commentaire