Jump to content

Recommended Posts

Hello:

 

Did a quick search, came up with nothing.  Here is the problem, I have two websites, running on the same server, both running the same version of PHP and the same version of mySQL.

 

One the first page, everything is working properly, or so I think.  I set a few variables using a POST from another page, I then define a function, that has no arguments specified, it then returns one value using the variables set via POST.  Later in the code I call the function.  Everything sets itself properly.

 

On my other page, I do exactly the same thing, unless I am missing something that I have done differently, my code does not return any values.  I then tried passing values using arguments with no luck.  The code is below, with chunks of it removed...

 

 

This works:

 


//Load the database configuration file, and setup the connection to the database and error handling

require_once ('config.php');

//Obtain the values from the previous form

$Method = $_POST['Method'];

//Determine how we should set the year and month, from the member-index page or via today's date

if ($Method == '')
{
//Get todays date month and year for the photo of the month addition

$Year = date("Y");
$Month = date("m");
}
else
{
//Set the date based on the values from the form

$Month = $_POST['Month'];
$Year = $_POST['Year'];
}

/**
* Define the function to create the common part of the form
*/

function funCreateCommonForm()
{
//Define the common parts of the form

$CommonForm = '<table id="InfoTable">
        <tbody>
            <tr align="center">
                <th colspan=2>Add a PoTM</th>
            </tr>
            <tr>
                <td>Photo number: <font color="red"><strong>*</strong></font></td>
                <td><input name="Photo" type="text" size="15" maxlength="6" value="' . $Photo . '"></td>
            </tr>
            <tr>
                <td>Month: <font color="red"><strong>*</strong></font></td>
                <td><input name="Month" type="text" size="15" maxlength="2" value="' . $Month . '"></td>
            </tr>
            <tr>
                <td>Year: <font color="red"><strong>*</strong></font></td>
                <td><input name="Year" type="text" size="15" maxlength="4" value="' . $Year . '"></td>
            </tr>
                <tr align="center">
                <td colspan="2"><input type="submit" value="Place Entry"></td>
            </tr>
        </tbody>
    </table>';

//Return the value

return $CommonForm;
}

/**
* End of function definition
*/

//Determine what the form should do

if ($Method == '')
{
//NEW REGISTRY ENTRY

//Define the page title

$page_title = 'Create A Photo of the Month Entry';

//Call the function to create the common parts of the form

$CommonForm = funCreateCommonForm();

//Define the rest of the form

$form = '<form name="PoTMForm" method="post" action="potm-exec.php">' . $CommonForm .'<input name="Method" type="hidden" class="textfield" value="New"></form>';

}

 

Any ideas why this is working on one page, but the similarly coded page doesn't work?

 

 

Link to comment
https://forums.phpfreaks.com/topic/192830-php-functions-working-differently/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.