Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Newbie needs help with confirmation message after form submission


PHP Newbie needs help with confirmation message after form submission

Reply
  #1 (permalink)  
Old 06-06-06, 04:11 PM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Cool PHP Newbie needs help with confirmation message after form submission

I have created this file to delete an image and empty the db field with the image name in it. So far, it works when the page originally loads...the image that is going to be deleted is displayed along with a button that says "Delete Image".

Once the button is clicked, all of the variable values in the URL are set correctly but it does not display the echo statements...it only displays the delete button again.

I have been looking around different forums for a couple of hours and was hoping someone here might be able to help me...you all look like a friendly bunch.

PHP Code:

<?php


if (submit_check!=1){
    
$directory $photo_dir;
    echo 
"<img src=\"/hotels_new/".$directory."/".$img."\"  />";
?>
<br />
<form id="form1" name="form1" method="get" action="del_photos.php">
  <input type="hidden" name="submit_check" value="1"/>
  <input type="hidden" name="img" value="<?=$img?>"/>
  <input type="hidden" name="itm" value="<?=$itm?>"/>
  <input type="hidden" name="id" value="<?=$id?>"/>
  <input type="hidden" name="which" value="<?=$which?>"/>
  <input type="hidden" name="directory" value="<?=$directory?>"/>
  <input type="submit" name="delete" value="Delete Image" />
</form>
<?php

if (
submit_check==1){
  require_once(
"./connect.php");

  switch (
$itm){
    case 
lux:
      
$query="update lux_data set";
      if(
$which =="main")         $query .=" photo_m='".$main_photo."' ";
      if(
$which == "additional")     $query .=" photo_o='".$additional_photo."' ";
      if(
$which == "floor")         $query .=" photo_floor='".$floor_plan."' ";
      
$query .=" where pack_id=".$_GET['id'];
      break;
    case 
drive:
      
$query="update drive_data set";
      if(
$which =="main")         $query .=" photo_m='".$main_photo."' ";
        if(
$which == "floor")         $query .=" photo_floor='".$floor_plan."' ";
      
$query .=" where pack_id=".$_GET['id'];
      break;
  }

echo 
$query;
$img_dir "/hotels_new/".$directory."/".$img;
echo 
$img_dir;

//mysql_query($query)or die (mysql_error());

//unlink($_GET['img']);

echo "Your image has been deleted.";
}
?>
I have commented out the mysql_query() and unlink() functions for now so I don't have to keep putting the images back (this is a live site). Before I put in the conditional statements to check for the form submission, this was all working. Not sure what I am overlooking, but I know it is something...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-06-06, 04:23 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
i can't seem to find the $_GET['varname'] statements to retrieve the values of the hidden fields. did you remove em to post your code here, or did you just forgot to add em ?

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-06-06, 04:41 PM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
When I started, I was just getting them and printing them to the page. I removed them before adding the submission check, and everything was still writing to the page ok...so I didn't think I needed it.

Here is what I had originally:
PHP Code:

<?php

require_once("./connect.php");

echo 
$_GET['img'];
echo 
$_GET['id'];
echo 
$_GET['itm'];
echo 
$_GET['which'];

switch (
$itm){
  case 
lux:
    
$query1="update lux_data set";
    if(
$which =="main")         $query1 .=" photo_m='".$main_photo."' ";
    if(
$which == "additional")     $query1 .=" photo_o='".$additional_photo."' ";
    if(
$which == "floor")         $query1 .=" photo_floor='".$floor_plan."' ";
    
$query1 .=" where pack_id=".$_GET['id'];
    break;
  case 
drive:
    
$query1="update drive_data set";
    if(
$which =="main")         $query1 .=" photo_m='".$main_photo."' ";
    if(
$which == "floor")         $query1 .=" photo_floor='".$floor_plan."' ";
    
$query1 .=" where pack_id=".$_GET['id'];
    break;
}

echo 
$query1;

mysql_query($query1)or die (mysql_error());

unlink($_GET['img']);

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-06-06, 04:42 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
In addition to what UnrealEd mentions, the if(....) statements (two places) reference what is probably an undefined constant - submit_check - and not a variable by that name - $submit_check

Edit: Register globals are probable on, in which case the variables are automatically created with the corresponding names.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-06-06, 04:58 PM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Adding this either before the submission check or just after the require_once didn't change anything that I could tell...

PHP Code:

  $img $_GET['img'];

  
$id $_GET['id'];
  
$itm $_GET['itm'];
  
$which $_GET['which'];
  
$photo_dir $_GET['photo_dir']; 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-06-06, 05:02 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
did you change the submit_check into $_GET['submit'] ?
otherwise the if-condition is not valid, and you will see the input fields again

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-06-06, 05:14 PM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Adding that, plus changing the constants to variables did the trick! Thanks so much to you both!

I originally had this in the directory with the images it was deleting, but instead want to use it whenever an image is deleted. So now, I just need to get it to delete from the correct directory and I will be all set!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 06-06-06, 05:30 PM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Just another quick question, if you have the chance...

I am getting this error now...

Code:
Warning: unlink(): open_basedir restriction in effect. File(/path/to_image/file.jpg) is not within the allowed path(s): (/my/dirs/:/usr/lib/php:/usr/local/lib/php:/tmp) in /sample/path/public_html/admin/delete_images.php on line 59
Do I need to have a separate file in the directory where the photos are being deleted just calling the unlink()? And if so, how would I reference it in my original file?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 06-07-06, 06:33 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
what do you fill in as value for $img. as far as i understand the error php has printed: i think you're deleting files that are not located in your server directory?

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 06-07-06, 08:30 AM
rmd rmd is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Although I have changed it to post here because I don't want to reveal the exact directory structure, it is trying to write to the correct directory (represented in my code here by /path/to_image/file.jpg). It is not letting me delete something not in the same directory as my PHP file.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM
Form Submission, PHP Coding Problem kibby67 PHP 3 12-02-04 02:13 PM
PHP Form Submission script sixflagsga Script Requests 0 10-10-04 08:26 PM
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM


All times are GMT -5. The time now is 11:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.