...

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



thesavior
01-06-2006, 05:24 AM
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
$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

<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
$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'";
$result= mysql_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
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?

ralph l mayo
01-06-2006, 06:12 AM
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.

thesavior
01-06-2006, 06:38 AM
can you explain what to do in more detail...i don't understand.

_Aerospace_Eng_
01-06-2006, 06:46 AM
Any headers that are being passed need to be at the very top of the page above everything else.

thesavior
01-06-2006, 06:50 AM
ok, well instead of a header, i could use a instant redirect, correct?

If so, then what is the code for that?

_Aerospace_Eng_
01-06-2006, 06:52 AM
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.

thesavior
01-06-2006, 06:58 AM
ok, so what can i possibly do, to change my code into something that does the same thing?

thesavior
01-08-2006, 02:12 AM
*bump*

ralph l mayo
01-08-2006, 02:17 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum