Reputation: 15
I wrote the following code in a page named : addSection.php
<from class="mainSettingsForm add" action="" method="post">
<h1>Add new section</h1>
<p>
<label>new section</label>
<input type="text" name="section_name" placeholder="section title">
<label>section status</label>
<select name="sectionStatus">
<option value="active">active</option>
<option value="disActive">disActive</option>
</select>
</p>
<p>
<label>section location</label>
<select name="sectionLocation">
<option value="Side">Side</option>
<option value="Body">Body</option>
</select>
</p>
<label>section description</label>
<textarea name="sectionDesc" placeholder="Section description"></textarea>
<input class="btn-primary" type="submit" name="submit" value="Add">
</from>
and the following code in a page named : Sections.php
<h2><a href="?page=sections&action=add">Add new section</a></h2>
<?php
if ($_POST OR @$_GET['action'])
{
if (isset($_GET['action']) AND $_GET['action']=="add")
{
include 'views/addSection.php';
if (isset($_POST['submit'])&&$_POST['submit']=="Add")
echo 'ok';
}
}
else
{
include 'views/sections.php';
}
?>
this statement if (isset($_POST['submit'])&&$_POST['submit']=="Add") echo 'ok'; is never be executed because it always gives false value , how can make isset($POST['submit']) statement gives true value to execute the condition ?
Upvotes: 0
Views: 2204
Reputation: 3738
Please try my code. This will help you to understand what are you passing. I also fix the form tag - as @Hobo Sapiens suggested.
<?php print_r($_REQUEST);?>
<form class="mainSettingsForm add" action="" method="post">
<h1>Add new section</h1>
<p>
<label>new section</label>
<input type="text" name="section_name" placeholder="section title">
<label>section status</label>
<select name="sectionStatus">
<option value="active">active</option>
<option value="disActive">disActive</option>
</select>
</p>
<p>
<label>section location</label>
<select name="sectionLocation">
<option value="Side">Side</option>
<option value="Body">Body</option>
</select>
</p>
<label>section description</label>
<textarea name="sectionDesc" placeholder="Section description"></textarea>
<input class="btn-primary" type="submit" name="submit" value="Add">
</form>
Upvotes: 0
Reputation: 27687
Your statement can never be true because the second IF statement is only for $_GET
variables and then you try to access $_POST
inside it. You can't have a GET and a POST at the same time.
You also have a few typos - $_GET['action']
will be "Add" not "add" and you have <from>
instead of <form>
in your HTML.
if ( isset( $_POST['submit'] ) && $_POST['submit'] == "Add" ){
echo "this is a POST and submit is add";
} elseif ( isset( $_GET['action']) && $_GET['action'] == "Add" ){
echo "this is a GET and submit is add";
} else {
include 'views/sections.php';
}
Upvotes: 0