Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-23-2006, 10:58 AM $Post Help
CWN
CWN's Avatar
Skilled Talker

Posts: 56
Trades: 0
Code:
      <form action="" method="post">
<table width="500" border="0" align="center">
  <tr>
    <th scope="row">Title: </th>
    <td><div align="center">
      <input name='title' type='text' value="<? echo("$title");?>">
    </div></td>
  </tr>
  <tr>
    <th scope="row">Subtext:</th>
    <td><div align="center">
      <input name='subtext' type='text' value="<? echo("$subtext");?>">
    </div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><div align="center"></div></td>
  </tr>
</table>

<div align="center">
<input value='Save Changes' type='submit'></form>

<?php
//Don't edit this--
$bad = array("<", ">", '"', "'",";");
$good  = array(" ", " "," ", " ", " ");
//Don't edit this--end

//add or modify the variables to change using similar format here
$title = $_POST['title'];
$subtext = $_POST['subtext'];

//view this format and modify to suit more or less variables - this stage cleans the user input
$cleantitle = str_replace($bad, $good, $title);
$cleansubtext = str_replace($bad, $good, $subtext);

//heres the new file contents, again look at the format and simply copy & paste to suite more or less variables
$content_to_write = 
'<?php 
$title = "' . $cleantitle . ' ";
$subtext = "' . $cleansubtext . ' ";
?>';

//filename of the file to hold variables
$filename = '../inc/variables.php';

// Main PHP
if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   if (fwrite($handle, $content_to_write) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
  
   // echo "Success, variables changed!";
  
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}

//Heres the form HTML that you need to add / modify to change the variables edited, note that $_POST['key'] matches up to name='key'

?>
So I have $title = $_POST['title']; and I only want title to be posted/changed when the form button is clicked. Whenever I refresh this page, it $_POST's title.

I have the variable set, and when I open the PHP page the variable posts nothing right away. After I post using the button the variable will show in the box... until the page gets refreshed again.

Anyone?
CWN is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-23-2006, 12:38 PM Re: $Post Help
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
Move the form processing portion of the script to the top of the page. The html for the page should come last. The problem is that the page is getting rendered before the variables are updated.

N.B. If the rewrite is successful, refreshing the page with the code as is will show the changes.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 07-23-2006, 05:49 PM Re: $Post Help
CWN
CWN's Avatar
Skilled Talker

Posts: 56
Trades: 0
Hi - I tried, it did not work Any other suggestions?
CWN is offline
Reply With Quote
View Public Profile
 
Old 07-23-2006, 06:55 PM Re: $Post Help
CWN
CWN's Avatar
Skilled Talker

Posts: 56
Trades: 0
Someone on MSN fixed the error
CWN is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to $Post Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35453 seconds with 12 queries