PROBLEMS Making a Search Page PHP and MYSQL -
i'm facing issue due lack of experience.
i'm getting data mysql database , populating second dropdown menu.
the problem is... when click in "validate" submit , record data in variable cleans previous option selected. i'm being unable record selected options in variables.
<?php $location = ""; $locationf = ""; $system = ""; $systemf = ""; $conn = mysqli_connect('localhost', 'root', 'test', 'srsbase') or die('cannot connect db'); $result = $conn->query("select distinct sub_account srsload"); if (isset($_post["selec"]["account"])) { $location = $_post["selec"]["account"]; $locationf = $location; $locationf = sprintf('%s', $locationf); } echo "location: $locationf"; $conn2 = mysqli_connect('localhost', 'root', 'test', 'srsbase') or die('cannot connect db'); $result2 = $conn2->query("select distinct systemname srsload sub_account='$locationf'"); if (isset($_post["selec"]["system"])) { $system = $_post["selec"]["system"]; $systemf = $system; } echo "system: $systemf"; $post_at = ""; $post_at_to_date = ""; $post_at_todate = ""; $querycondition = ""; if (!empty($_post["search"]["post_at"])) { $post_at = $_post["search"]["post_at"]; list($fiy, $fim, $fid) = explode("-", $post_at); $post_at_todate = date('yy-mm-dd'); if (!empty($_post["search"]["post_at_to_date"])) { $post_at_to_date = $_post["search"]["post_at_to_date"]; list($tiy, $tim, $tid) = explode("-", $_post["search"]["post_at_to_date"]); $post_at_todate = "$tiy-$tim-$tid"; //testing selected targets //echo $post_at; //echo "/"; //echo $post_at_todate; } //$querycondition .= "where rdate between '$fiy-$fim-$fid' , '" . $post_at_todate . "'"; $querycondition .= "where rdate between '$post_at' , '" . $post_at_todate . "'"; } //$sql = "select * srsload " . $querycondition . " order post_at desc"; //$sql = "select * srsload rdate between '$post_at' , $post_at_todate;" $sql = sprintf("select * srsload rdate between '%s' , '%s' , systemname='%s' , sub_account='%s'", $post_at, $post_at_todate, $systemf, $locationf); $result3 = mysqli_query($conn, $sql); ?> <!doctype html> <html> <head> <title>storage report system - search</title> <script src="jquery-1.9.1.js"></script> <link rel="stylesheet" href="jquery-ui-1.11.4.css"> <style> .table-content{border-top:#cccccc 4px solid; width:50%;} .table-content th {padding:5px 20px; background: #f0f0f0;vertical-align:top;} .table-content td {padding:5px 20px; border-bottom: #f0f0f0 1px solid;vertical-align:top;} </style> </head> <body> <h2 style='font-family:arial'>storage report system - search</h2> <form name='sname' id='sname' action='' method='post'> <select id='select' name="selec[account]" value="<?php echo $location; ?>" > <option value='-1'>--select location--</option> <?php while ($row = $result->fetch_assoc()) { unset($sub_acc); $sub_acc = $row['sub_account']; echo '<option value="' . $sub_acc . '">' . $sub_acc . '</option>'; } ?> </select> <input type='submit' value='validate' /> </form> <form name='sname' id='sname' action='' method='post' > <select id='system' name="selec[system]" value="<?php echo $system; ?>" > <option value='-1'>--select system--</option> <?php while ($row2 = $result2->fetch_assoc()) { unset($syst); $syst = $row2['systemname']; echo '<option value="' . $syst . '">' . $syst . '</option>'; } ?> </select> <input type='submit' value='validate' /> </form> <div class="demo-content"> <form name="frmsearch" method="post" action=""> <p class="search_input"> <input type="text" placeholder="from date" id="post_at" name="search[post_at]" value="<?php echo $post_at; ?>" class="input-control" /> <input type="text" placeholder="to date" id="post_at_to_date" name="search[post_at_to_date]" style="margin-left:10px" value="<?php echo $post_at_to_date; ?>" class="input-control" /> <input type="submit" name="go" value="search" > </p> <?php if (!empty($result3)) { ?> <table class="table-content"> <thead> <tr> <th width="30%"><span>system name</span></th> <th width="50%"><span>date</span></th> <th width="20%"><span>hsm</span></th> </tr> </thead> <tbody> <?php while ($row3 = mysqli_fetch_array($result3)) { ?> <tr> <td><?php echo $row["systemname"]; ?></td> <td><?php echo $row["rdate"]; ?></td> <td><?php echo $row["hsm_mcds"]; ?></td> </tr> <?php } ?> <tbody> </table> <?php } ?> </form> </div> <script src="jquery-ui-1.10.3.js"></script> <script> $.datepicker.setdefaults({ showon: "button", buttonimage: "datepicker.png", buttontext: "date picker", buttonimageonly: true, dateformat: 'yy-mm-dd' }); $(function () { $("#post_at").datepicker(); $("#post_at_to_date").datepicker(); }); </script> </body> </html>
it because have 2 forms there. every form has own select , submit. when click submit, appropriate form select sent. when want have data both selects, have have both selects in 1 form 1 submit. code:
<form name='sname' id='sname' action='' method='post'> <select id='select' name="selec[account]" value="<?php echo $location; ?>" > <option value='-1'>--select location--</option> <?php while ($row = $result->fetch_assoc()) { unset($sub_acc); $sub_acc = $row['sub_account']; echo '<option value="' . $sub_acc . '">' . $sub_acc . '</option>'; } ?> </select> <select id='system' name="selec[system]" value="<?php echo $system; ?>" > <option value='-1'>--select system--</option> <?php while ($row2 = $result2->fetch_assoc()) { unset($syst); $syst = $row2['systemname']; echo '<option value="' . $syst . '">' . $syst . '</option>'; } ?> </select> <input type='submit' value='validate' /> </form>
Comments
Post a Comment