Jump to content

Switched servers and now getting bugs with code


tcpbryson

Recommended Posts

I'm more of a php hobbiest having learned most of what I use from experimenting on our page.  I just switched servers from Total choice hosting to Godaddy and now some of my functions are not working.  The 2 biggest are:

 

On our where to play page the default that loads is our All page and that works but then people are supposed to be allowed to change types at the top and then hit select and pull up that page.  The function loads up the folder properly but when you press Select City it just reloads the All page. 

 

I still have access to the old server till the end of the month in order to get files and anything else that I may have forgotten to copy over.  Is there maybe a php file I should have brought over and forgot?  The other big difference I noticed my old page was stored in public_html the new one is stored in the root directory.  The page was originally created outside and I have maintained it for the last 5 years so I have been following behind the old code and didn't do the foundation myself.

 

Thank you for any help you can give.

 

The Code I have for these functions is:

<?php

 

echo "<form method=POST action=$PHP_SELF>

      <select name=\"selected_city\">

      <option value=\"\"></option>";

 

//check files in directory

if ($handle = opendir('locations/')) {

  while (false !== ($file = readdir($handle))) {

      if ($file != "." && $file != "..") {

          echo $file;

          $file = substr($file, 0, -4);

          echo "<option value=" . $file . ">$file</option>";

      }

  }

  closedir($handle);

}

?>

  </select>

  <input type="submit" name="submit" value="Select City" />

  </form>

   

  <?php

 

DEFINE('LOG_DIR', $_SERVER['DOCUMENT_ROOT'].'/locations/');

//if this is the first visit to this page, display the default city.

if ($submit){

    if($_POST['selected_city'] == ""){

        echo "<p>No city selected, please try again.</p>";

        exit;

    }

    $selected_city = $_POST['selected_city'];

}

else{

    //default city - must match csv filename exactly prior to appending extension

    $selected_city = "All";

}

 

 

echo "<p>$selected_city</p>";

$filename = $selected_city . ".csv";

$file = file(LOG_DIR.$filename);

 

?>

 

 

The other big announce is that our front page has a news feed that I update through another page that edits and deletes and adds to the notepad file that is read by the front page.  I have the notepad files permissions set to 777 but when I use the update it doesn't do anything.  The code for this page is:

 

<?php include "header.php" ?>

      <td width="75%" id="maincontain" class="main">

<?php include "adminbar.php" ?>

<hr />

<?php

if($action == "edit" && isset($HTTP_POST_VARS['password'])) {

    if($HTTP_POST_VARS['password'] == "gonews") {

        //Recompile that line with the pipe symbols so we can reinsert it

        $line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['title'];

        $line .= "|" . $HTTP_POST_VARS['news'];

        $line = str_replace("\r\n","<BR>",$line);

        $line .= "\r\n";

        $line = stripslashes($line);

        $data = file('news.txt');

        $data[$id] = $line;

        //the next line makes sure the $data array starts at the beginning

        reset($data);

        //now we open the file with mode 'w' which truncates the file

        $fp = fopen('news.txt','w');

        foreach($data as $element) {

            fwrite($fp, $element);

        }

        fclose($fp);

        echo "Item Edited!<BR><BR>\n";

        echo "<a href=\"$PHP_SELF\">Go Back</a>\n";

        exit;

    } else {

        echo "Bad password!\n";

        exit;

    }

}

if($action == "edit") {

    $data = file('news.txt');

    $element = trim($data[$id]);

    $pieces = explode("|", $element);

    //the next line is to reverse the process of turning the end of lines into breaking returns

    $news = str_replace("<BR>","\r\n",$pieces[2]);

    echo "Make the changes you would like and press save.<BR>\n";

    echo "<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";

    echo "Title:<BR>\n";

    echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"title\" value=\"".$pieces[1]."\"><BR>\n";

    echo "The News:<BR>\n";

    echo "<TEXTAREA NAME=\"news\" COLS=\"40\" ROWS=\"5\">".$news."</TEXTAREA><BR><BR>\n";

    echo "Password:<BR>\n";

    echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";

    echo "<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";

    echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";

    echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";

    echo "</FORM>\n";

    exit;

}

if($action == "delete" && isset($HTTP_POST_VARS['password'])) {

    if($HTTP_POST_VARS['password'] == "nonews") {

        $data = file('news.txt');

        //this next line will remove the single news item from the array

        array_splice($data,$id,1);

        //now we open the file with mode 'w' which truncates the file

        $fp = fopen('news.txt','w');

        foreach($data as $element) {

            fwrite($fp, $element);

        }

        fclose($fp);

        echo "Item deleted!<BR><BR>\n";

        echo "<a href=\"$PHP_SELF\">Go Back</a>\n";

        exit;

    } else {

        echo "Bad password!\n";

        exit;

    }

}

if($action == "delete") {

    echo "<H2>You are about to delete the following news item.</H2>\n";

    $data = file('news.txt');

    $element = trim($data[$id]);

    $pieces = explode("|", $element);

    echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";

    echo "<BR><BR>\n";

    echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>\n";

    echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";

    echo "Password:<BR>\n";

    echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";

    echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";

    echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";

    echo "</FORM>\n"; ?>

        </td>

    </tr>

</table>

<br />

<?php

    include "footer.php";

    exit;

}

?>

<?php

$data = file('news.txt');

//next line removed to make everything else easier in the admin script

//$data = array_reverse($data);

foreach($data as $key=>$element) {

    $element = trim($element);

    $pieces = explode("|", $element);

    echo "<strong>" . $pieces[1] . "</strong> - <font color=\"DF9D00\" size=\"1\">" . $pieces[0] . "</font><BR>" . $pieces[2]  . "<br /><br />";

    echo " <a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";

    echo " <a href=\"$PHP_SELF?action=edit&id=$key\">Edit</a>\n";

    echo "<hr><BR>\n";

}

echo "<HR>\n";

echo "<H4><u>Add News</u></H4>\n";

if($HTTP_POST_VARS['submit']) {

    if($HTTP_POST_VARS['password'] == 'gonews') {

        if(!$HTTP_POST_VARS['title']) {

            echo "You must enter a Title";

            exit;

        }

        if(!$HTTP_POST_VARS['news']) {

            echo "You must enter some news";

            exit;

        }

        if(strstr($HTTP_POST_VARS['title'],"|")) {

            echo "Title cannot contain the pipe symbol - |";

            exit;

        }

        if(strstr($HTTP_POST_VARS['news'],"|")) {

            echo "News cannot contain the pipe symbol - |";

            exit;

        }

        $fp = fopen('news.txt','a');

        if(!$fp) {

            echo "Error opening file!";

            exit;

        }

        $line = date("m.d.y") . "|" . $HTTP_POST_VARS['title'];

        $line .= "|" . $HTTP_POST_VARS['news'];

        $line = str_replace("\r\n","<BR>",$line);

        $line .= "\r\n";

        $line = stripslashes($line);

        fwrite($fp, $line);

        if(!fclose($fp)) {

            echo "Error closing file!";

            exit;

        }

        echo "<b>News added!</b>\n";

    } else {

        echo "Bad Password";

    }

}

 

?>

          <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">

          Your Title:<BR>

          <INPUT TYPE="text" SIZE="30" NAME="title"><BR>

          The News:<BR>

          <TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>

          News Password:<BR>

          <INPUT TYPE="password" SIZE="30" NAME="password"><BR>

          <INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>

          </FORM>

 

        </td>

 

<?php include "footer.php" ?>

 

Link to comment
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.