ka3pmw Posted November 6, 2012 Share Posted November 6, 2012 (edited) I used to know how to do this, then I had a stroke. I am using an html input tag to get a file name and I want to pass that filename to a php routine. Please help this ole man. Here is what I have: <?php if (isset($_POST['logbtn'])) { $data = $_POST['logname']; $file = $mylog; $fh = fopen($file, "w") or die("Couldn't open $file for login!"); /* write other data here */ fclose($fh); } ?> </head> <body> <form id="setupForm" name="setupForm" method="post" action=""> <p><font size = "5"> <label><strong>What do you wish to call this file? </strong></label> <input name="mylog" type="text" value="mylog" size="15" maxlength="15"> </font></p> </form> </body> </html> Edited November 6, 2012 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/270369-getting-a-file-name-to-open/ Share on other sites More sharing options...
requinix Posted November 6, 2012 Share Posted November 6, 2012 You're doing it right on the line immediately above: $_POST["logname"] But the field's not called "logname", of course... Quote Link to comment https://forums.phpfreaks.com/topic/270369-getting-a-file-name-to-open/#findComment-1390585 Share on other sites More sharing options...
ka3pmw Posted November 6, 2012 Author Share Posted November 6, 2012 I am getting the following error: Notice: Undefined variable: mylog in C:\xampp\htdocs\logger\mysetup.php on line 5 Warning: fopen(): Filename cannot be empty in C:\xampp\htdocs\logger\mysetup.php on line 6 Couldn't open for login! My code is: <?php if (isset($_POST['logbtn'])) { $data = $_POST['mylog']; $file = $mylog; $fh = fopen($file, "w") or die("Couldn't open $file for login!"); /* write other data here */ fclose($fh); } ?> < html> < body> <form id="setupForm" name="setupForm" method="post" action=""> <p><font size = "5"> <label><strong>What do you wish to call this file? </strong></label> <input name="mylog" type="text" value="mylog" size="15" maxlength="15"> </font></p> </form> < /body> < /html> I did change the "logname" Quote Link to comment https://forums.phpfreaks.com/topic/270369-getting-a-file-name-to-open/#findComment-1390589 Share on other sites More sharing options...
requinix Posted November 6, 2012 Share Posted November 6, 2012 Lemme be a little more clear: the value you want is in $_POST["mylog"]. $mylog, as the error message indicates, does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/270369-getting-a-file-name-to-open/#findComment-1390592 Share on other sites More sharing options...
ka3pmw Posted November 6, 2012 Author Share Posted November 6, 2012 Thanks, it works like a charm! Quote Link to comment https://forums.phpfreaks.com/topic/270369-getting-a-file-name-to-open/#findComment-1390596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.