1

In the code below the variables I create ($host, $username etc.) remain empty. What am I doing wrong? When I just make a variable with a regular string it works fine.

<form action="" method="post">
<input type="text" name="host" id="host-input" value="" />
<input type="text" name="dbname" id="db-input" value="" />
<input type="text" name="password" id="password-input" value="" />
<input type="text" name="username" id="username-input" value="" />
<input type="submit" name="submit" value="Submit">
</form>

<?php
if (isset($_POST['submit']))
{
        $host = $POST['host'];
        $username = $POST['username'];
        $dbname = $POST['dbname'];
        $password = $POST['password'];

        $file = 'testbestandje.php';
        // Open the file to get existing content
        $current = file_get_contents($file);
        // Append a new person to the file
        $current .= '<? $conn=mysql_connect("'.$host.'","'.$dbname.'","'.$password.'") or die("Kan geen verbinding maken met de DB server"); 
 mysql_select_db("'.$username.'",$conn) or die("Kan database niet selecteren"); ?>'; 
        // Write the contents back to the file
        file_put_contents($file, $current);
}
?>
2
  • $host = $POST['host']; should be $host = $_POST['host']; - you're missing the underscores. Commented May 31, 2013 at 18:09
  • what a stupid mistake. Thanks for pointing it out :) Commented May 31, 2013 at 18:09

1 Answer 1

4

$_POST is the correct variable name

    $host = $_POST['host'];
    $username = $_POST['username'];
    $dbname = $_POST['dbname'];
    $password = $_POST['password'];

Documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.