Asked  7 Months ago    Answers:  5   Viewed   32 times

In a nutshell on "page1.php" I have a calculator that consists of an HTML form, and then the PHP code totals the input and displays the total price. Below the price, it also displays a link to "page2.php" which contains an HTML form where they can enter their contact information. Upon submitting the form the selections they made on "page1.php" in the pricing calculator as well as the contact info on "page2.php" are emailed to me, and they are redirected to the home page.

In the email that is submitted to me, I receive the contact info from "page2.php", but I don't receive anything from "page1.php", so the variables are not getting correctly passed. In addition to the PHP on each page, I am using hidden values in an HTML form on "page2.php" to echo the data that was entered in the HTML form on "page1.php". I know that one of my issues is that I have a couple of $_GET fields when my form is "post".

However when I change it so that everything is $_POST, the calculator no longer works. I tried to put this altogether with different snippets of code suggested by others. The form on "page1.php" has 13 fields, named "one" - "thirteen". $total display the values of 1-13.

  $submit = $_GET['submit'];
  if($submit == "true")
    $total = ($_POST['one'] + $_POST['two'] + $_POST['three'] + $_POST['four']  + 
    $_POST['five'] + $_POST['six'] + $_POST['seven'] + $_POST['eight']+ $_POST['nine'] + 
    $_POST['ten']+ $_POST['eleven'] + $_POST['twelve']+ $_POST['thirteen']); 
    echo  " Your Price is $ " .number_format ($total, 2, '.', ','). "<BR>";
    echo ('">Get Your Project Started</a>');

The second form uses hidden values to echo the info from page1.php, and has three more fields named "name", "email" and "details".

  $to = "";
  $message = "Pages:t$_POST[one]n";
  $message .= "Pages:t$_POST[two]n";
  $message .= "Pages:t$_POST[three]n";
  $message .= "Ecommerce:t$_POST[four]n";
  $message .= "No Ecommerce:t$_POST[five]n";
  $message .= "CMS:t$_POST[six]n";
  $message .= "No CMS:t$_POST[seven]n";
  $message .= "Audio or Video:t$_POST[eight]n";
  $message .= "Flash Intro:t$_POST[nine]n";
  $message .= "Image Gallery:t$_POST[ten]n";
  $message .= "Graphic Design or Logo:t$_POST[eleven]n";
  $message .= "Copy:t$_POST[twelve]n";
  $message .= "Images:t$_POST[thirteen]n";
  $message .= "Price Total:t$_POST[total]n";
  $message .= "Name:t$_POST[name]n";
  $message .= "Email:t$_POST[email]n";
  $message .= "n";
  $message .= "n";
  $message .= "Details:t$_POST[details]n";
  mail($to, $subject, $message, $headers) ;

So what would be the correct PHP to put on "page1.php" and "page2.php"? Sorry the code is such a mess, if anyone could point me in the right direction, that would be great.



PHP is stateless unless you save things in session (which isn't secure right?)

You would need to make page2.php read all the values from page1.php and store them either in a server side state (session) or a client state (cookies or maybe hidden fields in the form)

If you want any of this secure or a secret, then you have to consider all of that as well. Nothing I explained is secret or secure in any way.

EDIT: here is an example of page1.php that sends the values of page1.php to page2.php as get parameters. You can do this with hidden fields, cookies or sessions as well.

What is important to remember is that page2.php is totally unaware of page1.php, and can't get to the values like you could it forms programming. Each page starts and ends it's life by the time you see a full web page, so you have to use some extra tricks to keep values. Those tricks are sessions, cookies, form posts, or gets.

<title>Page 1</title>
//set defaults assuming the worst
$total = 0;
$one =0;

//verify we have that value in $__POST
if (isset($_POST['submit']))
    $submit = $_POST['submit'];
    //If it is true, try some math
    if($submit == "sub-total")
            if (isset($_POST['one']))
                $one = $_POST['one'];
                //Add checks to see if your values are numbers
                if ( ! is_numeric($one)) { $one = 0;}

            if (isset($_POST['two']))
                $two = $_POST['two'];
                if ( ! is_numeric($two)) { $two = 0;}
            $total = $one + $two;
            echo " Your Price is $ " .number_format ($total, 2, '.', ','). "<BR>";
    if($submit == "submit" )
        //go to page two, with the total from page1.php passed as a $__GET value
        header("Location: page2.php?total=".$total);
    <form method="post" action="page1.php?submit=true">
        <input type="text" name="one" id="one" value="<?=$one?>"/>
        <input type="text" name="two" id="two"  value="<?=$two?>"/>
        <input type="submit" name="submit" value="sub-total" />
        <input type="submit" name="submit" value="submit" />
Wednesday, March 31, 2021
answered 7 Months ago

SOLUTION: after many hours of searching, it seems this problem was occurring when I access my website without adding the "www." before the domain. so what actually was happening is, I was logging in with sets session somewhere, that my member control doesn't recognize, so it redirects me back to, that when I login everything works Ok.

when I login from (with the www.) it logs in correctly from first attemp.

So I added a code to make sure I always have the www in the URL:

if ($_SERVER['HTTP_HOST'] == "")
   $url = "http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header("Location: $url");

and everything works well now. Hope it helps someone.

Wednesday, March 31, 2021
answered 7 Months ago

If this code is running, you should be seeing a ton of debug output, even if it is working correctly. You don't actually say what the problem is, but you're doing a few things wrong that I can see. It would really help if you based your code on the examples provided and read the docs instead of just guessing.

$mail->SMTPSecure = 'TLS';

should be:

$mail->SMTPSecure = 'tls';

Don't call smtpConnect() yourself, you'll mess up the tracking of SMTP transaction state. If you want to set SSL params, set them the expected way and then just call send(), which will deal with the connection:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true

The next question is why are you doing that? If you can't provide an explicit, specific reason for doing that, you're doing something wrong.

Saturday, May 29, 2021
answered 5 Months ago

The easiest way to do this would be to pass the session id to the signout activity in the Intent you're using to start the activity:

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);

Access that intent on next activity:

String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");

The docs for Intents has more information (look at the section titled "Extras").

Tuesday, June 1, 2021
answered 5 Months ago

The setUp() method is always called before tests, so even if you set up a dependency between two tests, any variables set in setUp() will be overwritten. The way PHPUnit data passing works is from the return value of one test to the parameter of the other:

class JsonRpcBitcoinTest extends PHPUnit_Framework_TestCase
    public function setUp()
        global $configRpcUser, $configRpcPass, $configRpcHost, $configRpcPort;

        $this->bitcoindConn = new JsonRpcBitcoin($configRpcUser, $configRpcPass, $configRpcHost, $configRpcPort);
        $this->blockHash = '';

    public function testCmdGetBlockHash()
        $result = (array)json_decode($this->bitcoindConn->getblockhash(20));

        return $result['result']; // the block hash

     * @depends testCmdGetBlockHash
    public function testCmdGetBlock($blockHash) // return value from above method
        $result = (array)json_decode($this->bitcoindConn->getblock($blockHash));
        $this->assertEquals($result['error'], $blockHash);

So if you need to save more state between tests, return more data in that method. I would guess that the reason PHPUnit makes this annoying is to discourage dependent tests.

See the official documentation for details.

Friday, August 13, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :