By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

problems using copy() and rename()

P: n/a
Im trying to move a file but am having luck
my code is below. The temp and target paths are valid as they echo
correctly. but I cant get the copy() function to work, or the rename()
function

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);

echo "Target - ".$target_path." Temp - ".$temp_path."<br>";

copy($temp_path, $target_path);

has any one experienced this problem?

Ian

Oct 21 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a

"mantrid" <ia********@virgin.netwrote in message
news:%7*************@newsfe5-win.ntli.net...
Im trying to move a file but am having luck
my code is below. The temp and target paths are valid as they echo
correctly. but I cant get the copy() function to work, or the rename()
function

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);

echo "Target - ".$target_path." Temp - ".$temp_path."<br>";

copy($temp_path, $target_path);

has any one experienced this problem?
are you receiving any error if so what is it? Also if it is as it looks and
is a file that has been uploaded then why not use the move_uploaded_file()
function.
Oct 21 '06 #2

P: n/a

"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>
"mantrid" <ia********@virgin.netwrote in message
news:%7*************@newsfe5-win.ntli.net...
Im trying to move a file but am having luck
my code is below. The temp and target paths are valid as they echo
correctly. but I cant get the copy() function to work, or the rename()
function

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);

echo "Target - ".$target_path." Temp - ".$temp_path."<br>";

copy($temp_path, $target_path);

has any one experienced this problem?

are you receiving any error if so what is it? Also if it is as it looks
and
is a file that has been uploaded then why not use the move_uploaded_file()
function.

I tried with the move_uploaded_file() originally but this didnt work
either. I thought maybe it only works initially with $_FILES as I understand
it checks that a file has been uploaded and returns negative if it cant find
one.
Ther is no error message it appears to work as my success message is
displayed but the file is not there
Oct 21 '06 #3

P: n/a

"mantrid" <ia********@virgin.netwrote in message
news:eU*******************@newsfe6-gui.ntli.net...
>
"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...

"mantrid" <ia********@virgin.netwrote in message
news:%7*************@newsfe5-win.ntli.net...
Im trying to move a file but am having luck
my code is below. The temp and target paths are valid as they echo
correctly. but I cant get the copy() function to work, or the rename()
function
>
$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);
>
echo "Target - ".$target_path." Temp - ".$temp_path."<br>";
>
copy($temp_path, $target_path);
>
has any one experienced this problem?
>


are you receiving any error if so what is it? Also if it is as it looks
and
is a file that has been uploaded then why not use the
move_uploaded_file()
function.

I tried with the move_uploaded_file() originally but this didnt work
either. I thought maybe it only works initially with $_FILES as I
understand
it checks that a file has been uploaded and returns negative if it cant
find
one.
Ther is no error message it appears to work as my success message is
displayed but the file is not there

Here is the full code. as you can see ive commented out much of it to try
and narrow down the problem. Ive used an echo to check that the session
variables are valid. but the file just will not move

$userid=$_SESSION[userid];
$delquest=$_SESSION[delquest];
$archivequest=$_SESSION[archivequest];
$changedquests=$_SESSION[changed];
$questids=$_SESSION[questids];
$imagechanged=$_SESSION[imagechanged];
$delimage=$_SESSION['delimage'];
$msg=$_SESSION['msg'];
$uploadedfile=$_SESSION['uploadedfile'];
$imagepath=$_SESSION['imagepath'];
$questuserid=$_SESSION[questuserid];
$imagequestindex=$_SESSION[imagequestindex];

if(count($imagechanged)>0){
$targetdir = "pupiltester/";
$tempdir= "temp/";
$allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
for ($x = 0; $x < count($imagequestindex); $x++){
if(!empty($uploadedfile["name"][$x])){

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);
$imagefile=$imagepath[$x];
echo "Userid - ".$questuserid[$x]." Target - ".$target_path." Temp -
".$temp_path." To replace - ".$imagefile."<br>";
copy("$temp_path", "$target_path");
//if($uploadedfile["size"][$x] < 35841) {
//if(preg_match("/\." . $allowed_file_types . "$/i",
$uploadedfile["name"][$x])) {
if(file_exists($target_path)){
//if($questuserid[$x]=$userid){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($tar getdir.$imagefile);}
//$msg.="<br><span class='greenbody'>Link formed to your existing
file by the name of ".$uploadedfile["name"][$x].".</span>";
//}else{
//$msg.="<br><span class='RedWarning'>A image by the name of
".$uploadedfile["name"][$x]." already exists for another users question.
Please rename it and try again.</span>";
//}
}else{
rename($temp_path, $target_path);
//if(move_uploaded_file($temp_path, $target_path)){
//$msg.="<br><span class='greenbody'>Uploaded the image
".$uploadedfile["name"][$x]." (" .$uploadedfile["type"][$x]. ",
".ceil($uploadedfile["size"][$x] / 1024) . " Kb).</span>";
//if($uploadedfile['name'][$x]!==''){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($tar getdir.$imagefile);}
//}
//}else{
//$msg.="<br><span class='Red Warning'>Error uploading image -
".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."</span>";
//}
}
//}else{
//$msg.="<br><span
class='RedWarning'>".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."
not uploaded. Not a valid image file.</span>";
//}
//}else{
//$msg.="<br><span class='RedWarning'>".$uploadedfile['name'][$x]." is
greater than 35Kb.</span>";
//}
}
}
//$_SESSION['msg']=$msg;
//echo("<br><br><div align='center'>".$msg."<br><br><a
href='usersquestions.php' class='BodyLink'>Return</a></div>");
}

Oct 21 '06 #4

P: n/a

"mantrid" <ia********@virgin.netwrote in message
news:kZ*******************@newsfe6-gui.ntli.net...
>
"mantrid" <ia********@virgin.netwrote in message
news:eU*******************@newsfe6-gui.ntli.net...

"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>
"mantrid" <ia********@virgin.netwrote in message
news:%7*************@newsfe5-win.ntli.net...
Im trying to move a file but am having luck
my code is below. The temp and target paths are valid as they echo
correctly. but I cant get the copy() function to work, or the
rename()
function

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);

echo "Target - ".$target_path." Temp - ".$temp_path."<br>";

copy($temp_path, $target_path);

has any one experienced this problem?

>

are you receiving any error if so what is it? Also if it is as it
looks
and
is a file that has been uploaded then why not use the
move_uploaded_file()
function.
>
>
I tried with the move_uploaded_file() originally but this didnt work
either. I thought maybe it only works initially with $_FILES as I
understand
it checks that a file has been uploaded and returns negative if it cant
find
one.
Ther is no error message it appears to work as my success message is
displayed but the file is not there

Here is the full code. as you can see ive commented out much of it to try
and narrow down the problem. Ive used an echo to check that the session
variables are valid. but the file just will not move

$userid=$_SESSION[userid];
$delquest=$_SESSION[delquest];
$archivequest=$_SESSION[archivequest];
$changedquests=$_SESSION[changed];
$questids=$_SESSION[questids];
$imagechanged=$_SESSION[imagechanged];
$delimage=$_SESSION['delimage'];
$msg=$_SESSION['msg'];
$uploadedfile=$_SESSION['uploadedfile'];
$imagepath=$_SESSION['imagepath'];
$questuserid=$_SESSION[questuserid];
$imagequestindex=$_SESSION[imagequestindex];

if(count($imagechanged)>0){
$targetdir = "pupiltester/";
$tempdir= "temp/";
$allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
for ($x = 0; $x < count($imagequestindex); $x++){
if(!empty($uploadedfile["name"][$x])){

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);
$imagefile=$imagepath[$x];
echo "Userid - ".$questuserid[$x]." Target - ".$target_path."
Temp -
".$temp_path." To replace - ".$imagefile."<br>";
copy("$temp_path", "$target_path");
//if($uploadedfile["size"][$x] < 35841) {
//if(preg_match("/\." . $allowed_file_types . "$/i",
$uploadedfile["name"][$x])) {
if(file_exists($target_path)){
//if($questuserid[$x]=$userid){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE
ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($tar getdir.$imagefile);}
//$msg.="<br><span class='greenbody'>Link formed to your existing
file by the name of ".$uploadedfile["name"][$x].".</span>";
//}else{
//$msg.="<br><span class='RedWarning'>A image by the name of
".$uploadedfile["name"][$x]." already exists for another users question.
Please rename it and try again.</span>";
//}
}else{
rename($temp_path, $target_path);
//if(move_uploaded_file($temp_path, $target_path)){
//$msg.="<br><span class='greenbody'>Uploaded the image
".$uploadedfile["name"][$x]." (" .$uploadedfile["type"][$x]. ",
".ceil($uploadedfile["size"][$x] / 1024) . " Kb).</span>";
//if($uploadedfile['name'][$x]!==''){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE
ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($tar getdir.$imagefile);}
//}
//}else{
//$msg.="<br><span class='Red Warning'>Error uploading image -
".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."</span>";
//}
}
//}else{
//$msg.="<br><span
class='RedWarning'>".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."
not uploaded. Not a valid image file.</span>";
//}
//}else{
//$msg.="<br><span class='RedWarning'>".$uploadedfile['name'][$x]."
is
greater than 35Kb.</span>";
//}
}
}
//$_SESSION['msg']=$msg;
//echo("<br><br><div align='center'>".$msg."<br><br><a
href='usersquestions.php' class='BodyLink'>Return</a></div>");
}
OK ive played around with it and have found the following

THIS DOESNT WORK

$targetdir = "pupiltester/";
$tempdir= "temp/";

$target_path = $targetdir."Arm.jpg";
$temp_path = $tempdir."Arm.jpg";
rename($temp_path, $target_path);

BUT THIS DOES

$target_path = "pupiltester/Arm.jpg";
$temp_path = "temp/Arm.jpg";
rename($temp_path, $target_path);

I cant see it am I being completely thick and missing something obvious
Oct 21 '06 #5

P: n/a
OK ive played around with it and have found the following

THIS DOESNT WORK

$targetdir = "pupiltester/";
$tempdir= "temp/";

$target_path = $targetdir."Arm.jpg";
$temp_path = $tempdir."Arm.jpg";
rename($temp_path, $target_path);

BUT THIS DOES

$target_path = "pupiltester/Arm.jpg";
$temp_path = "temp/Arm.jpg";
rename($temp_path, $target_path);

I cant see it am I being completely thick and missing something obvious
that is mighty strange because essentially they are the same thing. Have you
tried using full path's instead of relative paths?
Oct 21 '06 #6

P: n/a

"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>
>OK ive played around with it and have found the following

THIS DOESNT WORK

$targetdir = "pupiltester/";
$tempdir= "temp/";

$target_path = $targetdir."Arm.jpg";
$temp_path = $tempdir."Arm.jpg";
rename($temp_path, $target_path);

BUT THIS DOES

$target_path = "pupiltester/Arm.jpg";
$temp_path = "temp/Arm.jpg";
rename($temp_path, $target_path);

I cant see it am I being completely thick and missing something obvious

that is mighty strange because essentially they are the same thing. Have
you tried using full path's instead of relative paths?
also just to further on my previous post.

Is there a reason you are storing the paths in the session? just seems a
strange thing to do. Are they changing depending on the user.

Regarding not receiving an error ensure you have the following at the top of
your script:-

error_reporting(E_ALL);

It is possible that the errors are being supressed for some reason (possibly
the default error reporting level in the php.ini file set too low)
Oct 21 '06 #7

P: n/a

"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>
"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
OK ive played around with it and have found the following

THIS DOESNT WORK

$targetdir = "pupiltester/";
$tempdir= "temp/";

$target_path = $targetdir."Arm.jpg";
$temp_path = $tempdir."Arm.jpg";
rename($temp_path, $target_path);

BUT THIS DOES

$target_path = "pupiltester/Arm.jpg";
$temp_path = "temp/Arm.jpg";
rename($temp_path, $target_path);

I cant see it am I being completely thick and missing something obvious
that is mighty strange because essentially they are the same thing. Have
you tried using full path's instead of relative paths?

also just to further on my previous post.

Is there a reason you are storing the paths in the session? just seems a
strange thing to do. Are they changing depending on the user.
The paths are not used directly after the form they are created on is
posted. A page detailing the changes to be made is shown first and only when
the user clicks continue does the file with the rename function open Hence
the use of sessions to carry everything forward.

Regarding not receiving an error ensure you have the following at the top
of
your script:-

error_reporting(E_ALL);
That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest' in
.......

seems to be picking up all my variables ie in the above example
$archivequest do you know how to clear these type of notices?
It is possible that the errors are being supressed for some reason
(possibly
the default error reporting level in the php.ini file set too low)
It doesn't seem to affect other error messages. it is strange that it is
only happening in this case.
I have been doing some work on this page all day Ive just

put
$targetdir = "pupiltester/";
$tempdir= "temp/";

back in. And now it works. Dont know what I did but its ok now.

Oct 21 '06 #8

P: n/a
That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest' in
......

seems to be picking up all my variables ie in the above example
$archivequest do you know how to clear these type of notices?
had a quick look over your code and the reason for those errors are as
follows:-

you have lines such as:-

$archivequest=$_SESSION[archivequest];

it should be:-

$archivequest=$_SESSION['archivequest'];

because you do not have the quotes around them it is assuming they are
constants but as no constant is there it is using it as a string. This will
not always be the desired effect. Try and work with the error reporting
level that I already mentioned and it will cut down on alot of possible bugs
in your code.
Oct 21 '06 #9

P: n/a

"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>
That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest'
in
......

seems to be picking up all my variables ie in the above example
$archivequest do you know how to clear these type of notices?

had a quick look over your code and the reason for those errors are as
follows:-

you have lines such as:-

$archivequest=$_SESSION[archivequest];

it should be:-

$archivequest=$_SESSION['archivequest'];

because you do not have the quotes around them it is assuming they are
constants but as no constant is there it is using it as a string. This
will
not always be the desired effect. Try and work with the error reporting
level that I already mentioned and it will cut down on alot of possible
bugs
in your code.

That seems to have done it all except these ones

Notice: Undefined index: cancel in
/home/iddsoftw/public_html/questiondbase/questionupdate.php on line 11

Warning: Cannot modify header information - headers already sent by (output
started at /home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line 17
refering to the top of my page (below)
<?php
session_start();
error_reporting(E_ALL); //show all errors

ini_set( "session.bug_compat_warn", "off" );

if(!isset($_SESSION['userid'])){
header("Location: http://www.site.co.uk/forbidden.html");
}

$cancel=$_POST['cancel'];
if(isset($cancel)){
header("Location: http://www.site.co.uk/path/my.php");
}else{
header("Cache-control: private"); //IE 6 Fix
include("../include/idd.php");

?>
<html>
<head>

<link href="../CSS/body.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$userid=$_SESSION['userid'];
$delquest=$_SESSION['delquest'];
$archivequest=$_SESSION['archivequest'];
$changedquests=$_SESSION['changed'];
$questids=$_SESSION['questids'];
$imagechanged=$_SESSION['imagechanged'];
$delimage=$_SESSION['delimage'];
$msg=$_SESSION['msg'];
$uploadedfile=$_SESSION['uploadedfile'];
$imagepath=$_SESSION['imagepath'];
$questuserid=$_SESSION['questuserid'];
$imagequestindex=$_SESSION['imagequestindex'];

$targetdir = "pupiltester/";
$tempdir= "temp/";
CODE HERE

unset($_SESSION['delquest']);
unset($_SESSION['archivequest']);
unset($_SESSION['changed']);
unset($_SESSION['questids']);
unset($_SESSION['iseditable']);
unset($_SESSION['imagechanged']);
unset($_SESSION['uploadedfile']);
unset($_SESSION['cost']);
unset($_SESSION['question']);
unset($_SESSION['opta']);
unset($_SESSION['optb']);
unset($_SESSION['optc']);
unset($_SESSION['optd']);
unset($_SESSION['opte']);
unset($_SESSION['ans1']);
unset($_SESSION['ans2']);
unset($_SESSION['ans3']);
unset($_SESSION['ans4']);
unset($_SESSION['ans5']);
unset($_SESSION['ans6']);
unset($_SESSION['ans7']);
unset($_SESSION['ans8']);
unset($_SESSION['ans9']);
unset($_SESSION['ans10']);
unset($_SESSION['msg']);
unset($_SESSION['delimage']);
unset($_SESSION['imagepath']);
unset($_SESSION['imagequestindex']);
?>
</body>
</html>
<?php
}
?>
Oct 22 '06 #10

P: n/a
mantrid wrote:
"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>>>That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest'

in
>>>......

seems to be picking up all my variables ie in the above example
$archivequest do you know how to clear these type of notices?

had a quick look over your code and the reason for those errors are as
follows:-

you have lines such as:-

$archivequest=$_SESSION[archivequest];

it should be:-

$archivequest=$_SESSION['archivequest'];

because you do not have the quotes around them it is assuming they are
constants but as no constant is there it is using it as a string. This

will
>>not always be the desired effect. Try and work with the error reporting
level that I already mentioned and it will cut down on alot of possible

bugs
>>in your code.



That seems to have done it all except these ones

Notice: Undefined index: cancel in
/home/iddsoftw/public_html/questiondbase/questionupdate.php on line 11

Warning: Cannot modify header information - headers already sent by (output
started at /home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line 17
refering to the top of my page (below)
<?php
session_start();
error_reporting(E_ALL); //show all errors

ini_set( "session.bug_compat_warn", "off" );

if(!isset($_SESSION['userid'])){
header("Location: http://www.site.co.uk/forbidden.html");
}

$cancel=$_POST['cancel'];
if(isset($cancel)){
header("Location: http://www.site.co.uk/path/my.php");
}else{
<snip>

It's saying $_POST['cancel'] isn't set, so the statement

$cancel=$_POST['cancel'];

is referencing a key ('cancel') which doesn't exist.

It should be something like:

if ($isset($_POST['cancel']) {
header("Location: http://www.site.co.uk/path/my.php");
}
else {
....

The "headers already sent" error error is because of the first error
message.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 22 '06 #11

P: n/a
Thanks thats solved it.
I read somewhere you should assign posted info to variables at the top of
the script so that it will make managing the code easier. Hence my
$cancel=$_POST['cancel'];
is this not the case?

Ian

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:8p******************************@comcast.com. ..
mantrid wrote:
"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>>That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest'
in
>>......

seems to be picking up all my variables ie in the above example
$archivequest do you know how to clear these type of notices?

had a quick look over your code and the reason for those errors are as
follows:-

you have lines such as:-

$archivequest=$_SESSION[archivequest];

it should be:-

$archivequest=$_SESSION['archivequest'];

because you do not have the quotes around them it is assuming they are
constants but as no constant is there it is using it as a string. This
will
>not always be the desired effect. Try and work with the error reporting
level that I already mentioned and it will cut down on alot of possible
bugs
>in your code.


That seems to have done it all except these ones

Notice: Undefined index: cancel in
/home/iddsoftw/public_html/questiondbase/questionupdate.php on line 11

Warning: Cannot modify header information - headers already sent by
(output
started at
/home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line
17


refering to the top of my page (below)
<?php
session_start();
error_reporting(E_ALL); //show all errors

ini_set( "session.bug_compat_warn", "off" );

if(!isset($_SESSION['userid'])){
header("Location: http://www.site.co.uk/forbidden.html");
}

$cancel=$_POST['cancel'];
if(isset($cancel)){
header("Location: http://www.site.co.uk/path/my.php");
}else{
<snip>

It's saying $_POST['cancel'] isn't set, so the statement

$cancel=$_POST['cancel'];

is referencing a key ('cancel') which doesn't exist.

It should be something like:

if ($isset($_POST['cancel']) {
header("Location: http://www.site.co.uk/path/my.php");
}
else {
...

The "headers already sent" error error is because of the first error
message.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 22 '06 #12

P: n/a
mantrid wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:8p******************************@comcast.com. ..
>>mantrid wrote:
>>>"peter" <su****@flexiwebhost.comwrote in message
news:eh**********@aioe.org...
>That has thrown up lots of notices, most of which are of the type:
>Notice: Use of undefined constant archivequest - assumed 'archivequest'

in
>......
>
>seems to be picking up all my variables ie in the above example
>$archivequest do you know how to clear these type of notices?

had a quick look over your code and the reason for those errors are as
follows:-

you have lines such as:-

$archivequest=$_SESSION[archivequest];

it should be:-

$archivequest=$_SESSION['archivequest'];

because you do not have the quotes around them it is assuming they are
constants but as no constant is there it is using it as a string. This

will
not always be the desired effect. Try and work with the error reporting
level that I already mentioned and it will cut down on alot of possible

bugs
in your code.


That seems to have done it all except these ones

Notice: Undefined index: cancel in
/home/iddsoftw/public_html/questiondbase/questionupdate.php on line 11

Warning: Cannot modify header information - headers already sent by

(output
>>>started at

/home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
>>>in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line

17
>>>
refering to the top of my page (below)
<?php
session_start();
error_reporting(E_ALL); //show all errors

ini_set( "session.bug_compat_warn", "off" );

if(!isset($_SESSION['userid'])){
header("Location: http://www.site.co.uk/forbidden.html");
}

$cancel=$_POST['cancel'];
if(isset($cancel)){
header("Location: http://www.site.co.uk/path/my.php");
}else{

<snip>

It's saying $_POST['cancel'] isn't set, so the statement

$cancel=$_POST['cancel'];

is referencing a key ('cancel') which doesn't exist.

It should be something like:

if ($isset($_POST['cancel']) {
header("Location: http://www.site.co.uk/path/my.php");
}
else {
...

The "headers already sent" error error is because of the first error
message.

Thanks thats solved it.
I read somewhere you should assign posted info to variables at the top of
the script so that it will make managing the code easier. Hence my
$cancel=$_POST['cancel'];
is this not the case?

Ian
(Top posting fixed)

Yes, it's often good to do it that way. But that's only 1/2 of it. You
must also ensure that the variable is set before you try to assign it!

If $_POST['cancel'] is not set, you get just the error you saw - because
you didn't have a button/checkbox/field/whatever named 'cancel' passed
from the browser.

P.S. Please don't top post. Thanks.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 22 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.