Php Mates,
I have built an html form where atleast one of the input fields must be filled. If not one filled atleast then show error.
I tried these ways but none of them work:
[code]
<?php
//Required PHP Files.
include ‘config.php’; //Required on all webpages of the site.
//Check if User is already logged-in or not. Get the login_check() FUNCTION to check.
if (login_check() === FALSE)
{
//Redirect User to Log-in Page immediately.
//header(“refresh:0; url=home.php”);
header(“location:login.php”);
exit();
}
if ($_SERVER[‘REQUEST_METHOD’] == “POST”)
{
//Step 2: Check User submitted details.
//Check if User made any inputs or not.
if (!isset($_POST[“one”]) &
!isset($_POST[“two”]) &
!isset($_POST[“three”]) &
!isset($_POST[“four”]) &
!isset($_POST[“five”]))
{
echo “not ISSET”;
echo “You must atleast make an input in one field”;
}
else
{
echo “ISSET”;
echo “”; //How to show the ISSET one here ? (The field that has been filled in).
}
}
?>
<form method=”post” action=””>
<p align=”left”><h2>QuickLink Submission Form</h2></p>
<div class=”form-group”>
<p align=”left”><label>One:</label>
<input type=”url” name=”one” autocorrect=off value=”<?php if(isset($_POST[‘one’])) { echo htmlentities($_POST[‘one’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Two:</label>
<input type=”url” name=”two” autocorrect=off value=”<?php if(isset($_POST[‘two’])) { echo htmlentities($_POST[‘two’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Three:</label>
<input type=”url” name=”three” autocorrect=off value=”<?php if(isset($_POST[‘three’])) { echo htmlentities($_POST[‘three’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Four:</label>
<input type=”url” name=”four” autocorrect=off value=”<?php if(isset($_POST[‘four’])) { echo htmlentities($_POST[‘four’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Five:</label>
<input type=”url” name=”five” autocorrect=off value=”<?php if(isset($_POST[‘five’])) { echo htmlentities($_POST[‘five’]); }?>”></p>
</div>
<p align=”left”><button type=”submit” class=”btn btn-default” name=submit”>Submit!</button></p>
</form>
</div>
</body>
</html>
get error:
Parse error: syntax error, unexpected ‘echo’ (T_ECHO) in C:xampphtdocstestsettings.php on line 27
Q1. What is wrong ?
Line 27 is this:
[code]
echo “You must atleast make an input in one field”;
Ok. Making another attempt ….
[code]
<?php
//Required PHP Files.
include ‘config.php’; //Required on all webpages of the site.
//Check if User is already logged-in or not. Get the login_check() FUNCTION to check.
if (login_check() === FALSE)
{
//Redirect User to Log-in Page immediately.
//header(“refresh:0; url=home.php”);
header(“location:login.php”);
exit();
}
if ($_SERVER[‘REQUEST_METHOD’] == “POST”)
{
//Step 2: Check User submitted details.
//Check if User made any inputs or not.
if (!isset($_POST[“one”]) &
!isset($_POST[“two”]) &
!isset($_POST[“three”]) &
!isset($_POST[“four”]) &
!isset($_POST[“five”]))
{
echo “not ISSET”;
echo $_POST[“one”];
echo $_POST[“two”];
echo $_POST[“three”];
echo $_POST[“four”];
echo $_POST[“five”];
}
else
{
echo “ISSET”;
echo “”; //How to show the ISSET one here ? (The field that has been filled in).
}
}
?>
<form name “settings_form” method = “post” action=”” enctype = “multipart/form-data”>
<p align=”left”><h2>QuickLink Submission Form</h2></p>
<div class=”form-group”>
<p align=”left”><label>One:</label>
<input type=”url” name=”one” autocorrect=off value=”<?php if(isset($_POST[‘one’])) { echo htmlentities($_POST[‘one’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Two:</label>
<input type=”url” name=”two” autocorrect=off value=”<?php if(isset($_POST[‘two’])) { echo htmlentities($_POST[‘two’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Three:</label>
<input type=”url” name=”three” autocorrect=off value=”<?php if(isset($_POST[‘three’])) { echo htmlentities($_POST[‘three’]); }?>”></p>
</div>
<div class=”form-group”>
<p align=”left”><label>Four:</label>
<input type=”url” name=”four” autocorrect=off value=”<?php if(isset($_POST[‘four’])) { echo htmlentities($_POST[‘four’]); }?>”></p>
</div>
<p align=”left”><button type=”submit” class=”btn btn-default” name=submit”>Submit!</button></p>
</form>
I get error:
Notice: Undefined index: one in C:xampphtdocsfollowing_browserWORKINGCOMPLETEsettings.php on line 28
Notice: Undefined index: two in C:xampphtdocstest.php on line 29
Notice: Undefined index: three in C:xampphtdocstest.php on line 30
Notice: Undefined index: four in C:xampphtdocstest.php on line 31
Notice: Undefined index: five in C:xampphtdocstest.php on line 32
Q2. Have I got my issets and my &s correct to achieve what I want ? If not, then care to show another way with a code sample.
Do bare in mind that, I want php to give error if atleast one input field is not filled out of the five.
Thanks!