/    Sign up×
Community /Pin to ProfileBookmark

require_once problem ??

Hi

I am running a script
which includes the following lines

[code=php]
/*
* Now we get the pictures.
*/
if( $pict == “y”){
require_once(“a_picts.php”);
} // endif
else{
$N_pix1=$N_pix2=$N_pix3=$N_pix4=$N_pix5=”none”;
} // end else

$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”);

[/code]

Within the called a_picts.php is another require
stmt to include a form.

[code=php]require_once (“a_picts_fm.php”);
exit();[/code]

this form when submitted reruns a_picts.php in order to process it.

<form name=”main_fm” enctype =”multipart/form-data” action=”a_picts.php” method=”POST”>

OK – pretty std.

But when the a_picts.php has finished – it does not return to the script that called it. I was expecting it to return to the point just after it was called from and then continue executing the next statements i.e. update the homes table.

Well it doesn’t – a_picts.php gets to the end and then hangs – just stops.

Why is this – what have I done wrong ?

Thanks

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 08.2006 — That is because [I]exit();[/I] aborts the script.
Copy linkTweet thisAlerts:
@DaveinLondonauthorJun 08.2006 — Not sure if that is the reason ...

The scripts are too long to post in full so I have chopped off most of it but left the problem ares

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

  • - dont know why ???


  • The First script calls the picture loading script:

    [code=php]
    <?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'])){ // BIG IF the main form has NOT run.

    PREPARES DATA AND CALLS MAIN FORM ( NOT PICTURE FORM)

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

    VALIDATES FORM DATA

    /*
    * Now we get the pictures.
    */
    if( $pict == "y"){
    require_once("a_picts.php"); // < -- HERE IS THE CALLING
    } // endif
    else{
    $N_pix1=$N_pix2=$N_pix3=$N_pix4=$N_pix5="none";
    } // end else

    // I WANT TO RETURN BACK HERE

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

    /*
    * Update the client table
    */
    ETC ETC

    } // end BIG else

    ?>
    [/code]



    HERE IS THE SCRIPT THAT IT CALLS :

    THE PROBLEM IS THAT THIS SCRIPT STOPS AT THE LAST LINE

    AFTER EXECUTING THIS:

    echo " *** and got here";

    IT DOESN'T RETURN TO HOMES_ADD.PRG


    [code=php]
    <?php
    /*
    * a_picts.php
    *
    * Called by : homes_add.php
    *
    * calls a_picts_fm.php
    *
    * Gets pictures for the advert and checks them out
    */

    if(isset($_POST['run'])){ // BIG IF
    $pix1_y = $pix2_y = $pix3_y = $pix4_y = $pix5_y = "n";

    $A_ref = strip_tags(trim($_POST["adref"]));
    $N_pix1 = strip_tags(trim($_FILES['upLoad1'][name]));
    $N_pix2 = strip_tags(trim($_FILES['upLoad2'][name]));
    $N_pix3 = strip_tags(trim($_FILES['upLoad3'][name]));
    $N_pix4 = strip_tags(trim($_FILES['upLoad4'][name]));
    $N_pix5 = strip_tags(trim($_FILES['upLoad5'][name]));
    $ctr = 0;

    // Checking image in pix files.

    if($N_pix1 != ""){
    if($_FILES['upLoad1']['tmp_name'] == "none") {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 500K";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad1']['type'])) {
    $message1 = "The file you have selected for Picture 1 is not";
    $message2 = "a recognised picture file - Please try a different file";
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix1_y = "y";
    } // endif
    else{
    $N_pix1 = "none";
    } // end else

    if($N_pix2 != ""){
    if($_FILES['upLoad2']['tmp_name'] == "none") {
    $message1 = "Picture file 2 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 500K";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad2']['type'])) {
    $message1 = "The file you have selected for Picture 2 is not";
    $message2 = "a recognised picture file - Please try a different file";
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix2_y = "y";
    } // endif
    else{
    $N_pix2 = "none";
    } // end else

    if($N_pix3 != ""){
    if($_FILES['upLoad3']['tmp_name'] == "none") {
    $message1 = "Picture file 3 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 500K";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad3']['type'])) {
    $message1 = "The file you have selected for Picture 3 is not";
    $message2 = "a recognised picture file - Please try a different file";
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix3_y = "y";
    } // endif
    else{
    $N_pix3 = "none";
    } // end else

    if($N_pix4 != ""){
    if($_FILES['upLoad4']['tmp_name'] == "none") {
    $message1 = "Picture file 4 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 500K";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad4']['type'])) {
    $message1 = "Picture file did not successfully upload: Pix 4" ;
    $message2 = "a recognised picture file - Please try a different file";
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix4_y = "y";
    } // endif
    else{
    $N_pix4 = "none";
    } // end else

    if($N_pix5 != ""){
    if($_FILES['upLoad5']['tmp_name'] == "none") {
    $message1 = "Picture file 5 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 500K";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad5']['type'])) {
    $message1 = "The file you have selected for Picture 5 is not";
    $message2 = "a recognised picture file - Please try a different file";
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix5_y = "y";
    } // endif
    else{
    $N_pix5 = "none";
    } // end else

    /*
    * Everything seems ok - so we connect to the database and
    * move the images to the website.
    */

    if($pix1_y == "y"){
    $destination = 'D:WebDWimages'."\".$_FILES['upLoad1']['name'];
    $temp_file = $_FILES['upLoad1']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    } // endif

    if($pix2_y == "y"){
    $destination = 'D:WebDWimages'."\".$_FILES['upLoad2']['name'];
    $temp_file = $_FILES['upLoad2']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    } // endif

    if($pix3_y == "y"){
    $destination = 'D:WebDWimages'."\".$_FILES['upLoad3']['name'];
    $temp_file = $_FILES['upLoad3']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    } // endif

    if($pix4_y == "y"){
    $destination = 'D:WebDWimages'."\".$_FILES['upLoad4']['name'];
    $temp_file = $_FILES['upLoad4']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    } // endif

    if($pix5_y == "y"){
    $destination = 'D:WebDWimages'."\".$_FILES['upLoad5']['name'];
    $temp_file = $_FILES['upLoad5']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    } // endif

    echo "got here";
    } // end BIG IF

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

    echo " *** and got here"; // THIS WHERE IT STOPS

    ?>
    [/code]


    AND HERE IS THE FORM SCRIPT THAT A_PICTS.PHP CALLS:

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


    <div style='position:absolute; left:370px; top:280px' >
    <input type="submit" value="Upload All Images"><br />
    <input type="reset" value="Reset All Images"
    onclick="
    document.getElementById('image1').src='';document.getElementById('image1').style.display='none'
    document.getElementById('image2').src='';document.getElementById('image2').style.display='none'
    document.getElementById('image3').src='';document.getElementById('image3').style.display='none'
    document.getElementById('image4').src='';document.getElementById('image4').style.display='none'
    document.getElementById('image5').src='';document.getElementById('image5').style.display='none'
    ">
    </div>

    </form>
    </body>
    </html>
    [/code]
    Copy linkTweet thisAlerts:
    @bokehJun 08.2006 — Not sure if that is the reason ...[/QUOTE]Well your script contains an [I]exit()[/I] and it is impossible to pass that point without the script aborting.
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorJun 08.2006 — The reason why the exit shouldn't effect it is because it is in

    an else statement that is only run once.

    I have condensed the script :

    the "got here"

    and the

    "*** and got here"

    both print out to the screen

    (thats after the exit stmt ) - and THEN the script stops.


    [code=php]
    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");
    exit();
    } // end else

    echo " *** and got here"; // THIS WHERE IT STOPS

    ?> [/code]


    BUT see other two scripts in prior posting.
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorJun 09.2006 — I have tried taking out the exit , but as I thought the script doesn't work if I do that - reason : when there is no exit after calling the form, after displaying the form in a_picts_fm - with no exit the script doesn't wait for response from the form but continues the script. I think its almost always the case to have exit after calling a form.

    Again - it is clear that the problem is not in returning from a_picts_fm back to a_picts - BUT the problem is returning from a_picts back to the homes_add script.

    I wonder if there is a fundamental structural problem ?

    The main script (homes_add)

    calls ( require_once ) the a_picts which processes the form.

    The form itself on submisson re-runs the a_picts which when finshed should return to the main script (homes_add) and continue from where it left the off.

    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

  • - dont know why ???


  • I have stripped out more code to try and make it clearer.

    ? 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

    [code=php]
    <?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"){

    require_once("a_picts.php"); // < -- HERE IS THE CALLING
    exit(); // < -- I TRIES TAKING THIS OUT

    } // endif
    else{
    $N_pix1=$N_pix2=$N_pix3=$N_pix4=$N_pix5="none";
    } // end else

    // I WANT TO RETURN BACK HERE

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

    /*
    * Update the client table
    */
    ETC ETC

    } // end BIG else

    ?> [/code]




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

    THE FORM

    [code=php]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

    ?> [/code]


    AND THIS IS THE FORM THAT THE ABOVE REQUIRES


    Code:

    <?php

    /*

    *
    picts_fm.php

    *

    *
    Called by : picts.php

    * IT THEN GOES BACK TO PICTS.PHP

    *



    * FORM for adding images.

    *


    */

    ?>


    [code=php]<!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> [/code]
    ×

    Success!

    Help @DaveinLondon spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.9,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...