| | |
script running without errors, but not doing tasks
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Solved Threads: 0
Hi,
I'm very new to PHP. Any help is appreciated.
I wrote a script that should create a flat file and store information in the flat file that was entered in a form on an earlier page. The script runs successfully and with no errors, and creates the file with the correct name (so my variable values are being passed ok by $_POST), but when I look at the file, nothing was written to it. It was only created and named.
Here's the script...
also, if an existing file name is used, it is not stopping the script to echo "The accountname $accountname already exists."
Thanks in advance for any help. I'd look it up on my own, but I'm not getting any errors to google and I can't find a good tutorial for what I'm trying to do.
- John
I'm very new to PHP. Any help is appreciated.
I wrote a script that should create a flat file and store information in the flat file that was entered in a form on an earlier page. The script runs successfully and with no errors, and creates the file with the correct name (so my variable values are being passed ok by $_POST), but when I look at the file, nothing was written to it. It was only created and named.
Here's the script...
PHP Syntax (Toggle Plain Text)
<?php $accountname = $_POST['accountname']; $phone = $_POST['phone']; $fax = $_POST['fax']; $cell = $_POST['cell']; $add1 = $_POST['add1']; $add2 = $_POST['add2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $data = "$accountname \n $phone \n $fax \n $cell \n $add1 \n $add2 \n $city \n $state \n $zip \n"; $ending = ".txt"; $filename = "$accountname$ending"; $handle = fopen($filename, 'x+'); if (file_exists('$filename')){ echo "The accountname $accountname already exists."; }else{ $handle; fwrite($filename, $data); fclose($filename); echo "Data Stored Successfully"; } ?>
also, if an existing file name is used, it is not stopping the script to echo "The accountname $accountname already exists."
Thanks in advance for any help. I'd look it up on my own, but I'm not getting any errors to google and I can't find a good tutorial for what I'm trying to do.
- John
try these changes...I put some comments where I thought they might help you understand what I changed...
php Syntax (Toggle Plain Text)
<?php $accountname = $_POST['accountname']; $phone = $_POST['phone']; $fax = $_POST['fax']; $cell = $_POST['cell']; $add1 = $_POST['add1']; $add2 = $_POST['add2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $data = "$accountname \n $phone \n $fax \n $cell \n $add1 \n $add2 \n $city \n $state \n $zip \n"; $ending = ".txt"; $filename = "$accountname$ending"; //strings are only interpolated in double quotes! do not use single quotes if placing variables in strings. //'$filename' = $filename //"$filename" = the contents of $filename if (file_exists("$filename"))//check for file in this directory { echo "The accountname $accountname already exists."; } else { //open file handle in this directory $handle = fopen($filename, 'x+'); //write to handle fwrite($handle, $data); //close file handle fclose($handle); //the next line will echo regardless if what it says is true... echo "Data Stored Successfully"; } ?>
The End
![]() |
Similar Threads
- Programming FAQ - Updated 1/March/2005 (Computer Science)
- in over my head LOST welcha? wininet? (Viruses, Spyware and other Nasties)
- HJT log - bridge.dll & others..? (Viruses, Spyware and other Nasties)
- IE Syntax Error and Can´t browse some sites (Viruses, Spyware and other Nasties)
- How can I delete Hosts: 1159680172 auto.search.msn.com? (Viruses, Spyware and other Nasties)
- Server delay - with html, asp, aspx pages (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: New php user need help
- Next Thread: How to stop spam?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue eregi error explodefunction file files folder form forms function functions google hack href htaccess html image include insert integration ip java javasciptvalidation javascript joomla keywords limit link login loop mail matching menu mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web website xml youtube





