0

I have a doubt on the following code. My function is not called when the save button is clicked .

This is the following code for save function,

 if(isset($_POST['Save'])) // If the submit button was clicked
    {
        echo "hgfd";
        $post['ProductSegmentCode'] = $_POST['ProductSegmentCode'];
        $post['ProductSegment'] = $_POST['ProductSegment'];
        $post['ProductGroup'] = $_POST['productgroup'];

        // This will make sure its displayed
        if(!empty($_POST['ProductSegment'])&&!empty($_POST['ProductSegmentCode'])&&!empty($_POST['productgroup']))
        {   

                echo "SAVE";
             $news->addNews($post);
        ?>
            <script type="text/javascript">
            alert("Created Sucessfully..!!");
            </script>
            <?
        }
        else
        {
            ?>
            <script type="text/javascript">
            alert("Enter Mandatory Fields");
            </script>
            <?
        }
    }

following is the button format in html,

<div style="width:70px; height:32px; float:left; margin-top:16px; margin-left:4px;">

                      <input name="Save" type="button" class="button" value="Save">
                           </div>
3
  • button format in html missing? Commented Oct 4, 2012 at 5:50
  • What is onclick="Save" supposed to do? Is there an accompanying Javascript function? Are you misunderstanding how PHP and forms interact? Commented Oct 4, 2012 at 5:54
  • put ` print_r($_POST)before isset()` clause and see whats being posted, that will get you futher Commented Oct 4, 2012 at 6:50

3 Answers 3

2

Your button is type="button"; to get the form to submit, it needs to be type="submit". Try updating it with this and it should work (also pending you form has action="post", or no action specified; the default is post):

<input name="Save" type="submit" class="button" value="Save" onclick="Save" />

Also, you're using onclick="Save" in your button. This indicates you have a corresponding JavaScript function named Save() - though, per your code examples you do not show one. I'm assuming that this is in error and can safely be removed (the value="Save" can also be removed as you only need to check isset($_POST['Save']) and not it's actual value). All changes in-place should give you:

<input name="Save" type="submit" class="button" />

If you do, in fact, have a JavaScript function named Save(), please post its code and I can revise.

Sign up to request clarification or add additional context in comments.

Comments

0

use form for sending data and use type submit

<form action="" method="post">
  <input name="Save" type="submit" class="button" value="Save">
</form>

and if you want to use this

<input name="Save" type="button" class="button" value="Save" onclick="Save()">

create Save() function in javascript and use ajax call for sending data.

Comments

0

It looks like you should change

<input name="Save" type="button" class="button" value="Save" onclick="Save">

to a summit button.

<input name="Save" type="submit" class="button" value="Save">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.