html - How can i search for a specific row in a Database using PHP? -
how can make search form in html page display result in same html page? having error when try , run code says inputpackageid not defined. how can solve this. seems variable not being recognized form. please help
here code. if dont understand question can ask me not clear.
<div class="main"> <div class="col-md-12"> <div class="row"> <div class="container"> </div> <div class="search center-block col-md-6" align="center"> <p> want track package? <br /> enter package id(pid) </p> <form method="post" action="trackshipment.php"> <div class="form-group"> <label class="sr-only" for="inputpackageid"></label> <input type="search" name="inputpackageid" class="form-control edit-form-control" id="inputpackageid" placeholder="pid"> </div> <div class="modal-footer"> <input type="submit" class="btn btn-primary" name="submit" /> </div> </form> </div> <div class="col-md-8" align="center"> <h2>well, here package!</h2> <?php include '../includes/connection.php'; //include 'phpscripts/trackshipment.php'; $packageid = $_get['inputpackageid']; $sql = "select * package p_id='$packageid'"; ?> <table class="table table-striped"> <tr> <th><span>pid</span></th> <th><span>customer id</span></th> <th>name</th> <th>description</th> <th>destination per km</th> <th>type</th> <th>price/kg</th> </tr> </th> <?php foreach ($db->query($sql) $count)?> <tr> <td> <?php echo $count['p_id']; ?> </td> <td> <?php echo $count['cus_id']; ?> </td> <td> <?php echo $count['package_name']; ?> </td> <td> <?php echo $count['package_description']; ?> </td> <td> <?php echo $count['package_type']; ?> </td> <td> <?php echo $count['destination_per_km']; ?> </td> <td> <?php echo $count['price_per_kg']; ?> </td> <?php } ?> </table> </div> </div>
it's showing it's not defined because form uses post method, , you're using array.
$packageid = $_get['inputpackageid'];
change to
$packageid = $_post['inputpackageid'];
plus, use isset()
if(isset($_post['inputpackageid'])){ $packageid = $_post['inputpackageid']; }
since you're using entired code inside same page.
or !empty()
if(!empty($_post['inputpackageid'])){ $packageid = $_post['inputpackageid']; }
if you're using same code inside same file, can use action=""
, conditional statement submit button.
if(isset($_post['submit'])){...}
seeing comment of yours, isn't case , using seperate file, can scratch that.
however, if method want use, need change method method="get"
in form. using method unsafe, consult footnotes.
footnotes:
your present code open sql injection. use mysqli
prepared statements, or pdo prepared statements, they're safer.
"how can make search form in html page display result in same html page?"
- you can either use ajax this, or use
action=""
.
Comments
Post a Comment