Jump to content


Photo

[resolved] Undefined variable


  • Please log in to reply
11 replies to this topic

#1 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 09:47 AM

Hi guys, im think im getting somewhere with me delete code now. Instead of the usual error message of erro2. Im now only getting


Notice: Undefined variable: Videofile in c:\documents and settings\administrator\my documents\web pages\st john fisher movie front end v2\delete.php on line 28

Warning: unlink(\\benin\Videolibrary\): Permission denied in c:\documents and settings\administrator\my documents\web pages\st john fisher movie front end v2\delete.php on line 28


Can anyone help me work out where the undefined variable is comming from? Heres my code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php include "conn.inc.php"; ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>St John Fisher Catholic High School</title>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="St John Fisher Catholic High School" name=keywords>
<META content="St John Fisher Catholic High School" name=description>
<META content="Simon Mackness-Pettit, Arutha Studios" name=Author>
<link type="text/css" rel="stylesheet" href="styles.css">
</head>
<body>

<?php

if (isset($_GET['ID'])) {
   $vidID = $_GET['ID'];
} else {
   $vidID = NULL;
}
$query = "SELECT * FROM videos WHERE ID = ('$vidID')";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))

//Code that makes sure a certain file can be found on the drive before it unlinks the videofile
if ( file_exists( "\\\benin\\Videolibrary\\checkme_sjf.txt" ) ){

//Code that goes to the drive and deletes the file.
   unlink("\\\benin\\Videolibrary\\" . $Videofile);
   
//Code that deletes record from database
   $query2 = "DELETE FROM videos WHERE ID = ('$vidID')";
   $result2 = mysql_query($query2);
   
   echo "The video has been deleted.";
   
//Code that happens if checkme_sjf is not found on the drive   
} else {

echo "Im afraid the drive you are trying to upload the file to is incorrect, please contact the ICT department.";

}

?>

<p align="center"><a href="delvideo.php">Back To Video Removal Facility</a></p>

</body>
</html>


Thanks for any help you can offer

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 30 October 2006 - 10:54 AM

Yeah... The $Videofile variable is being used on the following line...

<?php

//Code that goes to the drive and deletes the file.
   unlink("\\\benin\\Videolibrary\\" . $Videofile);

?>

I would assume that it should be defined as the filename of the video file you are trying to delete. Do you store the filename in the database table? If so, you need to assign that value to the variable before using it.

#3 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 11:01 AM

Yeah... The $Videofile variable is being used on the following line...

<?php

//Code that goes to the drive and deletes the file.
   unlink("\\\benin\\Videolibrary\\" . $Videofile);

?>

I would assume that it should be defined as the filename of the video file you are trying to delete. Do you store the filename in the database table? If so, you need to assign that value to the variable before using it.


Yes the file name is stored in the database in the videos table and in there under Videofile, I thought I had assigned the value in the code as I delaire the variable in the code. How do I go about doing this then, do i simple put another quary in before the unlink?

#4 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 30 October 2006 - 11:38 AM

My first suggestion is to print out the contents of your $result variable, so that you can see the values. You would then need to assign the filename contained in the result to the $Videofile variable.

<?php

$query = "SELECT * FROM videos WHERE ID = ('$vidID')"; //Try to always fetch the columns that you need from the table. SELECT filename, description FROM videos WHERE ID = ('$vidID')
$result=mysql_query($query);

print_r($result); //Print out the results from the query
exit(); //Exit the script so that you can see the output

?>


#5 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 11:44 AM

My first suggestion is to print out the contents of your $result variable, so that you can see the values. You would then need to assign the filename contained in the result to the $Videofile variable.

<?php

$query = "SELECT * FROM videos WHERE ID = ('$vidID')"; //Try to always fetch the columns that you need from the table. SELECT filename, description FROM videos WHERE ID = ('$vidID')
$result=mysql_query($query);

print_r($result); //Print out the results from the query
exit(); //Exit the script so that you can see the output

?>


Already started doing that, strange thing is that its printing out nothing, it seems the Array is empty. Heres the code that im using.


<?php

if (isset($_GET['ID'])) {
   $vidID = $_GET['ID'];
} else {
   $vidID = NULL;
}

$query = "SELECT * FROM videos WHERE ID = {$vidID}";
echo "Running query ... {$query}<br>";
$result = mysql_query ($query);
echo "Found " . mysql_num_rows ($result) . " record(s)<br>";

print ("<pre>"); print ($result); print ("</pre>");

$tralala = mysql_fetch_array ($result);

print ("<pre>"); print ($tralala); print ("</pre>");

?>


And like I said it seems to be saying the array is empty

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 30 October 2006 - 11:51 AM

How is this script being invoked? Is $_GET['vivID'] set when entering?
Put this code at the start of your script:
<?php
echo '<pre>' . print_r($_GET,true) . '</pre>';
?>

Ken

#7 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 12:00 PM

How is this script being invoked? Is $_GET['vivID'] set when entering?
Put this code at the start of your script:

<?php
echo '<pre>' . print_r($_GET,true) . '</pre>';
?>

Ken


Well this is what its printing out

Array
(
    [ID] => 75
)
Running query ... SELECT * FROM videos WHERE ID = 75
Found 1 record(s)

Resource id #4Array

#8 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 30 October 2006 - 12:09 PM

As far as I'm aware print_r() is for arrays, I think using print $tralala will appear as an empty array because it's not actually reading the array.

In the code given, you haven't actually defined the $videoFile at all.  You've fetched the array into $tralala and not done anything following that such as:

<?php
$videoFile = $tralala['videoFile'];
?>

HTH

Dest

#9 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 12:20 PM

As far as I'm aware print_r() is for arrays, I think using print $tralala will appear as an empty array because it's not actually reading the array.

In the code given, you haven't actually defined the $videoFile at all.  You've fetched the array into $tralala and not done anything following that such as:

<?php
$videoFile = $tralala['videoFile'];
?>

HTH

Dest


Have tried that and am still getting blank reports, this is strange

#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 12:34 PM

I would think this...

unlink("\\\benin\\Videolibrary\\" . $Videofile);

would need to be.....

unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);


#11 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 30 October 2006 - 12:48 PM

I would think this...

unlink("\\\benin\\Videolibrary\\" . $Videofile);

would need to be.....

unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);


That seemed ta do the job, thanks

#12 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 30 October 2006 - 01:07 PM

Sorry Jurik, my mistake... I should have told you to print the output of the $row variable, as mysql_query() returns a resource which you would then need to pass through to mysql_fetch_array()  ::)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users