Jump to content

Archived

This topic is now archived and is closed to further replies.

Jurik

[resolved] Undefined variable

Recommended Posts

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

[quote]

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

[/quote]

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

[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>

[/code]

Thanks for any help you can offer

Share this post


Link to post
Share on other sites
Yeah... The $Videofile variable is being used on the following line...

[code]
<?php

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

?>
[/code]

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.

Share this post


Link to post
Share on other sites
[quote author=gmwebs link=topic=113207.msg459885#msg459885 date=1162205667]
Yeah... The $Videofile variable is being used on the following line...

[code]
<?php

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

?>
[/code]

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.
[/quote]

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?

Share this post


Link to post
Share on other sites
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.

[code]
<?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

?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=gmwebs link=topic=113207.msg459896#msg459896 date=1162208282]
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.

[code]
<?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

?>
[/code]
[/quote]

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

[code]

<?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>");

?>

[/code]

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

Share this post


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

Ken

Share this post


Link to post
Share on other sites
[quote author=kenrbnsn link=topic=113207.msg459907#msg459907 date=1162209113]
How is this script being invoked? Is $_GET['vivID'] set when entering?
Put this code at the start of your script:
[code]<?php
echo '<pre>' . print_r($_GET,true) . '</pre>';
?>[/code]

Ken
[/quote]

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

Share this post


Link to post
Share on other sites
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:

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

HTH

Dest

Share this post


Link to post
Share on other sites
[quote author=Destruction link=topic=113207.msg459917#msg459917 date=1162210187]
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:

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

HTH

Dest
[/quote]

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

Share this post


Link to post
Share on other sites
I would think this...

[code=php:0]
unlink("\\\benin\\Videolibrary\\" . $Videofile);
[/code]

would need to be.....

[code=php:0]
unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);
[/code]

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=113207.msg459922#msg459922 date=1162211648]
I would think this...

[code=php:0]
unlink("\\\benin\\Videolibrary\\" . $Videofile);
[/code]

would need to be.....

[code=php:0]
unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);
[/code]
[/quote]

That seemed ta do the job, thanks

Share this post


Link to post
Share on other sites
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()  ::)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.