You are here: Re: Sessions « PHP Language « IT news, forums, messages
Re: Sessions

Posted by Kathryn Gill on 01/07/06 17:39

this is some of the code

mempic.php


<?php session_start(); ?>
{other code}
<?php

if (isset($_GET['id']))
{
$id = $_GET['id'];
$_SESSION['id'] = $id;
}
else
{
$id = $_SESSION['id'];
}
if (isset($_GET['clan']))
{
$clan = $_GET['clan'];
$_SESSION['clan'] = $clan;
}
else
{
$clan = $_SESSION['clan'];
}
$username='****;
$password='****';
$hostname='****';
$databasename='****';

$mysql_link = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename);


$numresults=mysql_query("SELECT picture FROM ".$clan." WHERE id=".$id."");
$numrows=mysql_num_rows($numresults);
while ($row = mysql_fetch_array($numresults)) {
if ($row{'picture'}==""){
echo "<img width=\"150\" src=\"images/nopic.gif\"><br>";}
else {
echo "<p align=\"left\" class=\"header\">Current Picture: <p align=\"left\"
class=\"header\">";
$pathold=$row{'picture'}
?>
<img width="150" src="../<?php echo $row{'picture'};?>"><p align="left"
class="header">
<?php }}
echo $error;

?>

<p align="left" class="header">
<form action="connectpic.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="pathold" value="<?php echo $pathold; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="hidden" name="clan" value="<?php echo $clan; ?>">
Upload New Photo:<br>
<input type="file" name="picture" size="30"><p align="left" class="header">
<input type="submit" value="Add Photo To Profile" name="submit"> Please
click only once, this may take a while.
</form>

connectpic.php

{other code}
<?php
if ($_FILES["picture"]["name"] == "")
{
if (!($pathold==""))
{
$del="/usr/local/psa/home/vhosts/clan3cho.co.uk/httpdocs/".$pathold;
unlink($del);
}
$update = "UPDATE ".$clan." SET picture='' WHERE id=".$id."";
mysql_query($update,$mysql_link) or die ($clan);
$mysql_insert = mysql_query($update, $mysql_link) or die(failed);
include 'memsub.php';
session_destroy();
}
else
{
if
(file_exists("/usr/local/psa/home/vhosts/clan3cho.co.uk/httpdocs/photos/".$_
FILES['picture']['name']))
{
$error= "<font face=\"Arial\" color=\"Yellow\"><strong>File with name
(".$_FILES['picture']['name'] .") already exists</strong></font><br>";
include 'mempic.php';
}
else
{
copy($_FILES['picture']['tmp_name'],
"/usr/local/psa/home/vhosts/clan3cho.co.uk/httpdocs/photos/".$_FILES['pictur
e']['name']) or die(failed);
$path="photos/".$_FILES['picture']['name']; ?>
<input type="hidden" name="path" value="<?php echo $path ;?>">
<?php
if (!($pathold==""))
{
$del="/usr/local/psa/home/vhosts/clan3cho.co.uk/httpdocs/".$pathold;
unlink($del);
}
$update = "UPDATE ".$clan." SET picture='$path' WHERE id=".$id."";
mysql_query($update,$mysql_link) or die ($clan);
$mysql_insert = mysql_query($update, $mysql_link) or die(failed);
include("memsub.php");
session_destroy();
}

}?>
when the file exists it goes back to mempic.php.. but keeps saying an error
due to session is already started.
Any Ideas how to get round this?

Thanks
Kathryn

"Stefan Rybacki" <stefan.rybacki@gmx.net> wrote in message
news:42a40aF1h6198U1@individual.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Kathryn Gill wrote:
> > Hi Guys,
> > I have a page which has a form, at the begining of the code i have
started a
> > session. When the form is completed, but with an error on it, it will go
> > back to the page with the form on it, with the details that were
submitted.
> > But, it keeps saying cannot start session, as session is already
started.
> > How do i get rid of this error?
> > Thanks
> > Kathryn (Sorry if it makes no sense)
> >
>
> the start_session command has to be called before any output is done.
Output is
> also stuff that is before the first <?php
>
> Regards
> Stefan
>
> >
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1rc2 (MingW32)
>
> iD8DBQFDv9oKyeCLzp/JKjARAhRmAJ0RtZDKEI1tmpImbUJjy7RDiddz6ACgj5fd
> h7oTEKCw/XMSs8PMkHXwGiI=
> =61o5
> -----END PGP SIGNATURE-----

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация