How to call PHP function from other page? -
i working in our project uses php.
i have button
<form method="post" action=""> <div class="profile" id="u118" style="left: 46px; top: 281px; width: 342px; height: 34px;"> <input name="neworder" type="submit" value="view full company details" class="profile" id="profbutton" style="width: 342px; height: 34px;"> </div> </form> and want call php code other file testdisplaycompanydetails.php
<?php if(isset($_get[$_session['id']])) { $id = $_session['id']; $sql="select * company companyid = :id"; $res=$db->prepare($sql); $res->execute(array('id'=> $id)); while($row = $res->fetch(pdo::fetch_assoc)){ echo $row['name']; echo "</br>"; echo $row['address']; echo "</br>"; echo $row['telephone1']; echo "</br>"; echo $row['telephone2']; echo "</br>"; echo $row['businesswebsite']; echo "</br>"; echo $row['businessemail']; echo "</br>"; echo $row['businesspermit']; echo "</br>"; echo $row['businesspermitvalidtill']; echo "</br>"; echo $row['dtipermit']; echo "</br>"; echo $row['dtipermitvalidtill']; echo "</br>"; echo $row['bankname']; echo "</br>"; echo $row['bankaccountnumber']; echo "</br>"; } } ?>
how can this? copied wrong code. sorry
in form, action needs point file.
<form action="/path/to/your/script.php" method="post">
also, method="post" means need use $_post instead of $_get - amd name of input have same key in $_post:
<?php include 'dbconnection.php'; if(isset($_post['neworder'])) { $id = $_post['neworder']; $sqlloader="select name validpersonnel personnelid = :id"; $resloader=$db->prepare($sqlloader); $resloader->execute(array('id' => $id)); $row = $resloader->fetch(); echo $row['name']; } it white screen value of $row unless tell php file output more stuff.
furthermore, you'll need <input type="submit"/> in order tell browser send data in input form --- or otherwise, you'll need javascript handler.
if output shouldn't intensive, you'll want ajax - allow data sent -- , allow process response without redirecting or reloading page.
also, smart understand how prevent against injection validating $_post inputs on server-side.
look filter_var start -
for numbers: filter_var($_post['neworder'], filter_validate_int); should suffice - else, gets bit tricky - typically use: filter_var($_post['neworder'], filter_sanitize_string); - cover basic needs.
Comments
Post a Comment