Hi all,
I have searched on this and might be missing something. I have a script that echo’s some html if a condition is met. The html is used to submit and move a file, I want to then redirect the page once this has happened. The problem lies with setting header, usually the header is set then php closes and you have your static html. In this case mine is echo’d and putting a header to redirect anywhere gets me the usual errors on headers sent. Here is the code:
[code=php]
<?php
include_once(“../../private/supplierconfig.php”);
checkLoggedIn(“yes”);
error_reporting (E_ALL);
echo “Welcome $username, “;
//Retrieve details from database to start
$id = $_SESSION[‘username’];
$query = “select image1, username from suppliers where username=’$id'”;
//now we pass the query to the database
$result=mysql_query($query, $link) or die(“MySQL query $query failed. Error if any: “.mysql_error());
//get the first (and only) row from the result
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$username=$row[‘username’];
$image1 = $row[‘image1’];
if($image1 !== “”)
{
print ‘You have an image already in this slot. Click the Delete button to clear it, then upload a new one:’;
$string = ‘<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN “http://www.w3.org/TR/html4/strict.dtd”>
<html lang=”en”>
<form name=”form1″ method=”post” action=”deleteimage1.php” enctype=”multipart/form-data”>
<input type=”hidden” name=”delete”>
<p></td><td><input name=”submit” type=”submit” value=”submit”></p>
</table>
</form>’;
echo “$string”;
}
else
{
echo “no image loaded”;
}
if(isset( $submit ) )
{
// exit;
//move image1 to the delete folder.
rename (“files/”.$image1, “temp/”.$image1)
or die (“Could not delete”);
//set image1 back to NULL
$image1 = ‘NULL’;
$query = “UPDATE `suppliers`
SET `image1` = ‘$image1’ WHERE `username` = ‘”. mysql_real_escape_string($_SESSION[‘username’]). “‘
LIMIT 1″;
$result = mysql_query($query, $link) or die(‘Update failed: ‘ . mysql_error());
echo $query;
//print_r($query);
mysql_info($link) ;
if(mysql_affected_rows($link) == 0);
header(“Location: suppliers.php?”.session_name().”=”.session_id());
}
else {
echo “<br><br>”;
exit;
}
?>
Do I still use a header? If so where does it go?
Thanks,
G