Mam ten formularz, który składa się dobrze. Problem polega na tym, że chciałem upewnić się, że pole formularza nie było puste. Teraz, gdy zostanie przesłany jako pusty, pokazuje komunikat o błędzie obok pola formularza "Support1". Ale nadal publikuje do bazy danych! Nie jestem pewien, dlaczego jego ignoruje się i kontynuuje instrukcję.

<?php
$service_id = trim($_GET['srvid']);
$service_name = trim($_GET['srvname']);
$year = $_GET["year"];

$x="SELECT
nfw_week.week_no
FROM
nfw_week";

$xx= mysql_query("$x") or die($myQuery."<br/><br/>".mysql_error());     

// POSTING FORM WEEKLY ANALYSIS FORM START

$poster = htmlspecialchars($_SERVER["PHP_SELF"]);
$support1error = "";
$support1 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["support1"])) {
$support1error = "Name is required";
} else {
$support1 = ($_POST["support1"]);
$conn2 = mysql_connect($dbhost, $dbuser, $dbpass);

$xplodedate = addslashes ($_POST['hiddenformfield']);
$xplodedatevar=explode(" ",$xplodedate);  
$weeknumvar=$xplodedatevar[0];
$datevar=$xplodedatevar[1];
date_default_timezone_set("Australia/Melbourne");
$myDate = date('Y-m-d');
   $myTime = date('H:i:s');
   $take1 = addslashes ($_POST['take1']);
   $take2 = addslashes ($_POST['take2']);
   $take3 = addslashes ($_POST['take3']);
   $take4 = addslashes ($_POST['take4']);
   $take5 = addslashes ($_POST['take5']);
   $take6 = addslashes ($_POST['take6']);
   $take7 = addslashes ($_POST['take7']);
   $taketotal = addslashes ($_POST['taketotal']);
   $service_id = addslashes ($_POST['service_id']);
   $service_name = addslashes ($_POST['service_name']);
   $hours1 = addslashes ($_POST['hours1']);
   $hours2 = addslashes ($_POST['hours2']);
   $hours3 = addslashes ($_POST['hours3']);
   $hours4 = addslashes ($_POST['hours4']);
   $hours5 = addslashes ($_POST['hours5']);
   $hours6 = addslashes ($_POST['hours6']);
   $hours7 = addslashes ($_POST['hours7']);
   $hourstotal = addslashes ($_POST['hourstotal']);
   $wages1 = addslashes ($_POST['wages1']);
   $wages2 = addslashes ($_POST['wages2']);
   $wages3 = addslashes ($_POST['wages3']);
   $wages4 = addslashes ($_POST['wages4']);
   $wages5 = addslashes ($_POST['wages5']);
   $wages6 = addslashes ($_POST['wages6']);
   $wages7 = addslashes ($_POST['wages7']);
   $wagestotal = addslashes ($_POST['wagestotal']);
   $prospecting1 = addslashes ($_POST['prospecting1']);
   $prospecting2 = addslashes ($_POST['prospecting2']);
   $prospecting3 = addslashes ($_POST['prospecting3']);
   $prospecting4 = addslashes ($_POST['prospecting4']);
   $prospecting5 = addslashes ($_POST['prospecting5']);
   $prospecting6 = addslashes ($_POST['prospecting6']);
   $prospecting7 = addslashes ($_POST['prospecting7']);
   $prospectingtotal = addslashes ($_POST['prospectingtotal']);
   $weather1 = addslashes ($_POST['weather1']);
   $weather2 = addslashes ($_POST['weather2']);
   $weather3 = addslashes ($_POST['weather3']);
   $weather4 = addslashes ($_POST['weather4']);
   $weather5 = addslashes ($_POST['weather5']);
   $weather6 = addslashes ($_POST['weather6']);
   $weather7 = addslashes ($_POST['weather7']);
   $jobs1 = addslashes ($_POST['jobs1']);
   $jobs2 = addslashes ($_POST['jobs2']);
   $jobs3 = addslashes ($_POST['jobs3']);
   $jobs4 = addslashes ($_POST['jobs4']);
   $jobs5 = addslashes ($_POST['jobs5']);
   $jobs6 = addslashes ($_POST['jobs6']);
   $jobs7 = addslashes ($_POST['jobs7']);
   $jobstotal = addslashes ($_POST['jobstotal']);
   $support2 = addslashes ($_POST['support2']);
   $support3 = addslashes ($_POST['support3']);
   $support4 = addslashes ($_POST['support4']);
   $support5 = addslashes ($_POST['support5']);
   $weeklyyear = addslashes ($_POST['weekly_report_year']);
   $service_name1 = addslashes ($_POST['service_name']);
   $service_id1 = addslashes ($_POST['service_id']);
   //not doing anything with the below yet. needs to be added to the database as a row and the sql query
   //$paidfees = addslashes ($_POST['haveyoupaidfees']);

$sql2 = "INSERT INTO nfw_weekly_report ".
       "(record_date, week_no, record_time, takings_sunday, takings_monday, takings_tuesday, takings_wednesday, takings_thursday, takings_friday, takings_saturday, takings_total,
        hours_sunday, hours_monday, hours_tuesday, hours_wednesday, hours_thursday, hours_friday, hours_saturday, hours_total,
        wages_sunday, wages_monday, wages_tuesday, wages_wednesday, wages_thursday, wages_friday, wages_saturday, wages_total,
        prospecting_sunday, prospecting_monday, prospecting_tuesday, prospecting_wednesday, prospecting_thursday, prospecting_friday, prospecting_saturday, prospecting_total,
        weather_sunday, weather_monday, weather_tuesday, weather_wednesday, weather_thursday, weather_friday, weather_saturday,
        jobs1, jobs2, jobs3, jobs4, jobs5, jobs6, jobs7, jobstotal,
        heardfromyn, byphone, inperson, byemail, rmfnotes, years, service_name, service_id)".

       "VALUES('$myDate','$weeknumvar','$myTime','$take1','$take2','$take3','$take4','$take5','$take6','$take7','$taketotal',
       '$hours1','$hours2','$hours3','$hours4','$hours5','$hours6','$hours7','$hourstotal',
       '$wages1','$wages2','$wages3','$wages4','$wages5','$wages6','$wages7','$wagestotal',
       '$prospecting1','$prospecting2','$prospecting3','$prospecting4','$prospecting5','$prospecting6','$prospecting7','$prospectingtotal',
       '$weather1','$weather2','$weather3','$weather4','$weather5','$weather6','$weather7',
       '$jobs1','$jobs2','$jobs3','$jobs4','$jobs5','$jobs6','$jobs7','$jobstotal',
       '$support1','$support2','$support3','$support4','$support5','$weeklyyear','$service_name1','$service_id1')";
mysql_select_db('ems_express');
$retval = mysql_query( $sql2, $conn2 ); 

// if the above is successful, display the popup modal with confirm of the invoice saved
echo "<script language='javascript'>
$(document).ready(function(){
           $('#alertsaved3').modal('show');
       });
function OKClicked(){
        window.location='view-invoices.php?id=$cust_id'
        };
</script>";
};}
?>
<!--BEGIN PAGE WRAPPER-->
        <div id="page-wrapper" style=""><!--BEGIN PAGE HEADER & BREADCRUMB-->
            <div class="page-header-breadcrumb">
                <div class="page-heading hidden-xs"><h1 class="page-title">View Customers</h1></div>
                <ol class="breadcrumb page-breadcrumb">
                    <li><i class="fa fa-home"></i>&nbsp;<a href="<? echo $siteurl ?>index2.php">Home</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
                    <li>Customers & Invoicing &nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
                    <li class="active">View Customers</li>
                </ol>
            </div>
            <!--END PAGE HEADER & BREADCRUMB-->
    <!--BEGIN CONTENT-->


    <div class="page-content">
<div class='row'>

                            <div class="portlet-body">
<div class="col-lg-12">
                        <div class="portlet">
                            <div class="portlet-header">
                                <div class="caption">Submit Weekly Analysis</div>
                                                           </div>
                            <div class="portlet-body">
                                <div id="rootwizard-tabdetail">
                                    <div class="navbar">
                                        <div class="navbar-inner">
                                            <ul>
                                                <li><a href="#tab1-rootwizard-tabdetail" data-toggle="tab"><span>1. Takings</span>

                                                    <p>Takings For Week</p></a></li>
                                                    <li><a href="#tab2-rootwizard-tabdetail" data-toggle="tab"><span>2. Hours Worked</span>

                                                    <p>The hours you worked</p></a></li>
                                                    <li><a href="#tab3-rootwizard-tabdetail" data-toggle="tab"><span>3. Wages</span>

                                                    <p>How much in wages</p></a></li>
                                                    <li><a href="#tab4-rootwizard-tabdetail" data-toggle="tab"><span>4. Prospecting</span>

                                                    <p>Hours spent prospecting</p></a></li>
                                                    <li><a href="#tab5-rootwizard-tabdetail" data-toggle="tab"><span>5. Weather</span>

                                                    <p>The Weather conditions</p></a></li>
                                                    <li><a href="#tab6-rootwizard-tabdetail" data-toggle="tab"><span>6. Jobs</span>

                                                    <p>How many jobs</p></a></li>
                                                    <li><a href="#tab7-rootwizard-tabdetail" data-toggle="tab"><span>7. Support</span>

                                                    <p>What support did you receive</p></a></li>
                                                    <li><a href="#tab8-rootwizard-tabdetail" data-toggle="tab"><span>8. Payments</span>

                                                    <p>Payments and final step</p></a></li>


                                            </ul>
                                        </div>
                                    </div>
                                    <div id="bar" class="progress progress-striped active">
                                        <div class="bar progress-bar"></div>
                                    </div>
                                    <div class="tab-content">
                                        <div id="tab1-rootwizard-tabdetail" class="tab-pane">
                                            <form role="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                                              <input type="hidden" name="service_name" id="service_name" value="<?php echo $service_name; ?>" placeholder="0.00" class="form-control"/>
                                              <input type="hidden" name="service_id" id="service_id" value="<?php echo $service_id; ?>" placeholder="0.00" class="form-control"/>
                                              <input id="week" type="hidden" value="">
                                              <div id="weekcommencing"></div>
                                                <div class="form-horizontal">
                                                <div class="form-group"><label class="col-sm-3 control-label">Sunday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take1" id="take1" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Monday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take2" id="take2" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Tuesday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take3" id="take3" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Wednesday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take4" id="take4" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Thursday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take5" id="take5" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Friday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take6" id="take6" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Saturday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="take7" id="take7" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Total Takings:</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-usd"></i><input type="text" name="taketotal" id="taketotal" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control" readonly/></div>
                                                        </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="tab2-rootwizard-tabdetail" class="tab-pane">
                                            <div class="form-horizontal">
                                                <div class="form-group"><label class="col-sm-3 control-label">Sunday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours1" id="hours1" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Monday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours2" id="hours2" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Tuesday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours3" id="hours3" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Wednesday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours4" id="hours4" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Thursday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours5" id="hours5" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Friday</label>

                                                    <div class="col-sm-9">
                                                        <div class="input-icon"><i class="fa fa-clock-o"></i><input type="text" name="hours6" id="hours6" placeholder="0.00" onKeyUp="calcfunc_1()" class="form-control"/></div>
                                                        </div>
                                                </div>
                                                <div class="form-group"><label for="inputUsername" class="col-sm-3 control-label">Saturday</label>
0
Elgoots 13 sierpień 2014, 07:09

2 odpowiedzi

Najlepsza odpowiedź

Możesz użyć isset(), aby sprawdzić, czy istnieje wejście, i użyj empty(), aby sprawdzić, aby sprawdzić, czy wejście jest puste lub nie. Na przykład:

if(isset($_POST['take5']) && !empty($_POST['take5'])) {
  $take5 = trim($_POST['take5']);
} else {
  // empty input, do something else
  // e.g. show error
}

Uwaga: Prawdopodobnie musisz uciec od wejścia, aby umieścić także do SQL

0
Raptor 13 sierpień 2014, 03:16

Użyj opcji required="required" na polach wejściowych, które należy wypełnić. Możesz także użyć @$_POST['var'], aby zignorować te wiadomości.

-1
monkeyinsight 13 sierpień 2014, 03:12