Current location: Hot Scripts Forums » Programming Languages » PHP » Writing to php file, via a form?


Writing to php file, via a form?

Reply
  #1 (permalink)  
Old 10-13-06, 01:14 PM
j-a-m-i-n's Avatar
j-a-m-i-n j-a-m-i-n is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 85
Thanks: 0
Thanked 1 Time in 1 Post
Question Writing to php file, via a form?

Hello fellow PT members,

As you can see, i'm a newbie here and also very new to php as a programming language.

I'm aiming to write to a php file via a form (which is included on multiple websites using include).

I have managed to write the form (update.php) and the process (just an echo as yet - I can't seem to put anything together using fopen & write, which subsequently is why I am here requesting help) (process.php).

I wish to overwrite the php file every time i use the form (update.php).

I think that what i'm trying to do is very basic, and shouldn't take a matter of minutes to correct for you wonderful gurus (correct me if i'm wrong) and am looking for help on how i can write to a file from form data rather than echoing it.

Update.PHP

Code:
<form ACTION="process.php" METHOD="post">
  <table WIDTH="400" BORDER="0" CELLSPACING="0" CELLPADDING="0">
  <tr>
    <td WIDTH="138" CLASS="style3">&nbsp;</td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td WIDTH="73" CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">Home Team: </td>
    <td COLSPAN="2" CLASS="style1"><input NAME="home" TYPE="text" /></td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">&nbsp;</td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">Away Team: </td>
    <td COLSPAN="2" CLASS="style1"><input NAME="away" TYPE="text" /></td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">&nbsp;</td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">Date:</td>
    <td WIDTH="121" CLASS="style1">      <span CLASS="style4">
      <select NAME="day" SIZE="1" CLASS="style2">
        <option>Monday</option>
        <option>Tuesday</option>
        <option>Wednesday</option>
        <option>Thursday</option>
        <option>Friday</option>
        <option>Saturday</option>
        <option>Sunday</option>
      </select>
    </span> </td>
    <td WIDTH="68" CLASS="style1">      <span CLASS="style4">
      <select NAME="number" SIZE="1" CLASS="style2">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
        <option>10</option>
        <option>11</option>
        <option>12</option>
        <option>13</option>
        <option>14</option>
        <option>15</option>
        <option>16</option>
        <option>17</option>
        <option>18</option>
        <option>19</option>
        <option>20</option>
        <option>21</option>
        <option>22</option>
        <option>23</option>
        <option>24</option>
        <option>25</option>
        <option>26</option>
        <option>27</option>
        <option>28</option>
        <option>29</option>
        <option>30</option>
        <option>31</option>
      </select>
    </span> </td>
    <td CLASS="style1"><select NAME="month" SIZE="1" CLASS="style2">
      <option>January</option>
      <option>February</option>
      <option>March</option>
      <option>April</option>
      <option>May</option>
      <option>June</option>
      <option>July</option>
      <option>August</option>
      <option>September</option>
      <option>October</option>
      <option>November</option>
      <option>December</option>
    </select></td>
  </tr>
  <tr>
    <td CLASS="style3">&nbsp;</td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">Time:</td>
    <td COLSPAN="2" CLASS="style3">
      <input NAME="hours" TYPE="text" VALUE="00" SIZE="2" MAXLENGTH="2" />
      :
      <input NAME="mins" TYPE="text" VALUE="00" SIZE="2" MAXLENGTH="2" />    </td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style3">&nbsp;</td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
  <tr>
    <td CLASS="style1"><input NAME="submit" TYPE="submit" VALUE="Update!" /></td>
    <td COLSPAN="2" CLASS="style3">&nbsp;</td>
    <td CLASS="style1">&nbsp;</td>
  </tr>
</table>
<br>
</form>
Process.PHP

PHP Code:

<?php

$home 
$_POST['home'];
$away $_POST['away'];
$day $_POST['day'];
$number $_POST['number'];
$month $_POST['month'];
$hours $_POST['hours'];
$mins $_POST['mins'];

echo 
"
<strong><span class='upcoming_teams'>
"
$home " <br> Vs <br> " $away " <br><br>
</span><span class='upcoming_date'>"
$day " "$number " "$month " <br> </span>
<span class='upcoming_time'>"
$hours ":"$mins "</span>
<span class='upcoming_date'>(GMT)</span>
<br />
<br />
<a href='http://www.timezoneconverter.com/cgi-bin/tzc.tzc' target='_blank'>
<span class='upcoming_date'>
TIME CONVERSION</span></a></strong>"
;

?>
I stand very appreciative of any help that can be given,
Ben
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-13-06, 05:25 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
what do you mean exactly when you say "write to a php file"? do you want to add text to a php file, or do you want to process the data by a php file?

this is a huge difference: when i take a look at your process.php it doesn't have anything in there to write to a php file, it simply to process entered data

What errors are you getting anyway? if none, make sure to set error_reporting to E_ALL

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-13-06, 05:36 PM
j-a-m-i-n's Avatar
j-a-m-i-n j-a-m-i-n is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 85
Thanks: 0
Thanked 1 Time in 1 Post
UnrealEd & All,

Quite simply - I am looking to just write the data entered in the form (update.php) shown on process.php as an echo to a php file (it's only set to echo the data because I'm not sure how to write it to a php file)

(i've tried tutorials to try and write the data instead of echoing it but i must be making basic errors when trying to do this)

Has anyone got any code suggestions for what i'm trying to achieve?

Thanks for your time,
Ben
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-13-06, 05:50 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
ok, to write the data to the file, you have to use either fopen and fwrite ( < PHP5) or file_put_contents (PHP5)

this is how you write to the file:
< PHP5
PHP Code:

// this will open a pointer to "myfile.extension"

// the "w" is a parameter which tells the fopen function to open the document, clear all data and then add new data read more about it on php.net
$fp fopen("myfilename.extension""w");
// to write to the file:
fwrite($fp$data);
fclose($fp); 
PHP5+:
PHP Code:

file_put_contents("myfile.extension"$data); 

Make sure your filepermissions are set correctly: when you want to store the file in a specific directory you must set the permissions of the directory so that everyone can write (create) files in that directory. you can do this by either using the chmod function in php, or changing the permissions of the directories in the properties menu of the file.

Hope this helps you,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-14-06, 05:43 AM
j-a-m-i-n's Avatar
j-a-m-i-n j-a-m-i-n is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 85
Thanks: 0
Thanked 1 Time in 1 Post
UnrealEd,

Thanks ever so much - you have been so helpful.

What you guys do here is second to none - supporting less knowledgeable folks like myself develop their knowledge of php.

It's like having the best 'paid for' support in the world - but FREE ...

Our new script is up and working -Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code 2 convert .doc file into .pdf file jeephp PHP 7 11-03-10 05:31 AM
Write to php file with php script or create new file, it is possible? Oskare100 PHP 10 08-14-08 10:03 AM
Writing to .txt file in php 897236489 PHP 3 06-20-05 02:25 AM
Writing from form to php config file Squid44th PHP 1 04-22-04 03:16 PM
php form to html file arnec PHP 1 01-21-04 11:14 AM


All times are GMT -5. The time now is 06:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.