Problems with 'if' statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mantrid

    Problems with 'if' statement

    Hello
    I have used the following php script in the form action to determine whether
    to post the same page again or open the php file called excelsave.php
    depending on which of two submit buttons is pressed in the form

    <form action="<?php if(isset($updat estats)){
    echo $_SERVER['PHP_SELF'];
    }else{
    ?>excelsave.php <?php
    }?>" method="post" enctype="multip art/form-data"
    name="savestatm ents">


    problem is whatever button is pressed the excel.php is run. what is wrong
    with my 'if.. ' statement?

    ian


  • rallykarro@hotmail.com

    #2
    Re: Problems with 'if' statement

    Hi,

    what do you think about

    <form action="<? if(isset($updat estats))
    echo $_SERVER['PHP_SELF'];
    else
    echo "excelsave.php" ;
    ?>" method="post" enctype="multip art/form-data"
    name="savestatm ents">

    regards,

    karolina

    mantrid skrev:
    Hello
    I have used the following php script in the form action to determine whether
    to post the same page again or open the php file called excelsave.php
    depending on which of two submit buttons is pressed in the form
    >
    <form action="<?php if(isset($updat estats)){
    echo $_SERVER['PHP_SELF'];
    }else{
    ?>excelsave.php <?php
    }?>" method="post" enctype="multip art/form-data"
    name="savestatm ents">
    >
    >
    problem is whatever button is pressed the excel.php is run. what is wrong
    with my 'if.. ' statement?
    >
    ian

    Comment

    • mantrid

      #3
      Re: Problems with 'if' statement


      <rallykarro@hot mail.comwrote in message
      news:1155240278 .424381.289790@ m79g2000cwm.goo glegroups.com.. .
      Hi,
      >
      what do you think about
      >
      <form action="<? if(isset($updat estats))
      echo $_SERVER['PHP_SELF'];
      else
      echo "excelsave.php" ;
      ?>" method="post" enctype="multip art/form-data"
      name="savestatm ents">
      >
      regards,
      >
      karolina
      >
      mantrid skrev:
      >
      no sorry that didnt work either
      whats a skrev?


      Comment

      • Alvaro G. Vicario

        #4
        Re: Problems with 'if' statement

        *** mantrid escribió/wrote (Thu, 10 Aug 2006 19:27:45 GMT):
        <form action="<?php if(isset($updat estats)){
        echo $_SERVER['PHP_SELF'];
        }else{
        ?>excelsave.php <?php
        }?>" method="post" enctype="multip art/form-data"
        name="savestatm ents">
        >
        >
        problem is whatever button is pressed the excel.php is run. what is wrong
        with my 'if.. ' statement?
        I find it pretty unlikely that the problem is in the if() part. What makes
        you think so? Have you var_dumped() your $_POST array? Does $updatestats
        have the correct value?


        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        • Jerry Stuckle

          #5
          Re: Problems with 'if' statement

          mantrid wrote:
          Hello
          I have used the following php script in the form action to determine whether
          to post the same page again or open the php file called excelsave.php
          depending on which of two submit buttons is pressed in the form
          >
          <form action="<?php if(isset($updat estats)){
          echo $_SERVER['PHP_SELF'];
          }else{
          ?>excelsave.php <?php
          }?>" method="post" enctype="multip art/form-data"
          name="savestatm ents">
          >
          >
          problem is whatever button is pressed the excel.php is run. what is wrong
          with my 'if.. ' statement?
          >
          ian
          >
          >
          Ian,

          I think your problem is not the if statement - I suspect $updatestats
          isn't being set. What code do you have that sets it?

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • mantrid

            #6
            Re: Problems with 'if' statement

            >
            I think your problem is not the if statement - I suspect $updatestats
            isn't being set. What code do you have that sets it?
            >

            That occured to me so I tried

            <form action="<?php if(isset($_POST['updatestats'])){

            instead of

            <form action="<?php if(isset($updat estats)){

            but still no luck, but I got round it by getting rid of the 'if' in the form
            action and placing them at the top of the page, as below

            *************** *************** *************** *******
            if(isset($downl oad)){
            header("Locatio n: http://www.mysite.co.u k/excelsave.php") ;
            }

            if(isset($updat estats)){
            script for creating confirmation version of original page
            }

            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
            enctype="multip art/form-data"name="save statments">

            *************** *************** *************** ******
            However I would still like to know why the first method didnt work.
            Thanks all for the support


            Ian


            Comment

            • Jerry Stuckle

              #7
              Re: Problems with 'if' statement

              mantrid wrote:
              >>I think your problem is not the if statement - I suspect $updatestats
              >>isn't being set. What code do you have that sets it?
              >>
              >
              >
              >
              That occured to me so I tried
              >
              <form action="<?php if(isset($_POST['updatestats'])){
              >
              instead of
              >
              <form action="<?php if(isset($updat estats)){
              >
              but still no luck, but I got round it by getting rid of the 'if' in the form
              action and placing them at the top of the page, as below
              >
              *************** *************** *************** *******
              if(isset($downl oad)){
              header("Locatio n: http://www.mysite.co.u k/excelsave.php") ;
              }
              >
              if(isset($updat estats)){
              script for creating confirmation version of original page
              }
              >
              <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
              enctype="multip art/form-data"name="save statments">
              >
              *************** *************** *************** ******
              However I would still like to know why the first method didnt work.
              Thanks all for the support
              >
              >
              Ian
              >
              >
              Ian,

              Were you trying to change the action based on a click on the same page?
              If so, it won't work.

              PHP is server side. By the time the page gets to your browser, PHP has
              done its job and ended processing for this page.

              Your if statement should work if $_POST['updatestats'] was set when this
              page was called. But only then.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • mantrid

                #8
                Re: Problems with 'if' statement


                "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                news:geudnTFQ18 TRbUbZnZ2dnUVZ_ sudnZ2d@comcast .com...
                mantrid wrote:
                >I think your problem is not the if statement - I suspect $updatestats
                >isn't being set. What code do you have that sets it?
                >


                That occured to me so I tried

                <form action="<?php if(isset($_POST['updatestats'])){

                instead of

                <form action="<?php if(isset($updat estats)){

                but still no luck, but I got round it by getting rid of the 'if' in the
                form
                action and placing them at the top of the page, as below

                *************** *************** *************** *******
                if(isset($downl oad)){
                header("Locatio n: http://www.mysite.co.u k/excelsave.php") ;
                }

                if(isset($updat estats)){
                script for creating confirmation version of original page
                }

                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
                enctype="multip art/form-data"name="save statments">

                *************** *************** *************** ******
                However I would still like to know why the first method didnt work.
                Thanks all for the support


                Ian
                >
                Ian,
                >
                Were you trying to change the action based on a click on the same page?
                If so, it won't work.
                PHP is server side. By the time the page gets to your browser, PHP has
                done its job and ended processing for this page.
                >
                Your if statement should work if $_POST['updatestats'] was set when this
                page was called. But only then.
                >
                Yes silly me that was exactly what I was doing. and it works the second way
                because when the page it resent only then does $_POST['updatestats'] have a
                value. nice one, thanks
                ian




                Comment

                Working...