Hi everyone im new to php and would like to know how if it is possible to pass the data from a child window with a table containing data from the database and upon selection of which data to echo the value into the text area of the parent window using a checkbox within the child window.I would much appreciate it if anyone could provide some help on this. Below is the code. Thanks.
Child Window:
<head>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.hovertable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.hovertable th {
background-color:#c3dde0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.hovertable tr {
background-color:#d4e3e5;
}
table.hovertable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
</style>
<!-- Table goes in the document BODY -->
</head>
<body>
<form action="retrievemath.php" method="post">
<table class="hovertable">
<tr>
<th>Insert ?</th><th>Expression Name</th><th>Math Expression</th>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
</tr>
<?php
while($row = mysql_fetch_assoc($queryResource))
{
?>
<tr>
<td><input type="radio" name="insert" id="<?php echo $row['mathID']?>" value="<?php echo $row['expressionname']?>" /> </td>
<td><?php echo $row['expressionname']; ?></td>
<td><?php echo $row['mathexpression']; ?></td>
</tr>
<?php
}
?>
</table>
<div class="submit">
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" value="Insert" />
</div>
</form>
</body>
<?php
if (isset($_POST['formsubmitted'])) {
echo $_POST['insert'];
}
?>
Parent Window:
<head>
<script type="text/javascript">
<!--
function myPopup2() {
window.open( "retrievemath.php", "myWindow",
"status = 1, height = 300, width = 300, resizable = 0" )
}
//-->
</script>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10" ></textarea>
<form>
<input type="button" onClick="myPopup2()" value="POP2!">
</form>
<p onClick="myPopup2()">CLICK ME TOO!</p>
</body>
your parent window can be accessed by "window.opener" here is an example how you can send data from child to the parent window.
Related
The below is the page where the user will enter their info and submit it to the PHP program
<!DOCTYPE html>
<html>
<head>
<title>Depreciation Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">
<h1>Enter Your info</h1>
<form action="deprecalc.php" method="post">
<div id="data">
<label>Item name</label>
<input type="text" name="item_name"/>
<label>Purchase price</label>
<input type="text" name="purchase_price"/>
</br>
<label>No. of years</label>
<input type="text" name="no_of_years"/>
</br>
<label>Salvage value</label>
<input type="text" name="salvage_value"/>
</br>
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate"></br>
</div>
</form>
</div>
</body>
</html>
And this is the page the data is being submitted to. My issue is where to define the variables needed to use this formula: Depreciation = (Purchase Price – Remaining Value) / Useful Life.
<?php
$item_name = $_POST['item_name'];
$purchase_price = $_POST['purchase_price'];
$no_of_years = $_POST['no_of_years'];
$salvage_value = $_POST['salvage_value'];
$remaining_value = $purchase_price - $depreciation;
$depreciation = ($purchase_price - $remaining_value) / $no_of_years;
?>
<!DOCTYPE html>
<html>
<head>
<title>Depreciation Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">
<style>
#values {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#values td, #values th {
border: 1px solid #ddd;
padding: 8px;
}
#values tr:nth-child(even){background-color: #f2f2f2;}
#values tr:hover {background-color: #ddd;}
#values th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: navy;
color: white;
}
</style>
<body>
<h2>Item: <?php echo $item_name;?></h2></br>
<h2>Cost: <?php echo $purchase_price;?></h2></br>
<table id="values">
<tr>
<th>Year</th>
<th>Depreciation to date</th>
<th>Remaining value</th>
</tr>
<tr>
<?php
$i=1;
while ($i <= $no_of_years){
echo "<td>" . $i++ . "</td>";
}
?>
<?php
while ($remaining_value >= 0){
echo "<td>" . $depreciation . "</td>";
}
?>
<?php
while ($depreciation <= $purchase_price){
echo "<td>" . $remaining_value . "</td>";
}
?>
</tr>
</table>
</body>
</html>
</div>
</body>
</html>
I'm supposed to display it in a table format with the table heads being year, depreciation to data, and remaining value. When I run the above code, it simply outputs the year 1-5, followed by a never ending string of 0's, which I know means that it's stuck in a loop, and I've tried putting an endwhile at the end of each loop, but I then get this error:
Parse error: syntax error, unexpected token "endwhile", expecting end of file in C:\xampp\htdocs\deprecalc.php on line 68
What to add in my query to restrict users from choosing wrong dates ,
E.G. From March 7 To March 2 , the transaction within march 2-7 does not show up ,but when you change it to march 7 to april 7 it shows all transaction , is
there anything that I can add to restrict users from doing that.
Please help me.
Thank you very much.
This is my sales.php file where the user will choose what date to show.
<form action="total_sales.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Sales" name="salesbtn" ></form></center>
This is my total_sales.php file.
<head>
<script>
$(function() {
$( "#tabs" ).tabs();
$('a[rel*=facebox]').facebox();
$( ".datepicker" ).datepicker();
});
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#searchme").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#searchTbl tbody>tr").hide();
$("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#searchTbl tbody>tr").show();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
</script>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.footer1 {
position: absolute;
right: 45%;
font-family: ""Lucida Console", Monaco, monospace";
top: 0%;
width: 80%;
background-color:#F8F8FF;
color: black;
text-align: left;
}
h3{
font-size:20px;
font-family: "Arial";
}
table {
width:60%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
#media print {
#page { margin: 0; }
body { margin: 1cm; }
#printPageButton {
display: none;
}
#e{
display:none;
}
.footer {
position: fixed;
left: 0;
font-family: ""Lucida Console", Monaco, monospace";
bottom: 0;
width: 100%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
}
</style>
<div style="height:30px;"></div>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-0">
<br><img src="../upload/logo.jpg" align="center" class="footer1" style="height:50px; width:50px;"><br>
<br>
<?php
if(isset($_POST['salesbtn'])) {
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>
<center><h1> Product Sales Report </h1><h3>From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<button id="printPageButton" onClick="window.print();" class="btn btn-primary" button type="submit">Print</button>
<button id="e" class="btn btn-primary" onclick="goBack()">Back</button>
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<td width="30%"><div align="center"><strong>Purchase Date</strong></div></td>
<td width="30%"><div align="center"><strong>Customer</strong></div></td>
<td width="40%"><div align="center"><strong> Purchase Name</strong></div></td>
<td width="40%"><div align="center"><strong>Quantity</strong></div></td>
</tr>
<?php
try {
require ("conn.php");
$stmt1 = $conn->prepare("select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id'] ."' AND sales_date BETWEEN '$from' AND '$to' order by sales.sales_date desc");
$stmt1->execute();
while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
$sales_date = $row['sales_date'];
$customer_name = $row['customer_name'];
$product_name = $row['product_name'];
$sales_qty = $row['sales_qty'];
?>
<tr align="center">
<td><?php echo $sales_date; ?></td>
<td><?php echo $customer_name; ?></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $sales_qty; ?></td>
</tr>
</center>
<?php
}
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
?>
<tr>
</tr>
</table> </br> </br>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>
So, I tried this and it worked:
the scripts HAVE TO BE in that order (if not it will break)
There is some problem with your pattern, but with Datepicker, you don't need it anyway
After the FROM Date selection I would set the minDate of the TO Date to +1d
Code Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<title>Document</title>
</head>
<body>
<form action="total_sales.php" method="post">
From:
<input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required > To:
<input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required >
<input type="submit" value="Show Sales" name="salesbtn">
</form>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
<script>
$(function () {
$(".datepicker").datepicker({
dateFormat: "yy-mm-dd",
minDate: "-1d",
maxDate: "+1w"
});
});
</script>
</body>
</html>
I'm not very good at website developing but as this is my graded unit and im trying to make it nice.
Im running into an issue with HTML and CSS (possibly PHP as well?) where it is not being applied when im using classes.
Things ive tried so far:
Put the CSS through w3schools error checks - Clean
Directly linking the CSS in the admin.php instead of through the seperate header - No effect
Directly applying the css is style tags (Tried inputting 'style"color:white;"' into both the thead and table tags) - No effect
I am using bottstrap for easier styling so maybe this is overpowering the CSS? My stylesheet is being called after though so this "shouldn't" be the case.
admin.php (the file i want the css to be applied to):
<?php
require 'header.php';
?>
<br><br><br>
<table class="aT">
<thead class="aTH">
<td>Member Number</td>
<td>Username</td>
<td>Forename(s)</td>
<td>Surname</td>
<td>Email</td>
<td>Date Of Birth</td>
<td>Age</td>
<td>User Type (1 = admin, 2 = Verified Seller, 3 = Unverified Seller)</td>
<td>Phone number</td>
</thead>
<?php
$result = mysqli_query($link, "SELECT userid, username, forenames, surname, email, dob, age, usergroup, phonenumber FROM members");
while($row = mysqli_fetch_array($result)) {
?>
<tbody>
<tr>
<td id="memberno" contenteditable="true"><?php echo $row['userid']?></td>
<td id="username" contenteditable="true"><?php echo $row['username']?></td>
<td id="dob" contenteditable="true"><?php echo $row['forenames']?></td>
<td id="salutation" contenteditable="true"><?php echo $row['surname']?></td>
<td id="forenames" contenteditable="true"><?php echo $row['email']?></td>
<td id="surname" contenteditable="false"><?php echo $row['dob']?></td>
<td id="email" contenteditable="false"><?php echo $row['age']?></td>
<td id="user_type" contenteditable="true"><?php echo $row['usergroup']?></td>
<td id="user_type" contenteditable="false"><?php echo $row['phonenumber']?></td>
</tr>
<?php
}
?>
</tbody>
<?php
include 'footer.php';
?>
header.php:
<!doctype html>
<html>
<?php
require 'mysqli.php';
?>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.php">Ross's Rides</a>
</div>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Buy/Sell</li>
</ul>
<?php
if(!isset($_SESSION))
{
session_start();
}
if (!isset($_SESSION["admin"]) && !isset($_SESSION["user"]) && !isset($_SESSION["useru"])) {
?>
<form method="get" action="login.php" class="btn_1">
<a class="btn btn_2 navbar-btn" href="login.php">Login/Register</a>
</form>
<?php
}
else {
?>
<form method="get" action="logout.php" class="btn_1">
<a class="btn btn_2 navbar-btn" href="logout.php">Logout</a>
</form>
<?php
}
if (isset($_SESSION["admin"])) {
?>
<form method="get" action="admin.php" class="btn_1">
<a class="btn btn_2 navbar-btn" href="admin.php">Admin Panel</a>
</form>
<?php
}
?>
</div>
</nav>
</head>
stylesheet.css:
.btn_1 {
display:inline;
float: right;
}
.btn_2 {
background-color: black;
border-radius: 25px;
padding: 10px 10px;
color: white;
}
.loginBox {
padding-top: 100px;
}
.submitBtn {
background-color: black;
border-radius: 25px;
padding: 10px 25px;
color: white;
}
.cancelBtn {
background-color: black;
border-radius: 25px;
padding: 10px 25px;
color: white;
}
.registerForm {
padding-top: 40px;
}
.redText {
color: red;
}
.aT {
width: 100%;
border: 1px;
border: thick;
border-color: limegreen;
padding: 10px;
text-align: left;
background-color: black;
color: white;
}
.aTH {
height: 50px;
}
Now I am almost certain a lot of my code is not "perfect" or following "proper procedures" and if you see any of this feel free to point it out and correct me as ive said im not that good at websites and could definetly learn a thing or two. I will be removing the tags later when i can get the CSS to properly apply, until then they will stay as my sketchy fix for now.
Cheers for all the help, here is an image to show the effect of my attempts.
if you need any more info/pics/other stuff feel free to ask and ill try to get as much as possible up. the footer.php does contain an if thats any consolation so the document does have an end!
On my code view the styles are not applying
Have you verified that all cache's have been cleared? I had this issue and I was struggling for quite awhile before I realized that my host cached the files automatically, as well as cloudflare cached it, AND Chrome cached it.
here is sample image
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 1px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<div class="header">
<h2><?php echo get_option('company_name'); ?> Catalog</h2>
</div>
<br /><br />
<div class="footer">Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?></div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: 10px; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 80px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:80px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
when i try to generate pdf it's always coming like this. i added my generate pdf code above .
2 nd page is not coming like 1st page.. i searched and found other dompdf solution for other peoples problem. but my problem is on 2nd page it's not coming as 1stpage.
There's some buggy behavior here on the part of dompdf. For some reason styling the DIV containing your product info with width: 100% is breaking the layout when the table row is paged. If you remove that styling from the DIV then the document should render as expected. The default DIV layout is full-width so you can leave the width styling on the DIV out
I'm trying to set up a CSS page so the my PHP site has background and basics. However, the CSS doesn't show up, although direct style modifications to the HTML code work fine.
Here's the CSS:
body {
background-color: #FF9900;
}
h1 {
color: #6600FF;
font-family: "Arial Black", Gadget, sans-serif;
}
#passwd_result{
background:#FF9900;
color:#FFFFFF;
font-weight:bold;
margin-right:60%;
}
#upload_result{
background:#CC3300;
color:#FFFFFF;
font-weight:bold;
margin-right:60%;
}
And this is the index page with the CSS reference:
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body>
<?php
echo "<h1 align='center'> Welcome to Metube! </h1>";
?>
<form action="login.php" method="post" align="center">
<input type="submit" class="button" VALUE = "Log in" >
</form>
<form action="register.php" method="post" align="center">
<input type="submit" class="button" VALUE = "Register" >
</form>
</body>
</html>