Jump to content

Recommended Posts

I am trying to write a file that contains php in it...it worked fine when the forms action was itself, except that it would write the wrong data to the file, because I was using variables that were used elsewhere in the page. Needless to say, I moved the forms action to it's own personal page, and now it will not open the file to write to it, I am thinking it's because it is in a different directory than the form itself...

 

mcomponents.php (included in the index file via ?func=mcomponents.php)

<?php

echo "<td vAlign='top' align='center'>
<center>This form is to select which components you would like to appear on your page for others to see. For example, if you would not like for anyone other than yourself to view your age, simply choose no, and then submit.<br><br><b>Be sure to set all components!</b></center>
   <form action='components/mcomponents2.php' method='POST'>
      <table border='0' cellpadding='5px' cellspacing='0'>
         <tr>
            <td>
About Me:
            </td>
            <td>
               <select name='aboutme'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Age:
            </td>
            <td>
               <select name='age'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Banner:
            </td>
            <td>
               <select name='banner'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Comments:
            </td>
            <td>
               <select name='comments'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Contact:
            </td>
            <td>
               <select name='contact'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Email:
            </td>
            <td>
               <select name='email'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Friends:
            </td>
            <td>
               <select name='friends'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Interests:
            </td>
            <td>
               <select name='interests'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Name:
            </td>
            <td>
               <select name='name'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Posts:
            </td>
            <td>
               <select name='posts'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Profile Picture:
            </td>
            <td>
               <select name='profilepicture'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Sex:
            </td>
            <td>
               <select name='sex'>
                  <option value='yes'>Yes</option>
                   <option value='no'>No</option>
                </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Sexual Preference:
            </td>
            <td>
               <select name='sexualpref'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Subscription:
            </td>
            <td>
               <select name='subscriptions'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
User Menu:
            </td>
            <td>
               <select name='usermenu'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
Welcome Note:
            </td>
            <td>
               <select name='welcome'>
                  <option value='yes'>Yes</option>
                  <option value='no'>No</option>
               </select>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td>
            </td>
            <td>
            </td>
            <td>
               <input type='submit' name='submit' value='submit' />
            </td>
         </tr>
      </table>
   </form>";

?>

 

mcomponents2.php

<?php

if ($_POST['submit']) {
   $paboutme = $_POST['aboutme'];
   $page = $_POST['age'];
   $pbanner = $_POST['banner'];
   $pcomments = $_POST['comments'];
   $pcontact = $_POST['contact'];
   $pemail = $_POST['email'];
   $pfriends = $_POST['friends'];
   $pinterests = $_POST['interests'];
   $pname = $_POST['name'];
   $pposts = $_POST['posts'];
   $pprofilepicture = $_POST['profilepicture'];
   $psex = $_POST['sex'];
   $psexualpref = $_POST['sexualpref'];
   $psubscriptions = $_POST['subscriptions'];
   $pusermenu = $_POST['usermenu'];
   $pwelcome = $_POST['welcome'];

   $writefile = ("components/list.php");
   $write = "<?php

$aboutme = '" . $paboutme . "';
$age = '" . $page . "';
$banner = '" . $pbanner . "';
$comments = '" . $pcomments . "';
$contact = '" . $pcontact . "';
$email = '" . $pemail . "';
$friends = '" . $pfriends . "';
$interests = '" . $pinterests . "';
$name = '" . $pname . "';
$posts = '" . $pposts . "';
$profilepicture = '" . $pprofilepicture . "';
$sex = '" . $psex . "';
$sexualpref = '" . $psexualpref . "';
$subscriptions = '" . $psubscriptions . "';
$usermenu = '" . $pusermenu . "';
$welcome = '" . $pwelcome . "';

?>";
   $writewrite = fopen($writefile, 'w') or die("Sorry, your components list could not be updated at this time, please try again later<br><br>");
   fwrite($writewrite, $write);
   fclose($writewrite);
   echo "Your components list has been modified.<br><br>";

}

?>

 

How do I get it to open the file?

Link to comment
https://forums.phpfreaks.com/topic/36729-solved-fopen-function-will-not-open-file/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.