Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Why does this not work?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Why does this not work?

Postby digitalbloke » Thu Jul 31, 2003 7:26 am

Hi i have a page that has a pull down menu that lists all the files in a chosen directory and that when you click submit it should open an edit box for the chosen file. however i always get a value of "1" for the string "FILE" can anyone help me???

Code: Select all
<?php
if ($_GET['action'] == "") {
?>

<?
//admin passwords
$passwords = "password";
$pw = $passwords;
?>

<center>
<font size="4"><p>Welcome to The Tiger Club Web Page!</p></font>

<?php
if ($password != $pw) {
?>

<font size = 2><p>If you are an administrator of thetigerclub.com you can log 
in to the admin area here using your password and edit the content of the site.
If you have forgotten you password please contact our webmaster (spike) on
<a href="mailto:webmaster@thetigerclub.com">webmaster@thetigerclub.com</a></p>

<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
  <p>Password: <input type="password" name="password" size="20"></p>
  <p><input type="submit" value="Enter the Admin Area" name="B1"></p>
</form>
</font>
</center>

<?
} else {
?>

<p>Welcome to the Admin Area!</p>
</center>
<table border="0" cellpadding="2" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="33%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">edit an existing page</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">
        <form method="POST" action=<? print("http://www.thetigerclub.com/index.php?page=admin&FILE=") . print("$editfile"); ?>&action=edit>
        <input type="hidden" name="password" size="20" value="password">
        <select size="1" name="editfile">
       
        <?php

         $directory = "/freeola/users/8/1/sr0254618/htdocs/pages/";
         if($dir_handle = opendir($directory)){
           while($file = readdir($dir_handle))
           {
             if($file !== "." && $file !== ".."){
               echo ("<option value='" . $file . "'>" . $file . "</option>");
             }
           }
         }
         closedir($dir_handle);
        ?>
        </select>
        <input type="submit" value="Submit" name="Submit">
        </form>
        </font></td>
      </tr>
    </table>
    </td>
    <td width="33%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">create a new page</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">new page</font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">delete an existing page</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">delete page</font></td>
      </tr>
    </table>
    </td>
    <td width="34%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">add new member</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">new member</font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber7">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">remove member</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">remove member</font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber8">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">reset password</font></td>
      </tr>
      <tr>
        <td width="100%"><font size="2">reset password</font></td>
      </tr>
    </table>
    </td>
  </tr>
</table>

<?
}
?>

<?
} else {
}
?>

<?php
if ($_GET['action'] == "edit") {
?>

<?php
if(isset($HTTP_POST_VARS['inputbox'])){
$fc = fopen( "pages/" . $_GET['FILE'] . ".php", 'w' ) or die("Couldnt Open for writing");
flock($fc, LOCK_EX);
fwrite($fc, $HTTP_POST_VARS['inputbox']);
flock($fc, LOCK_UN);
fclose( $fc );
Print("<center>Text Saved</center><p>");
}
$contents = "";
$fp = fopen( "pages/" . $_GET['FILE'] . ".php", 'r' ) or die("Couldnt Open Reader");
                flock($fp, LOCK_SH);
                while (! feof($fp)){
$contents = $contents.fgets( $fp, 1024);
}
                flock($fp, LOCK_UN);
                fclose($fp);
?>
<center>
<form action="http://www.thetigerclub.com/index.php?page=admin&action=edit" method="post">
<input type="hidden" name="password" size="20" value="password">
<TEXTAREA name="inputbox" style="HEIGHT: 200px; WIDTH: 400px" rows="1" cols="20"><? print($contents); ?></TEXTAREA><P>
<input type="submit" value="Submit"></center>
</form>
</center>

<?
} else {
}
?>


Thanks for your help!!!

You guys always sort me out!!!


Digitalbloke
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am

Postby Virtuoso » Thu Jul 31, 2003 8:13 am

you have:
Code: Select all
if($file !== "." && $file !== "..")


im not sure but isn't it:
Code: Select all
if($file != "." && $file != "..")


maybe !== is right, but i dunno cause i never seen it b4.
User avatar
Virtuoso
php-forum Active User
php-forum Active User
 
Posts: 268
Joined: Mon Jul 21, 2003 7:05 am

Postby digitalbloke » Thu Jul 31, 2003 8:19 am

erm,,,, does not make a difference the pull down finds all the files like i need it to its the sending of the string that does not work it should send the value selected from the pull down but sends 1 instead :(
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am

Postby Joel » Thu Jul 31, 2003 9:22 pm

Code: Select all
         
if($dir_handle = opendir($directory)){
           while($file = readdir($dir_handle))
           {
             if($file !== "." && $file !== ".."){
               echo "<option value=\"". $file ."\">" . $file . "</option>;
             }
           }


Try that.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby digitalbloke » Thu Jul 31, 2003 11:21 pm

i still get the same error :(
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am

Postby digitalbloke » Thu Jul 31, 2003 11:43 pm

i have made a few amendments. and what i dont understand is that i copied the pull down script for the delete file and it works fine!!! but $editfile which should be file names always ends up as "1"

thanks again!

Code: Select all
<?
//admin passwords
$passwords = "password";
$pw = $passwords;
?>

<center>
<font size="4"><p>Welcome to The Tiger Club Web Page!</p></font>

<?php if ($password == $pw) { ?>

<?php if ($_GET['action'] == "") { ?>

<p>Welcome to the Admin Area!</p>

<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
<input type="submit" value="Log Out">
</form>

</center>
<table border="0" cellpadding="2" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="33%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">edit an existing page</font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">
        <form method="POST" action="http://www.thetigerclub.com/index.php?page=admin&action=edit">
        <input type="hidden" name="password" size="20" value="password">
        <select size="1" name="editfile">
        <!-- <option selected="&blank&">&blank&</option> -->
        <!-- <option selected="home.txt">home.txt</option> -->

        <?php

         $directory = "/freeola/users/8/1/sr0254618/htdocs/pages/";
         if($dir_handle = opendir($directory)){
           while($file = readdir($dir_handle))
           {
             if($file !== "." && $file !== ".."){
               echo ("<option value='" . $file . "'>" . $file . "</option>");
             }
           }
         }
         closedir($dir_handle);
        ?>
        </select> <br>
        <input type="submit" value="Delete Page" name="Submit">
        </form>
        </font></td>
      </tr>
    </table>
    </td>
    <td width="33%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">
        Create A New Page
        </font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">
        <form method="POST" action="http://www.thetigerclub.com/index.php?page=admin&action=newpage">
          <input type="hidden" name="password" size="20" value="password">
          <p> <input type="text" name="newfile" size="20"><br>
          <input type="submit" value="Create New Page" name="B1"></p>
        </form>
        </font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">delete an existing page</font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">
        <form method="POST" action="http://www.thetigerclub.com/index.php?page=admin&action=delete">
        <input type="hidden" name="password" size="20" value="password">
        <select size="1" name="deletefile">
        <!-- <option selected="&blank&">&blank&</option> -->
        <!-- <option selected="home.txt">home.txt</option> -->

        <?php

         $directory = "/freeola/users/8/1/sr0254618/htdocs/pages/";
         if($dir_handle = opendir($directory)){
           while($file = readdir($dir_handle))
           {
             if($file !== "." && $file !== ".."){
               echo ("<option value='" . $file . "'>" . $file . "</option>");
             }
           }
         }
         closedir($dir_handle);
        ?>
        </select> <br>
        <input type="submit" value="Delete Page" name="Submit">
        </form>
   </font></td>
      </tr>
    </table>
    </td>
    <td width="34%" valign="top">
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">add new member</font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">new member</font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber7">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">remove member</font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">remove member</font></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber8">
      <tr>
        <td width="100%">&</td>
      </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5">
      <tr>
        <td width="100%" bgcolor="#800000">
        <p align="center"><font color="#FFFFFF" size="2">reset password</font></td>
      </tr>
      <tr>
        <td width="100%" align="center"><font size="2">reset password</font></td>
      </tr>
    </table>
    </td>
  </tr>
</table>

<? } else { ?>
<? } ?>

<?php if ($_GET['action'] == "newpage") { ?>

<? !fopen($path . 'pages/'. $newfile . ".php", "w") ?>
Page created!<br>File Name: <? print($newfile) ?>.php
<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
<input type="hidden" name="password" size="20" value="password">
<input type="submit" value="Return to Admin Area">
</form>

<? } else { ?>
<? } ?>

<?php if ($_GET['action'] == "edit") { ?>

<?php
if(isset($HTTP_POST_VARS['inputbox'])){
$fc = fopen( "pages/" . print($editfile), 'w' ) or die("Couldnt Open for writing");
flock($fc, LOCK_EX);
fwrite($fc, $HTTP_POST_VARS['inputbox']);
flock($fc, LOCK_UN);
fclose( $fc );
Print("<center>Text Saved</center><p>");
}
$contents = "";
$fp = fopen( "pages/" . print($editfile), 'r' ) or die("Couldnt Open Reader");
                flock($fp, LOCK_SH);
                while (! feof($fp)){
$contents = $contents.fgets( $fp, 1024);
}
                flock($fp, LOCK_UN);
                fclose($fp);
?>
<center>
<font size="4"><p>Edit Existing File: <? print($editfile) ?></p></font>
<font size = 2>
<p>Once you have made your changes to <? print($editfile) ?> then
simply click the save changes button below.<p>
<p>If however you wish not to make the changes click cancel.</p>
</font>
<form action="http://www.thetigerclub.com/index.php?page=admin&action=edit&FILE=<? print($editfile) ?>" method="post">
<input type="hidden" name="password" size="20" value="password">
<TEXTAREA name="inputbox" style="HEIGHT: 200px; WIDTH: 100%" rows="1" cols="20" wrap=off><? print($contents); ?></TEXTAREA><P>
<input type="submit" value="Submit">
</form>
<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
<input type="hidden" name="password" size="20" value="password">
<input type="submit" value="Cancel">
</form>
</center>

<? } else { ?>
<? } ?>

<?php if ($_GET['action'] == "delete") { ?>

<? !unlink("pages/" . $deletefile) ?>
Page Deleted!<br>File Name: <? print($deletefile) ?>
<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
<input type="hidden" name="password" size="20" value="password">
<input type="submit" value="Return to Admin Area">
</form>

<? } else { ?>
<? } ?>










<? } else { ?>

<font size = 2><p>If you are an administrator of thetigerclub.com you can log 
in to the admin area here using your password and edit the content of the site.
If you have forgotten you password please contact our webmaster (spike) on
<a href="mailto:webmaster@thetigerclub.com">webmaster@thetigerclub.com</a></p>

<form method="POST" action="http://www.thetigerclub.com/index.php?page=admin">
  <p>Password: <input type="password" name="password" size="20"></p>
  <p><input type="submit" value="Enter the Admin Area" name="B1"></p>
</form>
</font>
</center>

<? } ?>
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.