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>
Your button is
type="button"; to get the form to submit, it needs to betype="submit". Try updating it with this and it should work (also pending you form hasaction="post", or no action specified; the default ispost):Also, you’re using
onclick="Save"in your button. This indicates you have a corresponding JavaScript function namedSave()– though, per your code examples you do not show one. I’m assuming that this is in error and can safely be removed (thevalue="Save"can also be removed as you only need to checkisset($_POST['Save'])and not it’s actual value). All changes in-place should give you:If you do, in fact, have a JavaScript function named
Save(), please post its code and I can revise.