PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 04:55 PM
nepz nepz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 nepz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 23 sec
Reputation Power: 0
Troubles using fwrite

Hi,


I have some schoolwork that needs to be done, and im pretty new at PHP. My teacher wanted me to create an HTML conact form, after this you will be sent to page nr two. Where i am listing out the information in the form, a confirmation. This i done. But now he wants me to create an .txt file where the information will be saved.


Code:
<html><head><title>Form</title></head><body>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        
<form action="form.php" method="POST">
        <p>Name</p> <input type="text" name="name">
        <p>Email</p> <input type="text" name="email">
        <p>Phone</p> <input type="text" name="phone">
        <p>Adress</p><input type="text" name="adress">
        

<p>Hva lurer du på?<br/>
    <select size="1" name="dropdown">
<option>Products</option>
<option>Shipping</option>
<option>Other</option>
    </select>
    
<br />
<br />

    
        <td>Do you want us to call you?<br />
            Yes <input type="radio" name="answer" value="Yes" />

            No<input type="radio" name="answer" value="No" />
        </td>
        
        
        
        <br />
        <br />
<p>Comment</p><textarea wrap="OFF" name="comment" rows="6" cols="25"></textarea><br />      
<br />
<input type="submit" value="Send" />
</form>
</body>
</html>


Now i want the customers information to be saved in a .txt file.

Code:
<?php 
session_start();

$fp =fopen("temp/text.txt","w+");
fwrite($fp,$_SESSION["name"]."\n");
fwrite($fp,$_SESSION["phone"]."\n");
fwrite($fp,$_SESSION["adress"]."\n");
fwrite($fp,$_SESSION["email"]."\n");
fwrite($fp,$_SESSION["answer"]."\n");
fwrite($fp,$_SESSION["dropdown"]."\n");
fwrite($fp,$_SESSION["comment"]."\n");
fwrite($fp,"\n");
fclose($fp);
?>


Name, phone, adress and email is the only ones who saves in the .txt file. The others, i dont know (answer, dropdown, comment). Something wrong with my code? Tell me if you need some more info about this,

Thanks

Reply With Quote
  #2  
Old November 9th, 2012, 06:27 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,874 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 54 m 11 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
$_SESSION is for session data. You know, with session_start() and all that.

Use $_POST: that's data from a submitted form (with method=post).

Reply With Quote
  #3  
Old November 9th, 2012, 06:30 PM
nepz nepz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 nepz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
$_SESSION is for session data. You know, with session_start() and all that.

Use $_POST: that's data from a submitted form (with method=post).


Something like this?


PHP Code:
 fwrite($fp,$_POST["name"]."\n");
fwrite($fp$_POST["email"]."\n");
fwrite ($fp$_POST["phone"]."\n");
fwrite ($fp$_POST["adress"]."\n");
fwrite ($fp$_POST["comment"]."\n");
fwrite ($fp$_POST["dropdown"]."\n");
fwrite ($fp$_POST["answer"]."\n"); 

Reply With Quote
  #4  
Old November 9th, 2012, 06:34 PM
nepz nepz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 nepz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 23 sec
Reputation Power: 0
With the post method no informasjon is getting saved in my .txt file, its empty

Reply With Quote
  #5  
Old November 9th, 2012, 06:50 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,874 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 54 m 11 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Are you putting this code in form.php or someplace else? If the latter then what's in form.php?

Reply With Quote
  #6  
Old November 9th, 2012, 06:59 PM
nepz nepz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 nepz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Are you putting this code in form.php or someplace else? If the latter then what's in form.php?



PHP Code:
<?php
session_start
();
ini_set('session.bug_compat_warn'0);
ini_set('session.bug_compat_42'0);


if (isset(
$_REQUEST["name"]))
{
echo 
"Name: ".$_REQUEST["name"]."<br/> ";

}
if (isset(
$_REQUEST["Phone"]))
{
echo 
"Phone: ".$_REQUEST["Phone"]."<br>";
}
if (isset(
$_REQUEST["email"]))
{
echo 
"Epost: ".$_REQUEST["email"]."<br>";
}

if (isset(
$_REQUEST["dropdown"]))
{
echo 
"You question is about: ".$_REQUEST["dropdown"]."<br>";
}
if (isset(
$_REQUEST["comment"]))
{
    echo 
"Your comment: <br>";
    echo 
"<b>(".$_REQUEST["comment"].")</b><br/>";
}
if (isset(
$_REQUEST["adress"]))
{
echo 
"Adress: ".$_REQUEST["adress"]."<br>";
}

$_SESSION["name"]=$_REQUEST["name"];
$_SESSION["email"]=$_REQUEST["email"];
$_SESSION["phone"]=$_REQUEST["phone"];
$_SESSION["adress"]=$_REQUEST["adress"];
$_SESSION["comment"];$_REQUEST["comment"]; 
$_SESSION["dropdown"];$_REQUEST["dropdown"];

echo 
"<br/>";

$answer $_POST['answer'];

    if (
$answer == "Yes") {
        
        echo 
'<strong>We will call you!</strong>';
        
    }
    
    else {
        
        echo 
'<strong>We wont call you :(</strong>';
        
    }   
    echo 
"<br/>";

?>
<a href="form2.php">Continue to the third site</a>



This is form.php. I'm norwegian so i have to translate my coding into english, sorry for any mispelled words.

Reply With Quote
  #7  
Old November 9th, 2012, 08:01 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,874 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 54 m 11 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Then you actually should be using $_SESSION in the new code.

The problem is in form.php.
PHP Code:
 $_SESSION["comment"];$_REQUEST["comment"];  
$_SESSION["dropdown"];$_REQUEST["dropdown"]; 

See those extra semicolons?

Reply With Quote
  #8  
Old November 10th, 2012, 01:18 PM
nepz nepz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 nepz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Then you actually should be using $_SESSION in the new code.

The problem is in form.php.
PHP Code:
 $_SESSION["comment"];$_REQUEST["comment"];  
$_SESSION["dropdown"];$_REQUEST["dropdown"]; 

See those extra semicolons?


Oh my god.... am i blind? Thank you very much!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Troubles using fwrite

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap