Connecting Tech Pros Worldwide Help | Site Map

problems using copy() and rename()

mantrid
Guest
 
Posts: n/a
#1: Oct 21 '06
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





peter
Guest
 
Posts: n/a
#2: Oct 21 '06

re: problems using copy() and rename()



"mantrid" <ian.dandav@virgin.netwrote in message
news:%7o_g.143$76.75@newsfe5-win.ntli.net...
Quote:
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.


mantrid
Guest
 
Posts: n/a
#3: Oct 21 '06

re: problems using copy() and rename()



"peter" <submit@flexiwebhost.comwrote in message
news:ehd81o$cu8$1@aioe.org...
Quote:
>
"mantrid" <ian.dandav@virgin.netwrote in message
news:%7o_g.143$76.75@newsfe5-win.ntli.net...
Quote:
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?
>

Quote:
are you receiving any error if so what is it? Also if it is as it looks
and
Quote:
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


mantrid
Guest
 
Posts: n/a
#4: Oct 21 '06

re: problems using copy() and rename()



"mantrid" <ian.dandav@virgin.netwrote in message
news:eUp_g.42060$6C2.34098@newsfe6-gui.ntli.net...
Quote:
>
"peter" <submit@flexiwebhost.comwrote in message
news:ehd81o$cu8$1@aioe.org...
Quote:

"mantrid" <ian.dandav@virgin.netwrote in message
news:%7o_g.143$76.75@newsfe5-win.ntli.net...
Quote:
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?
>
>
>
>
Quote:
are you receiving any error if so what is it? Also if it is as it looks
and
Quote:
is a file that has been uploaded then why not use the
move_uploaded_file()
Quote:
Quote:
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
Quote:
it checks that a file has been uploaded and returns negative if it cant
find
Quote:
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>");
}



mantrid
Guest
 
Posts: n/a
#5: Oct 21 '06

re: problems using copy() and rename()



"mantrid" <ian.dandav@virgin.netwrote in message
news:kZp_g.42063$6C2.24358@newsfe6-gui.ntli.net...
Quote:
>
"mantrid" <ian.dandav@virgin.netwrote in message
news:eUp_g.42060$6C2.34098@newsfe6-gui.ntli.net...
Quote:

"peter" <submit@flexiwebhost.comwrote in message
news:ehd81o$cu8$1@aioe.org...
Quote:
>
"mantrid" <ian.dandav@virgin.netwrote in message
news:%7o_g.143$76.75@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()
Quote:
Quote:
Quote:
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?

>

Quote:
are you receiving any error if so what is it? Also if it is as it
looks
Quote:
Quote:
and
Quote:
is a file that has been uploaded then why not use the
move_uploaded_file()
Quote:
Quote:
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
Quote:
it checks that a file has been uploaded and returns negative if it cant
find
Quote:
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 -
Quote:
".$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."'";
Quote:
$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."'";
Quote:
$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]."
Quote:
not uploaded. Not a valid image file.</span>";
//}
//}else{
//$msg.="<br><span class='RedWarning'>".$uploadedfile['name'][$x]."
is
Quote:
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


peter
Guest
 
Posts: n/a
#6: Oct 21 '06

re: problems using copy() and rename()


Quote:
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?


peter
Guest
 
Posts: n/a
#7: Oct 21 '06

re: problems using copy() and rename()



"peter" <submit@flexiwebhost.comwrote in message
news:ehde9o$lfs$1@aioe.org...
Quote:
>
Quote:
>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)


mantrid
Guest
 
Posts: n/a
#8: Oct 21 '06

re: problems using copy() and rename()



"peter" <submit@flexiwebhost.comwrote in message
news:ehdeli$lsh$1@aioe.org...
Quote:
>
"peter" <submit@flexiwebhost.comwrote in message
news:ehde9o$lfs$1@aioe.org...
Quote:
Quote:
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.

Quote:
Regarding not receiving an error ensure you have the following at the top
of
Quote:
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?
Quote:
It is possible that the errors are being supressed for some reason
(possibly
Quote:
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.



peter
Guest
 
Posts: n/a
#9: Oct 21 '06

re: problems using copy() and rename()


Quote:
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.


mantrid
Guest
 
Posts: n/a
#10: Oct 22 '06

re: problems using copy() and rename()



"peter" <submit@flexiwebhost.comwrote in message
news:ehe92r$ps7$1@aioe.org...
Quote:
>
Quote:
That has thrown up lots of notices, most of which are of the type:
Notice: Use of undefined constant archivequest - assumed 'archivequest'
in
Quote:
Quote:
......

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
Quote:
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
Quote:
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
}
?>


Jerry Stuckle
Guest
 
Posts: n/a
#11: Oct 22 '06

re: problems using copy() and rename()


mantrid wrote:
Quote:
"peter" <submit@flexiwebhost.comwrote in message
news:ehe92r$ps7$1@aioe.org...
>
Quote:
Quote:
>>>That has thrown up lots of notices, most of which are of the type:
>>>Notice: Use of undefined constant archivequest - assumed 'archivequest'
>
in
>
Quote:
Quote:
>>>......
>>>
>>>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
>
Quote:
>>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
>
Quote:
>>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.
jstucklex@attglobal.net
==================
mantrid
Guest
 
Posts: n/a
#12: Oct 22 '06

re: problems using copy() and rename()


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" <jstucklex@attglobal.netwrote in message
news:8padnZI6cLYiTKfYnZ2dnUVZ_sidnZ2d@comcast.com. ..
Quote:
mantrid wrote:
Quote:
"peter" <submit@flexiwebhost.comwrote in message
news:ehe92r$ps7$1@aioe.org...
Quote:
>>That has thrown up lots of notices, most of which are of the type:
>>Notice: Use of undefined constant archivequest - assumed 'archivequest'
in
Quote:
>>......
>>
>>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
Quote:
>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
Quote:
>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
Quote:
Quote:
started at
/home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
Quote:
Quote:
in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line
17
Quote:
Quote:


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.
jstucklex@attglobal.net
==================

Jerry Stuckle
Guest
 
Posts: n/a
#13: Oct 22 '06

re: problems using copy() and rename()


mantrid wrote:
Quote:
"Jerry Stuckle" <jstucklex@attglobal.netwrote in message
news:8padnZI6cLYiTKfYnZ2dnUVZ_sidnZ2d@comcast.com. ..
>
Quote:
>>mantrid wrote:
>>
Quote:
>>>"peter" <submit@flexiwebhost.comwrote in message
>>>news:ehe92r$ps7$1@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
>
Quote:
Quote:
>>>started at
>
/home/iddsoftw/public_html/questiondbase/questionupdate.php:11)
>
Quote:
Quote:
>>>in /home/iddsoftw/public_html/questiondbase/questionupdate.php on line
>
17
>
Quote:
Quote:
>>>
>>>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.
jstucklex@attglobal.net
==================
Closed Thread