473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can't get Update to work on this script

155 100+
I've been working on this script all day with no luck at all. I have to successfully test both parts of this script in order to finish this project. I haven't tested the delete part yet, because I can't get the update part to work. I just can't figure out why this will not update the database.

[PHP]<?php
include("includes/dbconnect.php");

if(!isset($cmd))
{
$result = mysql_query("select * from $table order by title");
while($r = mysql_fetch_array($result))
{

$id = $r["id"];
$title = stripslashes($r["title"]);

echo "

<tr>
<td width='20%' align='right'>ID#: </td>
<td>$id</td>
</tr>
<tr>
<td width='20%' align='right'>Picture Title: </td>
<td>$title</td>
</tr>
<tr>
<td width='20%' align='right'>Picture File Name: </td>
<td>$image_name</td>
</tr>
<tr>
<td width='20%' align='right'>[ <a href='edit_picture.php?cmd=edit&id=$id'>Edit</a> ]</td>
<td>[ <a href='edit_picture.php?cmd=delete&id=$id'>Delete</a> ]</td>
</tr>
<tr><td colspan='4' width='100%' style='border-top: 1px solid #666'>&nbsp;</td></tr>

";

}
}
?>

</table>

<?php

echo "<h3>Edit a Picture</h3>";
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM $table WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<center>
<table width="95%" cellspacing="0" cellpadding="3" border="0">
<tr><td>
<form action="edit_picture.php" method="post">

<input type="hidden" name="id" value="<?php echo $myrow['id'] ?>">


Picture Title:<br>
<input type="text" name="title" VALUE="<?php echo stripslashes($myrow['title']) ?>" size="55"><br><br>

Picture Description:<br>
<TEXTAREA name="desc" ROWS=2 COLS=70 wrap=virtual><?php echo stripslashes($myrow['desc']) ?></TEXTAREA><br><br>

<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
</td>
</tr>
</table>
</center>

<?php
}
?>

<?php

if ($_POST["$submit"])
{

$title = addslashes($_POST['title']);
$desc = addslashes($_POST['desc']);

$sql = "UPDATE $table SET title='$title', desc='$desc' WHERE id=$id";

$result = mysql_query($sql);
echo "<br><br><p align='center'><span style='color:red'>Information updated.</span><br><br><a href='edit_picture.php'>Edit another Picture</a></p>";

}
}

?>

<?php
if($_GET["cmd"]=="delete")
{

$image_name = $_GET["image_name"];

$photo_dir = ('/mysite.com/gallery/image_uploads/');
$thumb_dir = ('/mysite.com/gallery/thumb_uploads/');

unlink($photo_dir.$image_name);
unlink($thumb_dir.$image_name);

$sql = "DELETE FROM $table WHERE image_name=$image_name";
$result = mysql_query($sql);

echo "<br><br><p align='center'><span style='color:red'><b>The Picture has been Deleted!<br><br>";
}

?>[/PHP]
Jun 21 '07 #1
27 1914
pbmods
5,821 Expert 4TB
Heya, David.

Try echoing the output of mysql_error() after the UPDATE query to see if your query generated an error.
Jun 21 '07 #2
DavidPr
155 100+
Error, query failed mysql said You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='Red Necklace.' WHERE id=''' at line 1
Jun 21 '07 #3
pbmods
5,821 Expert 4TB
Heya, David.

'desc' is a MySQL keyword. To use desc as a field name, you have to enclose it in backticks, like this:

Expand|Select|Wrap|Line Numbers
  1. WHERE `desc` = 'Red Necklace'
  2.  
Jun 21 '07 #4
DavidPr
155 100+
OK, it's working. But the delete part isn't.

I'm getting this error message:
[PHP]Warning: unlink(/mysite.com/gallery/image_uploads/): Is a directory in /home/user/mysite.com/admin/edit_picture.php on line 117

Warning: unlink(/mysite.com/gallery/thumb_uploads/): Is a directory in /home/user/mysite.com/admin/edit_picture.php on line 118[/PHP]

Here's the code:
[PHP]if($_GET["cmd"]=="delete")
{

$image_name = $_GET["image_name"];

$photo_dir = ('/mysite.com/gallery/image_uploads/');
$thumb_dir = ('/mysite.com/gallery/thumb_uploads/');

unlink($photo_dir.$image_name);
unlink($thumb_dir.$image_name);[/PHP]
Jun 21 '07 #5
pbmods
5,821 Expert 4TB
Heya, David.

You're getting these errors because $image_name is undefined.
Jun 22 '07 #6
DavidPr
155 100+
I'm using this further up.
[PHP]<a href='edit_picture.php?cmd=delete&image_name=$imag e_name'>Delete</a>[/PHP]
Jun 22 '07 #7
DavidPr
155 100+
Well, I've looked through all 3 of my php books and have searched the Web, but I haven't come across anything about deleting an image from the server. Is this beyond PHP's ability?
Jun 22 '07 #8
pbmods
5,821 Expert 4TB
Heya, David.

I haven't come across anything about deleting an image from the server. Is this beyond PHP's ability?
Have a look at unlink().
Jun 22 '07 #9
bonski
53
hello davidpr,

instead of passing na image_name, you use the image_id.. for more exact querying...

this line has an error... it doesn't pass the value of the variable $image_name instead it passes the string '$image_name' because you didn't put it inside a PHP tag. so change this line
Expand|Select|Wrap|Line Numbers
  1. <a href="edit_picture.php?cmd=delete&image_name=$image_name">

to this one... but using the field image_id..

Expand|Select|Wrap|Line Numbers
  1. <a href="edit_picture.php?cmd=delete&img_id=<?=$image_id?>">
then to your delete script...

[PHP]
<?php
if($_GET['cmd']=="delete" && isset($_GET['img_id'])){

$image_id = $_GET["img_id"];

//there's no need for parenthesis.. so i took it out.. ^__^
$photo_dir = '/mysite.com/gallery/image_uploads/';
$thumb_dir = '/mysite.com/gallery/thumb_uploads/';

//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE image_id='".$image_id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){

$sql = "DELETE FROM $table WHERE image_id=$image_id";
$result = mysql_query($sql);

if($result){
echo "<br><br><p align='center'><span style='color:red'><b>The Picture has been Deleted!<br><br>";
}

}else{
echo 'ERROR: Unable to delete image file!';
}

} //end of isset

?>[/PHP]


so if this works.. just modify its format or variables to where you're comfortable with.. ^___^..

bonski
Jun 22 '07 #10
pbmods
5,821 Expert 4TB
[nitpick]
Expand|Select|Wrap|Line Numbers
  1. <a href="edit_picture.php?cmd=delete&img_id=<?=$image_id?>">
only works if you have short tags enabled. Otherwise, you'll have to do this:
Expand|Select|Wrap|Line Numbers
  1. <a href="edit_picture.php?cmd=delete&img_id=<?php echo $image_id; ?>">
[/nitpick]
Jun 22 '07 #11
DavidPr
155 100+
I had to change it to this:
[PHP]<?php
if($_GET['cmd']=="delete" && isset($_GET['img_id'])){

$id = $_GET["img_id"];

//there's no need for parenthesis.. so i took it out..
$photo_dir = ('$_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/');
$thumb_dir = ('$_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/');

//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){

$sql = "DELETE FROM $table WHERE id=$id";
$result = mysql_query($sql);

if($result){
echo "<br><br><p align='center'><span style='color:red'><b>The Picture has been Deleted!<br><br>";
}

}else{
echo 'ERROR: Unable to delete image file!';
}

} //end of isset

?>[/PHP]
The below, edited with my website was returning = no such directory.
Of course, what I changed it to also doesn't work.

[PHP]$photo_dir = /mysite.com/gallery/image_uploads/;
$thumb_dir = /mysite.com/gallery/thumb_uploads/;[/PHP]
Jun 22 '07 #12
pbmods
5,821 Expert 4TB
Heya, David.

Looks pretty good. Is it working the way you expected?
Jun 22 '07 #13
bonski
53
^_____^... thats gonna work...!
Jun 22 '07 #14
DavidPr
155 100+
Here's the entire code, I think it'll help.

The only thing that's missing is my real website here:[PHP]$photo_dir = '/./gallery/image_uploads/';
$thumb_dir = '/./gallery/thumb_uploads/';[/PHP]

I've tried setting the path several different ways and each time either the directory or the file doesn't exist. Although they do exist. This latest time nothing came up except for my website heading.

[PHP]<?php
include("includes/dbconnect.php");

if(!isset($cmd))
{
$result = mysql_query("select * from $table order by title");
while($r = mysql_fetch_array($result))
{

$id = $r["id"];
$title = stripslashes($r["title"]);

echo "

<tr>
<td width='20%' align='right'>ID#: </td>
<td>$id</td>
</tr>
<tr>
<td width='20%' align='right'>Picture Title: </td>
<td>$title</td>
</tr>
<tr>
<td width='20%' align='right'>Picture File Name: </td>
<td>$image_name</td>
</tr>
<tr>
<td width='20%' align='right'>[ <a href='edit_picture.php?cmd=edit&id=$id'>Edit</a> ]</td>
<td>[ <a href='edit_picture.php?cmd=delete&id=$id'>Delete</a> ]</td>
</tr>
<tr><td colspan='4' width='100%' style='border-top: 1px solid #666'>&nbsp;</td></tr>

";

}
}
?>

</table>

<?php

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM $table WHERE id='$id'";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>


<h3>Edit a Picture</h3>

<center>
<table width="95%" cellspacing="0" cellpadding="3" border="0">
<tr><td>
<form action="edit_picture.php" method="post">

<input type="hidden" name="id" value="<? echo $myrow['id']; ?>">

Picture Title:<br>
<input type="text" name="title" VALUE="<? echo stripslashes($myrow['title']); ?>" size="55"><br><br>

Picture Description:<br>
<TEXTAREA name="image_desc" ROWS=2 COLS=70 wrap=virtual><? echo stripslashes($myrow['image_desc']); ?></TEXTAREA><br><br>

Picture Name: (This cannot be changed. It's here so you'll know you're editing the correct image.)<br>
<input type='text' size='55' name='image-name' value='<? echo stripslashes($myrow['image_name']); ?><br><br>


<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
</td>
</tr>
</table>
</center>

<?php
}
?>

<?php

if ($_POST["$submit"])
{

$id = $_POST['id'];
$title = addslashes($_POST['title']);
$image_desc = addslashes($_POST['image_desc']);

$query = "UPDATE $table SET title='$title', image_desc='$image_desc' WHERE id=$id";

$result = mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');

echo "<br><br><p align='center'><span style='color:red'>Information updated.</span><br><br><a href='edit_picture.php'>Edit another Picture</a></p>";

}
}

?>

<?php
if($_GET['cmd']=="delete" && isset($_GET['img_id'])){

$id = $_GET["id"];

//there's no need for parenthesis.. so i took it out..
$photo_dir = '/./gallery/image_uploads/';
$thumb_dir = '/./gallery/thumb_uploads/';


//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){

$sql = "DELETE FROM $table WHERE id=$id";
$result = mysql_query($sql);

if($result){
echo "<br><br><p align='center'><span style='color:red'><b>The Picture has been Deleted!<br><br>";
}

}else{
echo 'ERROR: Unable to delete image file!';
}

} //end of isset

?>[/PHP]

***EDITED***

[PHP]if($_GET['cmd']=="delete" && isset($_GET['img_id'])){[/PHP]

I forgot to change the img_id to just id. When I did that along with setting the below it worked! Thank you for the help.

[PHP]$photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
$thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';[/PHP]
Jun 22 '07 #15
bonski
53
instead of this
[PHP]
$photo_dir = '/./gallery/image_uploads/';
$thumb_dir = '/./gallery/thumb_uploads/';[/PHP]

change to this..

[PHP]$photo_dir = '../../gallery/image_uploads/';
$thumb_dir = '../../gallery/thumb_uploads/';[/PHP]

where exactly is your script? and wheres the root path of you image files?

example:
directory structure...

if you script is the same folder with the directory 'gallery'
Expand|Select|Wrap|Line Numbers
  1.  
  2. php_scripts/
  3.     gallery/
  4.          image_uploads/
  5.                 img.jpeg
  6.          thumb_uploads/
  7.                 thmb.jpeg
  8.  
  9.     edit_picture.php
  10.  
  11.  
then you should set the dir path like this

[PHP]
$photo_dir = 'gallery/image_uploads/';
$thumb_dir = 'gallery/thumb_uploads/';
[/PHP]

but if outside or another folder like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. images/
  3.     gallery/
  4.          image_uploads/
  5.                 img.jpeg
  6.          thumb_uploads/
  7.                 thmb.jpeg
  8. php_scripts/
  9.     edit_picture.php
  10.  
  11.  
then set it up like this

[PHP]
$photo_dir = '../images/gallery/image_uploads/';
$thumb_dir = '../images/gallery/thumb_uploads/';
[/PHP]

'..' means go up one level

^___^
Jun 22 '07 #16
bonski
53
thats good... ^___^..!!
Jun 22 '07 #17
DavidPr
155 100+
^___^ - what does this mean?


Question:
[PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;[/PHP]
How were you able to get the image_name from the above?

Also: The above was to delete image information in the database and the image on the server. The pictures are filed under a specific category or album. I have a script that will delete the category and I would like to take this one step further. If I decide to delete a category or album I would like for all of the pictures associated with this category or album to be deleted as well. Both from the server and the picture table ($table).

Will the big code below do the job or would this here have to be modified from image to images[PHP] //name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){ [/PHP]

[PHP]<?php
if($_GET['cmd']=="delete" && isset($_GET['cat_id']))

{

$cat_id = $_GET["cat_id"];

$photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
$thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){

$sql = "DELETE FROM $table WHERE cat_id=$cat_id";
$result = mysql_query($sql);

if($result)

{
echo "<br><br><p align='center'><span style='color:red'><b>The Pictures in this album have been Deleted!<br><br>";
}

}
else
{

echo 'ERROR: Unable to delete image file!';
}


$sql = "DELETE FROM $cat WHERE cat_id=$cat_id";
$result = mysql_query($sql);

if($result)
{
echo "<br><br><p align='center'><span style='color:red'><b>This Album has been Deleted!<br><br>";

}
else
{

echo 'ERROR: Unable to Delete this Album!';
}

}
?>[/PHP]
Jun 22 '07 #18
bonski
53
^___^ - what does this mean?


Question:
[PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;[/PHP]
How were you able to get the image_name from the above?
^___^ means a big smile... hahaha...

so from this query

[PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";[/PHP]

it will return the whole row of the image file record from the table which its 'id' is equal to the value you provide from the variable '$id'

well this line is getting the image_name field from your table
i used the function mysql_fetch_object(), so it looks like this
[PHP]$image_name = $row->image_name;[/PHP]
using -> as a pointer(im not sure bout the name.. but i call it pointer..)

so $image_name contains already the name of the image file from the table...

then thats the time you concatenate it with the directories when you unlink..

^____^ bonski
Jun 22 '07 #19
DavidPr
155 100+
Thanks for that explanation. I was editing my previous post at the same time you made your post. You beat me to the "Enter" key.

Was hoping you would have a peek at it and tell me what you think.
Thank you.
Jun 22 '07 #20
bonski
53
Thanks for that explanation. I was editing my previous post at the same time you made your post. You beat me to the "Enter" key.

Was hoping you would have a peek at it and tell me what you think.
Thank you.
sure buddy...!!! you're welcome.... ^___-. im looking forward for that...!
Jun 22 '07 #21
DavidPr
155 100+
Thanks I appreciated the help.

The script you were helping me with was to delete one picture from the server and that picture's information from the database. The categories the pictures are associated with are in a table called by the variable $cat. The fields or rows are - cat_id, cat_name and cat_desc.

What I would like to do is to alter the script we just completed, so that I can:
  • Delete a category from the $cat table.
  • Delete all the pictures on the server that are filed under that category's id number in the database table - $table.
  • Delete all the information in the $table pertaining to the pictures under the deleted category's id number.

The code below will do everything except it only removes one picture from the server. Is it possible to remove all the pictures on the server that are filed under the category being deleted?

Maybe change image_name to image_name(s)?[PHP]//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name))
{ [/PHP]

Here's what I have:
[PHP]<?php
if($_GET['cmd']=="delete" && isset($_GET['cat_id']))
{

$cat_id = $_GET['cat_id'];

$photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
$thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name))
{
$query = "DELETE FROM $table WHERE cat_id='".$cat_id."'";
$result = mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
if($result)
{
echo "<br><br><p align='center'><span style='color:red'><b>The Pictures in this album have been Deleted!<br><br>";
}
}
else
{
echo "ERROR: Unable to delete image file!";
}


$query = "DELETE FROM $cat WHERE cat_id='".$cat_id."'";
$result = mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
if($result)
{
echo "<br><br><p align='center'><span style='color:red'><b>This Album has been Deleted!<br><br>";
}
else
{
echo "ERROR: Unable to Delete this Album!";
}

} //end of isset
?>[/PHP]
Jun 22 '07 #22
DavidPr
155 100+
Would a while statement work? If so, would I still perform "If statement" shown below the while statement to make sure that the image files were unlinked so that it could move on to deleting the information from the database?

[PHP]<?php
if($_GET['cmd']=="delete" && isset($_GET['cat_id']))
{

$cat_id = $_GET['cat_id'];

$photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
$thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


//getting the data of the image
$image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_id."'";
$image_qry = mysql_query($image_sql);
$row = @mysql_fetch_object($image_qry);

//name of image file
$image_name = $row->image_name;

$num = 0;
while ($image_name > $num);
{
unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name);
$num++;
}

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name))
{

$query = "DELETE FROM $table WHERE cat_id='".$cat_id."'";
$result = mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
if($result)
{
echo "<br><br><p align='center'><span style='color:red'><b>The Pictures in this album have been Deleted!<br><br>";
}
}
else
{
echo "ERROR: Unable to delete image file!";
}[/PHP]
Jun 23 '07 #23
bonski
53
What I would like to do is to alter the script we just completed, so that I can:
  • Delete a category from the $cat table.
  • Delete all the pictures on the server that are filed under that category's id number in the database table - $table.
  • Delete all the information in the $table pertaining to the pictures under the deleted category's id number.
ok.. that script is only to delete one image file... and together with its record on the database... so deleting that image file record.. doesn't have to involved with the category itself.. right..

let me show some table relationship... table 1 is about category (e.g. animal photos) and table 2 is where the image file record is...

Expand|Select|Wrap|Line Numbers
  1. table 1: category
  2.  
  3. cat_id         cat_name
  4.  
  5.   1             birds
  6.   2             dogs
  7.  
  8. table 2: images
  9.  
  10. img_id       cat_id        img_name
  11.  
  12.    1               2               dog1.jpeg
  13.    2               1                bird1.jpeg
  14.    3               1               bird2.jpeg
  15.  
now... when you delete an image file... you going to query directly to table2 : images right? and it doesn't have to query from category anymore... because your just going to delete a certain image file...

[PHP]$delete_sql = "DELETE FROM ".$table_images." WHERE img_id='".$image_id."'";[/PHP]

now... if your going to delete a category... you're going to check if there's any image file record under this category.. right?

ok here..

[PHP]

if(isset($_GET['c_id'])){

$cat_id = $_GET['c_id'];

$photo_dir = '/mysite.com/gallery/image_uploads/';
$thumb_dir = '/mysite.com/gallery/thumb_uploads/';
$count_record = 0;
$sql = "SELECT * FROM ".$table_images." WHERE cat_id='".$cat_id."'";
$qry = mysql_query($sql);
$count_record = mysql_num_rows($qry);

if($count_record != 0){

$counter = 0;
while($row = mysql_fetch_array($qry, MYSQL_ASSOC)){
$image_id = $row['img_id'];
$image_name = $row['image_name'];

if(unlink($photo_dir.$image_name) && unlink($thumb_dir.$image_name)){
$sql = "DELETE FROM ".$table_images." WHERE image_id='".$image_id."'";
$result = mysql_query($sql);
if($result){

$counter++;

}//endif($result)

}//end of if

}// end of while loop

if($count_record==$counter){
$delete_cat = "DELETE FROM ".$table_category." WHERE cat_id='".$cat_id."'";
$delete_cat_qry = mysql_query($delete_cat);
}else{
echo 'ERROR: unable to delete category. unable to delete files!';
}

}else{
$delete_cat = "DELETE FROM ".$table_category." WHERE cat_id='".$cat_id."'";
$delete_cat_qry = mysql_query($delete_cat);
}

}

[/PHP]

so this code will check if there are files under this category and delete all files existing if a category is deleted.. or if there's no files under this category it will just delete the category immediately... ^___^
Jun 23 '07 #24
DavidPr
155 100+
I've a lot to learn. It works!

I didn't think so at first because it only showed my Web page heading after the script ran. This has happened to me in the past and was the result of a failed script as some point. I got used to seeing the confirmation messages of a successful action.

I added some confirmation messages, but I must not have put them in the correct locations since they didn't work when I re-ran the script.

This is great, thanks!

David
Jun 23 '07 #25
bonski
53
I've a lot to learn. It works!

I didn't think so at first because it only showed my Web page heading after the script ran. This has happened to me in the past and was the result of a failed script as some point. I got used to seeing the confirmation messages of a successful action.

I added some confirmation messages, but I must not have put them in the correct locations since they didn't work when I re-ran the script.

This is great, thanks!

David

glad to hear that.. you're welcome... have fun with you project... ^____^..

bonski
Jun 23 '07 #26
DavidPr
155 100+
I've put this in several places in this last script, but I can't get it to show up on a successful category delete. Can you tell me which line to put it? Thanks again.

[PHP]echo "<br><br><p align='center'><span style='color:red'><b>The Album has been Deleted!<br><br>";[/PHP]
Jun 24 '07 #27
bonski
53
I've put this in several places in this last script, but I can't get it to show up on a successful category delete. Can you tell me which line to put it? Thanks again.

[PHP]echo "<br><br><p align='center'><span style='color:red'><b>The Album has been Deleted!<br><br>";[/PHP]
put this line after line 34 and after line 41 with this lines of code...

[PHP]

if($delete_cat_qry){
echo "<br><br><p align='center'><span style='color:red'><b>The Album has been Deleted!<br><br>";
}
[/PHP]

bonski
Jun 25 '07 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jeff | last post by:
ok.... i dont know why this wont work. this is going to access DB on web. var1a = Request.Form("h1") var1b = Request.Form("h2") strSQL = "UPDATE matches SET team1a = " & var1a & ", team1b = "...
1
by: Dragon | last post by:
I am using mysql with the InnoDB engine. I wrote a perl script that first selects something from a table, and then updates a second table based on the select from the first table. I need to make...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
13
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks,...
4
by: yehey2010 | last post by:
Hi, I have problem with my ASP.Net Code, I used GridView with Edit/Update on it. However the program seems not work correctly because it doesn't Update the OLD VALUE with the NEW VALUE. Please...
5
by: HockeyFan | last post by:
We have an update panel that has a gridview with checkboxes and other items in each row. We went to the RowCreated event in the codebehind, to set an attribute on a checkbox in each row, to...
7
by: TriAdmin | last post by:
I am working with a system that allow me to add custom fields but I can not add OnChange() language to the custom fields. So I want to have a function in the header that recognizes when fieldx is...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.