Hello, I am trying to create a form with php that echo data like this: "echo -e “username /npassword” > filename". I created the form and php embedded code but I cant seem to create variables with the text box names. We currently have a automated guest wifi account creation and I have to GUI the process. I am using radio buttons to create and delete because depending on thier options the username and password echo's to different file locations. Can anyone help because I am fairly new to PHP and I cant find any help searching for what I want. thanks

Dani AI

Generated

Short, practical fixes and a safe pattern to follow for and .

The main problems seen in the original code are syntax errors and a misunderstanding of what PHP echo does vs writing a file or running a shell command. echo -e ... > file is a shell construct, not PHP. Also checks like isset($_POST(['create'])) are malformed (should be isset($_POST['create'])) and using $_POST[...] without existence checks causes "Undefined index" notices. Ensure your form fields actually have the name attributes the handler expects.

A simple, safer server-side pattern (validate, sanitize, write or queue the action) looks like this:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create'])) {
    $uname = trim($_POST['uname'] ?? '');
    $pword = $_POST['pword'] ?? '';
    $action = $_POST['create'];

    // basic sanitize: allow only safe filename chars
    $safe = preg_replace('/[^A-Za-z0-9._-]/', '', $uname);

    if ($action === 'creation') {
        if ($safe === '' || $pword === '') { echo '<p>Missing username or password.</p>'; }
        else {
            $path = "/WifiGuestCreate/{$safe}";
            $line = $uname . ' ' . $pword . PHP_EOL;
            if (file_put_contents($path, $line) === false) { echo '<p>Write failed: check permissions.</p>'; }
            else { echo '<p>Created (queued).</p>'; }
        }
    } elseif ($action === 'deletion') {
        $path = "/WifiGuestDelete/{$safe}";
        file_put_contents($path, $uname . PHP_EOL);
        echo '<p>Deleted (queued).</p>';
    }
}
?>

Troubleshooting tips and cautions:

  • Use htmlspecialchars($_SERVER['PHP_SELF']) or leave action empty to post to the same script.
  • Check directory permissions: the web user must be allowed to create/write those files.
  • If you must run shell commands, escape with escapeshellarg() and avoid user input directly.
  • For : "Undefined index: type" means the form did not send type — confirm name="type" exists or use isset()/filter_input(); move away from deprecated mysql_* functions and use prepared statements (mysqli or PDO) to avoid injection.

Here is What I have so far. Please let me know if I am doing this all wrong. Thanks

<html>
<head>
<title>FRHG Guest Wireless Account Creation or Deletion</title>
</head>

<body>
<h1 align= "center">Fremont-Rideout Health Group</h1>
<h1 align= "center">Guest Wireless</h1><br /><br /><br />

<?php
/*$uname = $_POST['uname'];
$pword = $_POST['pword'];
$create = $_POST['creation'];
$delete = $_POST['deletion'];*/

if(isset($_POST(['create']))
{

if($_POST['create'] == 'creation')
{
        echo -e  {$_POST['uname']} /n{$_POST['pword']} > /WifiGuestCreate/{$_POST['uname']};
}   
elseif($_POST['create'] == 'deletion')
{   
        echo -e  {$_POST['uname']} > /WifiGuestDelete/{$_POST['uname']};
}   
else
{
    echo "<p>Please select Create or Delete</p>";
}
}
?>

<form method= 'post' action= '<?php echo htmlentities $PHP_SELF;?>' id='form' accept-charset='UTF-8'>
<fieldset>
<legend>Account Creation/Deletion</legend><br /><br />
<label for='uname' >Username: </label>
<input type='text' size='30' maxlength='30' name='uname'><br /><br />
<label for='pword' >Password: </label>
<input type='password' size='30' maxlength='30' name='pword'><br /><br />
<input type='radio' name='create' value='creation' />Create
<input type='radio' name='create' value='deletion' />Delete<br /><br />
<input type='submit' name="submit" value='Submit' /><br /><br />
</fieldset>
</form>
<h5>*For Deleting feature, do not input Password</h5>

</body>
</html>

error it gives after pressing edit button is this

Notice: Undefined index: type in C:\xampp\htdocs\project\admin\users-edit-action.php on line 7

and this id the script on which it gives the error..i think error is due to wrong placement of values in radio buttons..

<?php include("../includes/config.php");?>
<?php
$id=$_POST["id"];
$firstname=$_POST["firstname"];
$lastname=$_POST["lastname"];
$email=$_POST["email"];
$type=$_POST["type"];

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }


 mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$firstname."' , lastname='".$lastname." email='".$email."' type='".$type."' WHERE (id='".$id."')");
$result = mysql_query($query);
echo "User has been updated Successfully!!";
mysql_close($con);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.