473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help with i/o in text files, please

I have a form calling below php snippet, and all it does is echo ".dat" on a blank page... what gives?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username = $_POST[$uname];
  3. $fname = $username . ".dat";
  4. if (!file_exists($fname)) { //uniqueness
  5.     chdir('data');
  6.     copy('blank.dat',$fname);
  7.     $handle = fopen($fnname,"a");
  8.     fwrite($handle, $_POST[$password]);
  9.     chdir('..');
  10.     echo $fname;
  11. }    
  12. else {
  13. echo "not unique";
  14. }
  15. ?>
Oct 12 '07 #1
14 1228
pbmods
5,821 Expert 4TB
Heya, DementedGimp. Welcome to TSDN!

Looks like it's not picking up $_POST[$uname]. Did you mean:
Expand|Select|Wrap|Line Numbers
  1. $username = $_POST['uname']
?
Oct 12 '07 #2
Tried that... still nothing... using Apache 1.3 & php 5
Oct 13 '07 #3
pbmods
5,821 Expert 4TB
Heya, DementedGimp.

The problem is that $username has no value. Try putting this at the top to see what is being submitted with the form:

Expand|Select|Wrap|Line Numbers
  1. print_r($_POST);
  2.  
Oct 13 '07 #4
pbmods,
all I get is ;Array()' as output!
Oct 14 '07 #5
pbmods
5,821 Expert 4TB
Heya, DementedGimp.

So $_POST is empty; therefore $_POST['uname'] has no value.
Oct 14 '07 #6
pbmods,
here is the calling form:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "Input user info:<br>";
  3. echo "<form method='POST' action='infoinput.php'>";
  4. echo "<br>Please enter username: <input type='text' name='$uname'>";
  5. echo "<br>Please enter password: <input type='text' name='$password'>";
  6. echo "<input type='submit'>";
  7. echo "</form>";
  8. ?>
It doesn't see $uname, i guess.....
Oct 14 '07 #7
Markus
6,050 Expert 4TB
pbmods,
here is the calling form:
<?php
echo "Input user info:<br>";
echo "<form method='POST' action='infoinput.php'>";
echo "<br>Please enter username: <input type='text' name='$uname'>";
echo "<br>Please enter password: <input type='text' name='$password'>";
echo "<input type='submit'>";
echo "</form>";
?>

It doesn't see $uname, i guess.....
Why use a variable as the name of the input?

Take away the dollar sign and then $_GET['uname'] and the same for password.
Oct 14 '07 #8
pbmods,
I striipped all the php out of the calling form, and it works... thanks pbmods
Oct 14 '07 #9
Arrrgh, pb, it worked for two input variables, but when I added more input vars:
Input user info:[php]
<br>
<form name="userinput" method="POST" action="infoinput.php">
<br>Please enter username: <input type="text" name"$username">
<br>Please enter last name: <input type="text" name="$lastname">
<br>Please enter first name: <input type="text" name="$firstname">
<br>Please enter sex: <input type="text" name="$sex">
<br>Please enter date of birth: <input type="text" name="$dob">
<br>Please enter password: <input type="text" name="$password">
<br>Please enter address1: <input type="text" name="$address1">
<br>Please enter address2: <input type="text" name="$address2">
<br>Please enter city: <input type="text" name="$city">
<br>Please enter statte: <input type="text" name="$state">
<br>Please enter zipcode: <input type="text" name="$zipcode">
<input type="submit">
</form>
[/php]
it didn't see $username, but saw the rest. here is infoiinput.php:
[php]
<?php
print_r($_POST);
$uname = $_POST['$username'];
$pw = $_POST['$password'];
$fname = $uname . ".dat";
if (!file_exists($fname)) { //uniqueness
chdir('data');
copy('blank.dat',$fname);
$handle = fopen($fname,"a");
fputs($handle, $pw);
chdir('..');
// echo $fname;
}
else {
echo "not unique";
}
?>
[/php]
I know, you're going to ask why not mysql, but mysql just refuses to work for me.
Oct 14 '07 #10
pbmods
5,821 Expert 4TB
Heya, DementedGimp.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

Have a look at this page.
Oct 14 '07 #11
PB,
I stripped the $ from the code, but it still does not see 'username'.... here the code:
Expand|Select|Wrap|Line Numbers
  1. Input user info:<br>
  2. <form name="userinput" method="POST" action="infoinput.php">
  3. <br>Please enter username: <input type="text" name"username">
  4. <br>Please enter last name: <input type="text" name="lastname">
  5. <br>Please enter first name: <input type="text" name="firstname">
  6. <br>Please enter sex: <input type="text" name="sex">
  7. <br>Please enter date of birth: <input type="text" name="dob">
  8. <br>Please enter password: <input type="text" name="password">
  9. <br>Please enter address1: <input type="text" name="address1">
  10. <br>Please enter address2: <input type="text" name="address2">
  11. <br>Please enter city: <input type="text" name="city">
  12. <br>Please enter statte: <input type="text" name="state">
  13. <br>Please enter zipcode: <input type="text" name="zipcode">
  14. <input type="submit">
  15. </form>
  16.  
here's the code for infoinput.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. print_r($_POST);
  3. $uname = $_POST['username'];
  4. $pw = $_POST['password'];
  5. $fname = $uname . ".dat";
  6. if (!file_exists($fname)) { //uniqueness
  7.     chdir('data');
  8.     copy('blank.dat',$fname);
  9.     $handle = fopen($fname,"a");
  10.     fputs($handle, $pw);
  11.     chdir('..');
  12. }   
  13. else {
  14. echo "not unique";
  15. }
  16. ?>    
  17.  
Oct 14 '07 #12
pbmods
5,821 Expert 4TB
Heya, DementedGimp.

What is the output of print_r($_POST) when you submit the form?
Oct 14 '07 #13
Pb,
Everything but the first variable username, which is weird, 'cause it worked with just 2 variables.....
Oct 15 '07 #14
Array ( [lastname] => jacques [firstname] => pages [sex] => m [dob] => 9/28/64 [password] => miki69 [address1] => dddddddddd [address2] => ssssssss [city] => ggggggg [state] => rii [zipcode] => 02842 )
Oct 15 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Alpha | last post by:
I have a Window based application that shows up still running in the task manager when I close it. It reaches the "this.close" statement and then it stops at the "}" at the section of the...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
0
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
5
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.