hello i have built a multi search form using php, basically this search form queries from a particular date to another, which i have gotten to work perfectly,
using this codes
search.html
<form class="form-horizontal" action="report_advanced.php" method="post" name="form1" id="form1">
<div class="control-group">
<label class="control-label" for="inputagent name"><span class="asasa">*</span> Advanced Search:</label>
<div class="controls">
<input type="text" name="from" value="" size="32" id="inputDate" placeholder="From" /><br /><br />
<input type="text" name="to" value="" size="32" id="inputDatess" placeholder="To" />
</div>
</div>
<p align="center">
<input type="submit" class="btn btn-mini btn-primary" value="Search" /></p>
</form>
and
report_advanced.php
mysql_select_db($database_kbl, $kbl);
$query_cert = sprintf("SELECT * FROM `transactions` WHERE `Start_Date` BETWEEN %s AND %s ",
GetSQLValueString($colname_cert, "text"),GetSQLValueString($colname2_cert, "text"));
$query_limit_cert = sprintf("%s LIMIT %d, %d", $query_cert, $startRow_cert, $maxRows_cert);
$cert = mysql_query($query_limit_cert, $kbl) or die(mysql_error());
$row_cert = mysql_fetch_assoc($cert);
<table width="60%" class="table table-bordered" id="table"></span>
<tr class="success">
<td style="color:#FFF" width="10%">Insured Name</td>
<td style="color:#FFF" width="10%">Telephone No</td>
<td style="color:#FFF" width="10%">Policy Number</td>
<td style="color:#FFF" width="10%">Car Make</td>
<td style="color:#FFF" width="10%">Model</td>
<td style="color:#FFF" width="10%">Registeration Number</td>
<td style="color:#FFF" width="10%">Amount</td>
<td style="color:#FFF" width="10%">Start Date</td>
<td style="color:#FFF" width="10%">Expiry Date</td>
</tr>
<?php do { ?>
<tr class="success" style="text-transform:capitalize;font-size:16px">
<td style="color:#FFF" width="10%"><?php echo $row_cert['Insured_Name']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Telephone']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Policy_Number']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Make_Of_Car']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Model']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Registeration_Number']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Premium']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Start_Date']; ?> </td>
<td style="color:#FFF; font-size:14px" width="10%"><?php echo $row_cert['Expiry_Date']; ?></td>
<?php } while ($row_cert = mysql_fetch_assoc($cert)); ?> </table>
<?php } // Show if recordset not empty ?>
but now i want to implement this same type of functionality in a mobile app, using phonegap, and i intend to make ajax requests using the snippets i have posted and display in a div, since php cannot be run in phonegap,
but i dont know how o go about this, i have done some searchin online but havent seen what i am lookin 4.
most especially because i want to use the same code i have used in my web project for this app by makin an ajax request
Simply, what you do is just make another http ajax request from phonegap to the same endpoint to your server, get the response and reload it in the div.
i.e
$.get(url_to_endpoint, function(data){
// do reloading of your div
});
this is can be done using jquerymobile library easily or depends how you do http requests from your phonegap.
Related
currently im doing my final year project which is advising system for student. My problem is that admin cannot update a certain data of student. At my first try, it says that, admin done update student profile but when i check at the database it does not update at all. After that i change my code, it turns that the data is undefined variable and mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given.
(AdminUpdateStd.php)
<?php
include("db.php");
$StdId = $_GET['id'];
$sql="SELECT * from member where id='$StdId'";
$result=mysqli_query($db,$sql);
while($rows=mysqli_fetch_array($result)){
$student_id=$rows[0];
$student_name=$rows[3];
$student_email=$rows[5];
$student_address=$rows[4];
$student_tel=$rows[6];
$intake=$rows[7];
$total_cred=$rows[8];
$advisor=$rows[9];
}
?>
<form action ="AdminUpdateProcess.php" method="POST">
<div id="reg-head" class="headrg" align="center"><strong>Profile Student <?php echo "$StdId"; ?></strong></div>
<table width="350" height="200" border="1" align="center" cellpadding="2" cellspacing="0" bgcolor="#FFF">
<input type="hidden" name="student_id" value=" <?php echo "$student_id"; ?>">
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Full Name:</div></td>
<td class="tl-4"><?php echo "$student_name"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Email:</div></td>
<td class="tl-4"><?php echo "$student_email"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Adress:</div></td>
<td class="tl-4"><?php echo "$student_address"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Tel Number:</div></td>
<td class="tl-4"><?php echo "$student_tel"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Intake:</div></td>
<td class="tl-4"><input type="text" name="intake" <?php echo "$intake"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Total Credit Hour:</div></td>
<td class="tl-4"><input type="text" name="total_credit" <?php echo "$total_cred"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Advisor:</div></td>
<td class="tl-4"><input type="text" name="advisor_name" <?php echo "$advisor"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name"> </div></td>
<td class="tl-4"><input type="submit" name="Update" <?php echo "value='UPDATE'"; ?>></a>
<button type="button">View Profile</button></td>
</tr>
</table>
</form>
(AdminUpdateProcess.php)
<?php
include("db.php");
$intake=$_POST['intake'];
$total_cred=$_POST['total_credit'];
$advisor=$_POST['advisor_name'];
$StdId = $_POST['student_id'];
if (isset ($_POST['Update'])) {
$UpdateQuery ="UPDATE member SET intake = '$intake', total_credit = '$total_cred', advisor_name = '$advisor' WHERE student_id ='$StdId'";
$res = mysqli_query ($UpdateQuery) or die ("Could not update".mysqli_error());
}
?>
On my website enter link description here I'm using checkbox buttons for updating data in a MySql table (pages are with login) and use this code in PHP that's working fine:
<?php
$sql="SELECT *,cast(DATE_FORMAT(datum,'%d-%m-%Y ') AS CHAR(32)) as datum FROM wedstrijden";
$result=mysqli_query($db,$sql);
$count=mysqli_num_rows($result);
?>
<table style="width: 100%;">
<tr>
<td><form name="frmactive" action="1fanionchange.php" method="post">
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
<tr>
<td> </td>
</tr><tr>
<td align="center"><!--<input type="checkbox" name="allbox" title="Select or Deselct ALL" style="background-color:#ccc;"/> --></td>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Datum</strong></td>
<td align="center"><strong>Uur</strong></td>
<td align="center"><strong>Thuis</strong></td>
<td align="center"><strong>Uit</strong></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td align="center"><? echo $rows['id']; ?></td>
<td align="center"><? echo $rows['datum']; ?></td>
<td align="center"><? echo $rows['uur']; ?></td>
<td align="center"><? echo zoeknaam($rows['thuisploeg']); ?></td>
<td align="center"><? echo zoeknaam($rows['uitploeg']); ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
</form>
</td>
</tr>
</table>
But when I use the same code in WordPress (I'm trying to make the website in WordPress), it is not working and no records are displayed. When I try to find the number of rows using:
echo $count. "<br />";
I get the correct number of records in that table. But the records are not showed?
Any idea how to handle the problem? Thanks.
PS. I use the plugin phpexec in WordPress!
In WordPress it is suggested to use the WordPress builtin Queries. So that it can have maximum compatibility with the server too it is hosted.
Reference: https://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
And all the following functions will attach the database that is defined as global..
$wpdb->insert('wp_submitted_form', array(
'name' => 'Kumkum',
'email' => 'kumkum#gmail.com',
'phone' => '3456734567', // ... and so on
));
Like wise you can use it for Update / Select as per your wish and it is considered as the best one according to WordPress..
I've stucked a bit when it comes to a small piece of my PHP code. The role of this script is to display whole table from mysql plus adding to each row a hyperlink to delete such row.
<?php
$connection=mysql_connect('localhost','root','') or die(mysql_error());
error
mysql_select_db('localhost_db',$connection) or die(mysql_error());
$query=mysql_query("SELECT * FROM cms_contest") or die(mysql_error());
if(mysql_num_rows($query)>0):
?>
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php
while($row=mysql_fetch_object($query)):?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">REMOVE</td>
</tr>
<?php endwhile;?>
</table>
<?php
else: ?>
<h3>No Results found.</h3>
<?php endif; ?>
It would be perfect if there appear a short javascript popup with question like: are you sure you want to remove this entry? OK / Cancel.
I have no clue how to do it.. thanks for any tips!
Simple/stupid method:
<td>nuke me</td>
But if a web spider or a browser link pre-fetch tool gets loose on this page, you'll be nuking ALL of your records.
Somewhat better:
<td>
<form method="post" action="deleteme.php">
<input type="hidden" name="id" value="<?php echo $row->ID ?>" />
<input type="submit" value="Nuke me" />
</form></td>
And then there's various options involving radio buttons/checkboxes, or JS to trap the click-on-the-link etc...
But, in the end, they ALL boil down to "you have to sent the ID of the row back to the server". How you go about that is up to you... just don't use the plain "click here" version.
Indeed there are several different ways to do this. One way I like is to wrap the entire table in a form that submits to the delete script, and use a button for each row with the row ID as its value.
<form method="post" action="delete.php">
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php while($row=mysql_fetch_object($query)): ?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">
<button name="delete-id" type="submit" value="<?php echo $row->ID; ?>">
REMOVE
</button>
</td>
</tr>
<?php endwhile;?>
</table>
</form>
There are also many different ways to confirm the deletion. The simplest I know of on the client side is to add onclick="return confirm('Are you sure?');" to the delete button.
click event:
DELETE
<script type="text(javascript">
function confirmDelete(id){
if(confirm('sure u want to delete entry with id: ' + id + '?')){
window.location.href = "ursite.php?id="+id+"&delete=true";
}
}
</script>
PHP
if(isset($_GET['delete'])){
$stmt = "DELETE FROM cms_contest WHERE ID = ".$_GET['id'];
mysql_query($stmt);
}
it's the worst way to do it.
I recommend you to look at:
jQuery $.post()jQuery $.ajax()
I hope it will help you.
i am working on a project which is airways ticketing.
i am able to display the final ticket to the user but how can i give user the ability to print it when he/she clicks on print button.
please help..
<title>Untitled Document</title>
<style type="text/css">
#main {
position:absolute;
top:100px;
width:100%;
height:250px;
z-index:1;
}
#submit {
position:absolute;
top:300px;
width:100%;
height:42px;
z-index:2;
}
</style>
</head>
<body>
<div id="main" align="center">
<?PHP
mysql_connect("127.0.0.1","root","");
mysql_select_db("cmc");
$id=$_REQUEST['id'];
$r=mysql_query("select * from manifest where transid=".$id);
$d=mysql_fetch_assoc($r);
?>
<table width="800" border="1">
<tr>
<td colspan="6" align="center">HORIZON AIRWAYS PASSENGER TICKET</td>
</tr>
<tr >
<td colspan="3" align="center">PNR NUMBER: </td>
<td colspan="3" align="center"><?php echo $d["pnrno."]; ?></td>
</tr>
<tr >
<td colspan="3" align="center"> PASSENGER'S NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
ini_set('date.timezone','asia/calcutta');
echo date("d/m/y"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">TIME OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
echo date("h/i/s"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF JOURNEY:</td>
<td colspan="3" align="center"><?php echo $d["day"]."-".$d["month"]."-".$d["year"]; ?> </td>
</tr>
<tr>
<td colspan="6" align="center">NOT TRANSFERRABLE</td>
</tr>
<tr>
<td colspan="3" align="center">PASSENGER NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr>
<td colspan="3" align="center">SECTOR:</td>
<td colspan="3" align="center"><?php echo $d["sector"]; ?></td>
</tr>
<tr>
<td width="134" align="center">FLIGHT #</td>
<td width="132" align="center">CLASS</td>
<td width="112" align="center">DATE</td>
<td width="130" align="center">DEP. TIME</td>
<td width="132" align="center">ARR. TIME</td>
<td width="120" align="center">STATUS</td>
</tr>
<tr>
<td><?php echo $d["flight_no."]; ?></td>
<td><?php echo $d["class"]; ?></td>
<td><?php echo $d["name"]; ?></td>
<td><?php echo $d["departure"]; ?></td>
<td><?php echo $d["arrival"]; ?></td>
<td><?php echo "confirm"; ?></td>
</tr>
</table>
<div id="submit" align="center">
<form name="form1" method="POST">
<input type="submit" value="Print" name="submit"/>
</form>
</div>
</div>
</body>
</html>
Printing has to be done on the client side, not the server side. This shouldn't be a form (I would actually make it a link). The simplest method:
<input type="submit" value="Print" onclick="print(); return false;"/>
You can trigger the print event bij using the javascript function: window.print().
Example:
print page
TIP!
Use a print CSS to tell the browser what to print! That way the user doesn't waste paper ;)
Example including a print CSS stylesheet: <style type="text/css" media="print" href="print.css" />
More info about CSS print stylesheets: http://www.alistapart.com/articles/goingtoprint/
You can invoke printing via javascript using print method
Click to Print This Page
You might want to hide certain elements in page when printing it. For that you can use css like so:
#media print {
.non-printable { display: none; }
}
And then give non-printable class to those elements that you don't want printed.
The others are correct that this would be done with
print ticket
You will also probably want to create a separate CSS style for the print version that strips out unnecessary graphics. You can also add manual page breaks in case there are individual boarding passes or something.
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />
i have a table has php variables fetched from mysql , the table is inside a Form , what i am trying to do is to display page to be printed for the user with a an invoice style layout, i tried to make a behavior that when the FORM Is submitted , a pop up page will come display the php variables data , which is doesn't work at all , i tried to display the content of popup page inside a regluar page , it worked ! , which means there is no problem with my php code .
here is the form page code :
<form action="../../printInvoice.php" method="post" onsubmit="MM_openBrWindow('../../printInvoice.php','Invoice','status=yes,scrollbars=yes')">
<table width="100%" border="0">
<tr>
<td align="left">Invoice:</td>
</tr>
<tr>
<td width="12%" height="39" bgcolor="#9DE3FB" align="center">Invoice Number</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Event Name</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Reservation Date</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Quantity</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Price Per Ticket</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Total Price</td>
</tr>
<tr>
<td width="12%" height="39" align="center"><input type="text" name="invoiceId" readonly="readonly" value="<? echo $row['invoiceId']; ?>" class ="field-style"/></td>
<td width="12%" height="39" align="center"><input type="text" name="eventTitle" readonly="readonly" value="<? echo $row['name']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceDate" readonly="readonly" value="<? echo $row['invoiceDate']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceqty" readonly="readonly" value="<? echo $row['quantity'] ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoicePPU" readonly="readonly" value="<? echo $row['price']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceTotal" readonly="readonly" value="<? echo $row['totalPrice']; ?>" class="field-style" /></td>
</tr>
</table>
<br />
<input type="submit" value="Print Invoice" />
</form>
here is the popup window code (invoice layout to print ):
<table width="65%" border="1" cellspacing="5" cellpadding="5">
<tr>
<td colspan="5"><table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="60%"><img src="images/Logo.png" /></td>
<td width="40%"><p>Invoice No:# <? echo $invoiceId; ?></p>
<p>Invoice Date: <? echo $invoiceDate ;?> </p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="125" colspan="5" valign="top"><p>Bill To:</p>
<p>Name:</p>
<p>Address:</p></td>
</tr>
<tr>
<td width="12%" align="center" height="40">Item Id</td>
<td width="28%" align="center">Item Disc</td>
<td width="9%" align="center">QTY</td>
<td width="40%" align="center">Price Per Unit</td>
<td width="11%" align="center">Total</td>
</tr>
<tr>
<td align="center" valign="middle">1</td>
<td align="center" valign="middle"><? echo $eventTitle . " ticket(s)"; ?></td>
<td align="center" valign="middle"><? echo $invoiceqty ; ?></td>
<td align="center" valign="middle"><? echo $invoicePPU ; ?></td>
<td align="center" valign="middle"><? echo $invoiceqty * $invoicePPU ; ?></td>
</tr>
</table>
for submitting behavior, i used Dreamweaver behavior panel. what's wrong here ?
I'm not sure about dreamweaver behaviour but as far as I can tell this will never work.
You are posting the data to a the "../../printInvoice.php" but when you request the popup page you are opening a new instance that hasn't received the post data.
You need to alter your javascript that pops the page up so that it posts the forms data when it performs the popup request.
I don't know which library you are using to create your popup but fancybox (Jquery plugin: http://fancybox.net) allows you to post data to the popup it creates.
If you could tell me what popup library you are using I might be able to help further.
you cant use php to show a popup you must use ajax, and javascript :
http://jquery.malsup.com/form/
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
//show your Popup
});
});
Have you tried to use $row['invoiceId']; instaed of $invoiceId in the popupwindow?
It seems to be the same file and therfore the $row[] data should be accessable!
If this doesn't works we propably need more code, especially of the php side.
^^ Overlooked something, we definitely need more code!
thanks, instead of all of this , i posted all the variables as url parameters such as :
<onsubmit="MM_openBrWindow('../../printInvoice.php?invoiceId=<? echo $row['invoiceId']; ?>&eventTitle=<? echo $row['name']; ?>','Invoice'
thanks for trying & your time everyone :)