Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-11-2006, 07:55 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,512
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Silly problem but I cant see it ! ??



Hi

I just cant see the problem !

This should be pretty simple !

I wrote a script to processes my image-getting form and it is "included" by my
main script which is called homes_add.php. After doing the "include()" the main script should just continue processing - right ??
well it doesn't.

I have put in some test displays and you can see them in the code.
The HELLOOOOO gets displayed.

From inside the included script (a_pict.php) a form script (a_pict_fm.php) is run which works fine ( the form just actions the included script again).

The include then finally displays
the 2 test texts: "got here" and "*** and GOT here"

Then the screen stops.
- GOT HERE !!! on the main script does NOT display nor do the other tests !!

To summarise the problem is that the a_pict.php stops at the last line afer executing this :

echo " *** and GOT here";

IT DOESN'T RETURN TO HOMES_ADD.PRG


If anyone can help - I'd much appreciate it as I am a bit stuck !


HERE IS THE MAIN - HOMES_ADD.PHP SCRIPT
IT CALLS THE PICTURE HANDLING SCRIPT

PHP Code:
<?php 
/* 
*  homes_add.php 

* Called by :  homes_ad_btn.php 

* Call a_picts.php to get the pictures 

*  processes the  homes_add_fm.php which is the 
*   FORM for adding a home. 
*/ 
          
if (!isset($_POST['run_mn'])){     

PREPARES DATA AND CALLS THE MAIN FORM NOT PICTURE FORM

else {   
// BIG else    -  SO MAIN FORM HAS RUN 

   
VALIDATES FORM DATA 

/* 
*  Now we get the pictures. 
*/ 
    
if( $pict == "y"){ 
     echo 
"HELLOOOOO";      //  < --   test  ( this displays ok )
      
include ("a_picts.php");   //  < --   HERE IS THE CALLING 
     
echo " GOT HERE !!!";  //  < --   test  ( this does NOT display )
         
}  // endif 
    
else{ 
       
$N_pix1=$N_pix2=$N_pix3=$N_pix4=$N_pix5="none"
         } 
// end else 


echo "Pix1: ".$N_pix1." Pix2: ".$N_pix2." Pix3: ".$N_pix3;   //  < --   test  ( this does NOT display )
         
$sql "UPDATE homes SET 
         pix1 = '$N_pix1', 
         pix2 = '$N_pix2', 
         pix3 = '$N_pix3', 
         pix4 = '$N_pix4', 
         pix5 = '$N_pix5' 
                                              
     WHERE ad_ref = '$A_ref' "

      
     
mysql_query($sql
    or die(
"could not execute HOMES UPDATE PICTURES query"); 
 
echo
" DONE HOMES UPDATE";  //  < --   test  ( this does NOT display )        
         
/* 
*  Update the client table 
*/ 
        
ETC ETC 
      
// end BIG else 

?>

THIS IS THE FORM THE SECOND SCRIPT THAT CALLS AND THEN PROCESSES
THE FORM


PHP Code:
if(isset($_POST['run'])){  // BIG IF 

     
PROCESSES THE PICT_FM.PHP   FORM 

   
echo "got here"
}  
// end BIG IF 

else    { 
    
$message1 "none"
    
$message2 "none"
     require_once (
"a_picts_fm.php");    //  CALLS THE FORM 
     
exit(); 
    } 
// end else 

echo " *** and got here";    

  
//  THIS WHERE IT STOPS 

?> 
AND THIS IS THE FORM THAT THE ABOVE REQUIRES
(which works fine)

PHP Code:
<?php 
/* 
* picts_fm.php 

* Called by : picts.php 
* IT THEN GOES BACK TO PICTS.PHP 

* FORM for adding images. 

*/ 
?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<script type="text/javascript"> 

      
    var IE = true; 
    if (navigator.appName != "Microsoft Internet Explorer"){IE = false} 

    function showImg1(){ 
        var fullName = document.main_fm.upLoad1.value; 
        var fileName = fullName.match(/[^/]+$/); 
        var splitName = fullName.split("."); 
        var fileType = splitName[1]; 
        fileType = fileType.toLowerCase(); 
        if (fileType == 'gif' || fileType == 'jpg' || fileType == 'jpeg') 
            { 
             if (IE) 
                { 
                document.getElementById('image1').style.display = ''; 
        document.getElementById('image1').src = fullName; 
                } 
             document.main_fm.fName1.value = 'Picture file name: '+fileName; 
            } 
        else       { 
              alert('Invalid file type'); 
            } 
    } 


</script> 
</head> 
<body> 
<!-- Using a linked stylesheet --> 
<link rel="STYLESHEET" type="text/css" href="yodbod.css"> 
<img alt="header (13K)" src="flashtest1.jpg" height="130" width="920" /> 

<div style='width:600px; position:absolute; left:40px; top:160px' > 
<b><big>Adding pictures to your advert.</big></b><br> 
<b>Select your picture files from your computer using the browse buttons.</b><br /> 
You can have up to five photos for all catagories except Jobs and Careers<br /> 
which excepts only one (we couldn't see any reason for more!).<br /> 
<br /> 
<?php 
if($message1 != "none"){ 
  echo 
"$message1<br />$message2"
// end if 
?> 

</div> 

<form name="main_fm" enctype ="multipart/form-data" action="a_picts.php" method="POST"> 
<input type = 'hidden' name='run' value="on"> 
<input type="hidden" name ="MAX FILE SIZE" value="500000"> 
<input type = 'hidden' name='adref' value="<?php echo $A_ref ?>"> 

<div style='position:absolute; left:40px; top:320px' > 
<b>First image:</b><br /> 
<input type="file" size="50" id = "u1" name="upLoad1" onchange="showImg1()"><br /> 
<input type="text" size="50" id = "n1" name="fName1" readonly> 
<input type="button" value ="Clear" onclick="document.main_fm.upLoad1.value='';document.main_fm.fName1.value='';document.getElementById('image1')    .src='';document.getElementById('image1').style.display='none'"> 
</div> 

<div style='position:absolute; left:500px; top:262px' > 
<img height='160' width='160' id="image1" style='display:none' /> 
</div>

REALLY HOPE SOMEONE CAN HELP
jeddi is offline   Reply With Quote
Old 06-11-2006, 11:47 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
my only GUESS is that in this code here:

PHP Code:
if(isset($_POST['run'])){  // BIG IF 

     
PROCESSES THE PICT_FM.PHP   FORM 

   
echo "got here"
}  
// end BIG IF 

else    { 
    
$message1 "none"
    
$message2 "none"
     require_once (
"a_picts_fm.php");    //  CALLS THE FORM 
     
exit(); 
    } 
// end else 

echo " *** and got here";    

  
//  THIS WHERE IT STOPS 

?> 
your script is tripping up on the exit() command somehow and forcing the program to stop execution...so everything outputs for that page of code, and then execution ends? Dunno, I've seen stranger things...

try commenting out exit() or removing it altogether and see what happens...

Quote:
edit: another thing you can do is insert:

error_reporting(E_ALL);

into your pages to catch all errors....

And you could try eliminating chunks of your code piece by piece until you code works, to isolate the problem...
__________________
Regards, R.J.

Last edited by chump2877; 06-11-2006 at 11:50 AM..
chump2877 is offline   Reply With Quote
Old 06-11-2006, 12:11 PM   PM User | #3
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
if you want to stop execution of an included file, use
return false;
not exit()...
GJay is offline   Reply With Quote
Old 06-11-2006, 02:30 PM   PM User | #4
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,512
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
I have tried taking out that exit() but ( as you would guess ) the scrpit then doesn't work properly because instead of stopping while the form is filled in and the action="a_picts.php" is caled, the script carries on ( down the wrong path).

As you know the exit() is normally placed here after calling a form.

I will try the error_reporting(E_ALL);

will also try return false;
jeddi is offline   Reply With Quote
Old 06-11-2006, 02:38 PM   PM User | #5
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,512
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Well I tried "return false;"

but it didn't stop the script whie the form ran so with the form still onscreen I got all the other test messages come through on my screen showing that the
main script had been returned to and processed information that it didn't yet have becasue the form hadn't ben processed.

In other words the exit(); is necessary at that point.

Actually the script gets past that point anyway because it prints out
" *** and got here" - which is AFTER that exit()cmd.

any more thoughts ?
jeddi is offline   Reply With Quote
Old 06-11-2006, 03:07 PM   PM User | #6
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
for this code:

PHP Code:
if(isset($_POST['run'])){  // BIG IF 

     
PROCESSES THE PICT_FM.PHP   FORM 

   
echo "got here"
}  
// end BIG IF 

else    { 
    
$message1 "none"
    
$message2 "none"
     require_once (
"a_picts_fm.php");    //  CALLS THE FORM 
     
exit(); 
    } 
// end else 

echo " *** and got here";    

  
//  THIS WHERE IT STOPS 

?> 
instead of putting this code into an include file, you could try dumping all of this code into a function that is called on the main page.....or you could just put the include file code in with the rest of the code on the main page...and you might try using die() instead of exit(), though i doubt that will make any difference, but maybe worth a try...
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 06-11-2006, 03:13 PM   PM User | #7
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Actually the script gets past that point anyway because it prints out
" *** and got here" - which is AFTER that exit()cmd.
this is likely occurring because the output buffer information was sent to the browser before script execution ends...try reading through the info/comments at the bottom of this page: http://us3.php.net/manual/en/function.exit.php
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 06-11-2006, 03:29 PM   PM User | #8
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,512
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
the Error_reporting (E_ALL)

throw up an error.

to check into it I need to list the contents of the _FILES array.

I have used a form to capture the name of a file using
the type="file" input

like this:

PHP Code:
<form name="main_fm" enctype ="multipart/form-data" action="aaa_process.php" method="POST"> 
<input type = 'hidden' name='run' value="on"> 
<input type="hidden" name ="MAX FILE SIZE" value="500000"> 
<input type = 'hidden' name='adref' value="<?php echo $A_ref ?>"> 

<div style='position:absolute; left:40px; top:320px' > 
<input type="file" size="50" id = "u1" name="upLoad1" ><br /> 
<input type="text" size="50" id = "n1" name="fName1" readonly> 
</div>

How do find out what the contents of the _FILES array is and display them to screen ?

Last edited by jeddi; 06-11-2006 at 03:39 PM..
jeddi is offline   Reply With Quote
Old 06-11-2006, 03:38 PM   PM User | #9
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,512
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
The reason why the included script a_picts is not in the main script is becaues the form needs to re-initate it to perform the validation.
It does this with the action="a_picts.php" stmt.
jeddi is offline   Reply With Quote
Old 06-11-2006, 05:54 PM   PM User | #10
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
How do find out what the contents of the _FILES array is and display them to screen ?
this should do it i think:

PHP Code:
foreach ($_FILES as $key => $val)
{
       echo 
$_FILES[$key]['name'] . "<br>";

__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:43 PM.


Advertisement
Log in to turn off these ads.