Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    take a look at this, and let me know why it doesn't work.

    Im not sure why this isn't working, im being returned when i try to edit a tutorial:

    Warning: Cannot add header information - headers already sent by (output started at c:\phpdev5\www\tms\index.php:17) in c:\phpdev5\www\tms\admin\adminlogin.php on line 26
    Like, i understand the error, but i don't know how to fix it, but keep it working.

    This is the code, of all files that should relate.

    index.php
    PHP Code:
    <?PHP
      $act 
    $_GET['act']; 
      if(!isset(
    $act)) 
      { 
        
    $act "new"//set if there wan't an act 
      

    ?>
    <?php 
    require 'includes/config.inc.php'?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="includes/defaultstyle.css" rel="stylesheet" type="text/css" />
    <title>TheSavior Tuts - Main</title>
    </head>
    <body>
        <table align="center" width="75%" class="default" cellspacing="4" cellpadding="2">
            <tr>
                <td class="default2">
                    <table summary="header" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td width="50%" class="default4">
                                <a class="tlinks" href="index.php">Newest 10</a> | 
                                <a class="tlinks" href="index.php?act=submit">Submit</a> | 
                                <a class="tlinks" href="index.php?act=admin">Administration</a> | 
                            </td>
                            <td width="50%" class="default5">
                                Categories: |
                                <?php // connect to the mysql database server.
                                
    mysql_connect ($dbhost$dbusername$dbuserpass);
                                
    mysql_select_db($dbname) or die(mysql_error());
                                
    $query "SELECT DISTINCT category FROM $tuttable";
                                
    $result mysql_query($query) or die(mysql_error());
                                while (
    $row mysql_fetch_array($result)) 
                                {
                                    echo (
    $row['category']." | ");
                                }
                                
    ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="cont">
                    <table width="98%" cellpadding="0" cellspacing="2" class="t2" summary="title table">
                        <tr>
                            <td class="title" width="568">
                                TheSavior Tuts
                                <hr />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <?
                                
    switch($act
                                { 
                                  case 
    'rand': include('includes/random.inc.php'); break;
                                  case 
    'submit': include('includes/submit.inc.php'); break;
                                  case 
    'admin': include('admin/admin.php'); break;
                                  case 
    'adminlog': include('admin/adminlogin.php'); break; 
                                  default: include(
    'includes/new10.inc.php'); break;
                                } 
                                
    ?>
                            </td>
                        </tr>
                    </table>
                </td>
                <tr>
                    <td align="left">
                        <hr /><br />
                        <a class="blinks" href="index.php?act=rand">Random Tutorial</a> | 
                        Total Tutorials: <b><?php echo mysql_num_rows($result); ?></b>
                    </td>
                </tr>
            </tr>
        </table>
    </body>
    </html>

    admin.php
    PHP Code:
    <form action="index.php?act=adminlog&do=edit" method="post">
    <
    b>Username</b>:<input type="text" name="username" size="20"><br>
    <
    b>Password</b>:<input type="password" name="password" size="20"><br>
    <
    input type="submit" value="Login"></form
    adminlogin.php
    PHP Code:
    <?php
      $do 
    $_GET['do']; 
      if(!isset(
    $do)) 
      { 
        
    $act "edit"//set if there wan't an act 
      

    $_SESSION['login_username'] = $username;
    include 
    "includes/config.inc.php";
    mysql_connect ($dbhost$dbusername$dbuserpass);
    mysql_select_db($dbname) or die(mysql_error());
    $query="SELECT * from $logtable where username='$username' and password='$password'";
    $resultmysql_query($query) or die("Could not execute query: $q." mysql_error());

    if (
    $_SESSION['login_username'] = $username)
            {


                switch(
    $act
                { 
                  case 
    'edit': include('admin/edittuts.php'); break;
                  default: include(
    'edittuts.php'); break;
                } 

            }
    else{
    header("Location: ../index.php?act=admin");
    }
    ?>
    edittuts.php
    PHP Code:
    <?php 
    if( !isset($_SESSION['login_username'])){
    header("Location: index.php?act=admin");
    } else {
    mysql_connect ($dbhost$dbusername$dbuserpass);
    mysql_select_db($dbname) or die(mysql_error());
    $query "SELECT * FROM $tuttable WHERE onoff='0' ORDER BY id DESC";
    $result mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_array($result)) {
     echo 
    "<table style=\"clear: both;\">
        <form action=\"index.php?act=adminlog&do=edit\" method=\"post\">
            <tr>
                <td rowspan=\"2\">
                    <img width=\"40\" height=\"40\" alt=\"preview\" src=\""
    .$row['image']."\" />
                </td>
                <td align=\"center\">
                    Title: <input type=\"text\" name=\"name\" value=\""
    .$row['title']."\" />
                </td>
                <td align=\"center\">
                    Author: <input type=\"text\" name=\"authorname\" value=\""
    .$row['author']."\" />
                </td>
                <td align=\"center\">
                    Tut-URL: <input type=\"text\" name=\"loca\" value=\"viewtut.php?id="
    .$row['id']."\" />
                </td>
                <td align=\"center\" rowspan=\"2\" colspan=\"2\">
                    <select name=\"approve\" id=\"approve\">
                    <option value=\"3\" selected=\"selected\">Edit</option>
                    <option value=\"1\">Approve</option>
                    <option value=\"0\">Leave as is</option>
                    <option value=\"2\">Delete</option>
                    </select>
                    <br />
                    <input type=\"hidden\" name=\"idnum\" value=\""
    .$row['id']."\" />
                    <input type=\"submit\" class=\"submit\" value=\"Go\" />
                    <br />
                    <input type=\"reset\" class=\"submit\" value=\"Reset\" />
                </td>
            </tr>
            <tr>
                <td colspan=\"1\">
                    <textarea name=\"descrip\">"
    .$row['descr']."</textarea>
                </td>
                <td align=\"center\">
                    <input type=\"radio\" name=\"cat\" value=\"Photoshop\" checked/> Photoshop<br />
                    <input type=\"radio\" name=\"cat\" value=\"PHP\" /> PHP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSP\" /> PSP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSE\" /> PSE<br />
                </td>
            </tr>
            <tr>
                <td colspan=\"7\">
                    Preview Location: 
                    <input type=\"text\" value=\""
    .$row['image']."\" name=\"preview\" size=\"55\" />
                </td>
            </tr>
        </form>
    </table>"
    ;
    }
    if (
    $_POST['approve'] == 1) {
         
    // SQL to update row to be active
    } else if ($_POST['approve'] == 2) {
         
    // SQL to delete row
    }  else if ($_POST['approve'] == 3) {
         
    // SQL to update row
         
    $update "UPDATE $tuttable = WHERE ".$row['image']."=".$row['image']."";
        
    mysql_query($update);
    }   
    }  
    ?>

    Can someone make this work?

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Just test if $act is adminlog or anything else that needs to send headers at the top of the page before headers are sent instead of way down in that switch statement.

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    can you explain what to do in more detail...i don't understand.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Any headers that are being passed need to be at the very top of the page above everything else.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, well instead of a header, i could use a instant redirect, correct?

    If so, then what is the code for that?

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No because to do a redirect you need to use location: http://www.blah.com and location needs to be inside of a header function.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, so what can i possibly do, to change my code into something that does the same thing?

  • #8
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #9
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by ralph l mayo
    Just test if $act is adminlog or anything else that needs to send headers at the top of the page before headers are sent instead of way down in that switch statement.
    What he said. include adminlog at the top of the file if $act is adminlog, and take it out of that switch statement.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •