Firstly, hi all, and i apologise i am very new to this!
I have a fully functional SQL read php page with a few functions.
My issue is i need pass javascript functions adultticketqty, concessionticketqty, studentticketqty, childticketqty, programticketqty and total sell through to PHP in order to write to SQL table.
My insert.php code will write static values, but i can’t get the javascript values to pass through.
Ive spent a number of hours without success trying to get it working, so any assistance would be greatly appreciated.
Cheers
i have the following html code
<!doctype html>
<html>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<head>
<meta charset="utf-8">
<title>Hobart & Latrobe Raceway POS Terminal</title>
<style type="text/css">
body {
background-color: #000000;
text-align: center;
font-size: 24px;
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
font-style: normal;
font-weight: 400;
color: #272727
}
.quantity {
background-color: #000000;
text-align: center;
font-size: 60px;
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
font-style: normal;
font-weight: 500;
color: white
}
.totalquantities {
background-color: #FF0000;
text-align: center;
font-size: 20px;
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
font-style: normal;
font-weight: 200;
color: white
}
.lineprice {
background-color: #000000;
text-align: center;
font-size: 40px;
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
font-style: normal;
font-weight: 400;
color: white
}
.totalsell {
background-color: #FF0000;
text-align: center;
font-size: 50px;
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
font-style: normal;
font-weight: 600;
color: white
}
.display {
font-family: amaranth;
font-style: normal;
font-weight: 400;
font-size: 60px;
color: #FFFFFF;
text-align: center;
}
</style>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/amaranth:n4:default;acme:n4:default;hammersmith-one:n4:default.js" type="text/javascript"></script>
</head>
<?php
include('phpsqlget.php');
?>
<body>
<span style="font-family: Impact, Haettenschweiler, 'Franklin Gothic Bold', 'Arial Black', sans-serif"></span>
<script type="text/javascript">
//Set the ticket/program quantities to a default of 0
var adultticketqty = 0;
var concessionticketqty = 0;
var studentticketqty = 0;
var childticketqty = 0;
var programqty = 0;
var adultlineprice = 0;
var concessionlineprice = 0;
var studentlineprice = 0;
var childlineprice = 0;
var programlineprice = 0;
var totalsaleprice = 0;
var totaltickets = 0;
//Adult Ticket Calculations
function adultticketadd(){
adultticketqty++;
document.getElementById('displayadultqty').innerHTML = adultticketqty;
}
function adultticketsubtract(){
adultticketqty--;
document.getElementById('displayadultqty').innerHTML = adultticketqty;
}
function calculateadultTotal()
{
//display the result
adultlineprice = <?php echo($AdultPrice); ?> * adultticketqty
var divobj = document.getElementById('adultlinesell');
divobj.style.display='block';
divobj.innerHTML = "$"+adultlineprice;
}
//Concession Ticket Calculations
function concessionticketadd(){
concessionticketqty++;
document.getElementById('displayconcessionqty').innerHTML = concessionticketqty;
}
function concessionticketsubtract(){
concessionticketqty--;
document.getElementById('displayconcessionqty').innerHTML = concessionticketqty;
}
function calculateconcessionTotal()
{
//display the result
concessionlineprice = <?php echo($ConcessionPrice); ?> * concessionticketqty
var divobj = document.getElementById('concessionlinesell');
divobj.style.display='block';
divobj.innerHTML = "$"+concessionlineprice;
}
// Student Ticket Calculations
function studentticketadd(){
studentticketqty++;
document.getElementById('displaystudentqty').innerHTML = studentticketqty;
}
function studentticketsubtract(){
studentticketqty--;
document.getElementById('displaystudentqty').innerHTML = studentticketqty;
}
function calculatestudentTotal()
{
//display the result
studentlineprice = <?php echo($StudentPrice); ?> * studentticketqty
var divobj = document.getElementById('studentlinesell');
divobj.style.display='block';
divobj.innerHTML = "$"+studentlineprice;
}
// Child Ticket Calculations
function childticketadd(){
childticketqty++;
document.getElementById('displaychildqty').innerHTML = childticketqty;
}
function childticketsubtract(){
childticketqty--;
document.getElementById('displaychildqty').innerHTML = childticketqty;
}
function calculatechildTotal()
{
//display the result
childlineprice = <?php echo($ChildPrice); ?> * childticketqty
var divobj = document.getElementById('childlinesell');
divobj.style.display='block';
divobj.innerHTML = "$"+childlineprice;
}
//Program Calculations
function programadd(){
programqty++;
document.getElementById('displayprogramqty').innerHTML = programqty;
}
function programsubtract(){
programqty--;
document.getElementById('displayprogramqty').innerHTML = programqty;
}
function calculateprogramTotal()
{
//display the result
programlineprice = <?php echo($ProgramPrice); ?> * programqty
var divobj = document.getElementById('programlinesell');
divobj.style.display='block';
divobj.innerHTML = "$"+programlineprice;
}
//calculate total sale price
function calcsellprice()
{
//display the result
totalsaleprice = adultlineprice + concessionlineprice + studentlineprice + childlineprice + programlineprice
var divobj = document.getElementById('totalsalesell');
divobj.style.display='block';
divobj.innerHTML = "$"+totalsaleprice;+":00"
}
//calculate total number of tickets
function calctotaltickets()
{
//display the result
totaltickets = adultticketqty + concessionticketqty + studentticketqty + childticketqty
var divobj = document.getElementById('totalticketitemqty');
divobj.style.display='block';
divobj.innerHTML = totaltickets;
}
//calculate total number programs
function calctotalprograms()
{
var divobj = document.getElementById('totalprogramitemqty');
divobj.style.display='block';
divobj.innerHTML = programqty;
}
function passVal(){
var data = {
fn: "filename",
str: "this_is_a_dummy_test_string"
};
$.post("test.php", data);
}
passVal();
</script></script>
<table width="1016" height="524" border="0" cellpadding="0" cellspacing="0">
<tbody>
</tbody>
<tbody>
<tr>
<td width="177" height="50" rowspan="2" style="text-align: center"><img src="assets/Hobart Raceway - Logo_Transparent" width="141" height="136" alt=""/></td>
<td width="260" height="50" colspan="4" style="font-size: 60px"><img src="assets/AdultwithoutSign" width="228" height="70" alt="" /></td>
<td width="80" height="50" colspan="6" style="font-size: 60px"><img src="assets/+" alt="" width="70" height="70" class="AdultTicketAddImage" onClick="adultticketadd();calculateadultTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td width="80" height="50" style="font-size: 60px"><img src="assets/-" alt="" width="70" height="70" class="AdultTicketSubtractImage" onClick="adultticketsubtract();calculateadultTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<th width="131" height="50" nowrap bgcolor="#5E4D4E" class="display" style="color: #FFFFFF"><div class="quantity" id="displayadultqty">
<script type="text/javascript">document.write(adultticketqty);</script>
</div></th>
<td width="87" height="50" style="color: #FFFFFF"> </td>
<td width="171" height="50" class="AdultLineSell" style="font-size: 36px"><div class="lineprice" id="adultlinesell"></div></td>
</tr>
<tr>
<td height="50" colspan="4" valign="middle"><img src="assets/ConcessionwithoutSign" width="228" height="70" alt=""/></td>
<td height="50" colspan="6" valign="middle"><img src="assets/+" alt="" width="70" height="70" class="ConcessionTicketAddImage" onClick="concessionticketadd();calculateconcessionTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" valign="middle"><img src="assets/-" alt="" width="70" height="70" class="ConcessionTicketSubtractImage" onClick="concessionticketsubtract();calculateconcessionTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" valign="middle" bgcolor="#5E4D4E" class="ConcessionTicketQty" style="color: #FFFFFF"><div class="quantity" id="displayconcessionqty">
<script type="text/javascript">document.write(concessionticketqty);</script>
</div></td>
<td height="50" valign="middle" style="color: #FFFFFF"> </td>
<td height="50" valign="middle" class="ConcessionTicketLineSell" style="font-size: 36px"><div class="lineprice" id="concessionlinesell"></div></td>
</tr>
<tr>
<td height="50" style="text-align: center"><img src="assets/SOLO Logo_Transparent" width="113" height="59" alt=""/></td>
<td height="50" colspan="4" style="font-size: 60px"><img src="assets/StudentwithoutSign" width="228" height="70" alt=""/></td>
<td height="50" colspan="6" style="font-size: 60px"><img src="assets/+" width="70" height="70" alt="" class="StudentTicketAddImage" onClick="studentticketadd();calculatestudentTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" style="font-size: 60px"><img src="assets/-" width="70" height="70" alt="" class="StudentTicketSubtractImage" onClick="studentticketsubtract();calculatestudentTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" bgcolor="#5E4D4E" class="StudentTicketQty" style="color: #FFFFFF"><div class="quantity" id="displaystudentqty">
<script type="text/javascript">document.write(studentticketqty);</script>
</div></td>
<td height="50" style="color: #FFFFFF"> </td>
<td height="50" class="StudentTicketLineSell" style="font-size: 36px"><div class="lineprice" id="studentlinesell"></div></td>
</tr>
<tr>
<td height="50" valign="middle" style="text-align: center"><img src="assets/Schweppes-logo" width="104" height="50" alt=""/></td>
<td height="50" colspan="4" valign="middle" style="font-size: 60px"><img src="assets/ChildwithoutSign" width="228" height="70" alt=""/></td>
<td height="50" colspan="6" valign="middle" style="font-size: 60px"><img src="assets/+" width="70" height="70" alt="" class="ChildTicketAddImage" onClick="childticketadd();calculatechildTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" valign="middle" style="font-size: 60px"><img src="assets/-" width="70" height="70" alt="" class="ChildTicketsubtractImage" onClick="childticketsubtract();calculatechildTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" valign="middle" bgcolor="#5E4D4E" class="childticketqty" style="color: #FFFFFF"><div class="quantity" id="displaychildqty">
<script type="text/javascript">document.write(childticketqty);</script>
</div></td>
<td height="50" valign="middle" style="color: #FFFFFF"> </td>
<td height="50" valign="middle" style="font-size: 36px"><div class="lineprice" id="childlinesell"></div></td>
</tr>
<tr>
<td height="50"> </td>
<td height="50" colspan="4" style="font-size: 60px"><img src="assets/ProgramwithoutSign" width="228" height="70" alt=""/></td>
<td height="50" colspan="6" style="font-size: 60px"><img src="assets/+" width="70" height="70" alt="" class="ProgramAddImage" onClick="programadd();calculateprogramTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" style="font-size: 60px"><img src="assets/-" width="70" height="70" alt="" class="ProgramSubtractImage" onClick="programsubtract();calculateprogramTotal();calcsellprice();calctotaltickets();calctotalprograms();"/></td>
<td height="50" bgcolor="#5E4D4E" class="ProgramTicketQty" style="color: #FFFFFF"><div class="quantity" id="displayprogramqty">
<script type="text/javascript">document.write(programqty);</script>
</div></td>
<td height="50" style="color: #FFFFFF"> </td>
<td height="50" style="font-size: 36px"><div class="lineprice" id="programlinesell"></div></td>
</tr>
<tr>
<td height="3" colspan="4" nowrap="nowrap" style="font-size: 9px" "> </td>
<td height="3" colspan="8" nowrap="nowrap" style="font-size: 9px" "> </td>
<td height="3" colspan="3" nowrap="nowrap" style="font-size: 9px" "> </td>
</tr>
<tr>
<td height="30" colspan="4" class="totalquantities" ">TOTAL TICKETS:</td>
<td height="30" colspan="8" class="totalquantities" ">TOTAL PROGRAMS:</td>
<td height="30" colspan="3" class="totalquantities"">SALE TOTAL:</td>
</tr>
<tr>
<td height="63" colspan="4" bgcolor="#FF0004" style="color: #FFFFFF"><div class "totalquantities" id="totalticketitemqty"></div></td>
<td colspan="8" bgcolor="#FF0004" style="color: #FFFFFF"><div class "totalquantities" id="totalprogramitemqty"></div></td>
<td colspan="3" bgcolor="#FF0004" style="font-size: 45px"><div class="totalsell" id="totalsalesell"></div></td>
</tr>
</tbody>
<tbody>
</tbody>
</table>
<table width="1016" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="5"> </td>
<td height="5"> </td>
<td height="5" style="color: #555252"> </td>
<td height="5" colspan="2"> </td>
<td height="5"> </td>
</tr>
<tr>
<td width="228"><img src="assets/VoidSale" width="228" height="70" alt=""/></td>
<td width="44"> </td>
<td width="228" style="color: #555252"><img src="assets/DriverEntry" width="228" height="70" alt=""/></td>
<td width="228" style="color: #555252"><img src="assets/ScanEntry" width="228" height="70" alt=""/></td>
<td width="56" style="color: #000000"> </td>
<td width="232"><form action="insert.php" method="post">
<input type="image" src="assets/CompleteSale" alt="Submit">
</form></td>
</tr>
</tbody>
</table>
<p> </p>
</body>
</html>
insert.php contains
<?php
include('phpsqlget.php');
$adultticketqty = "<script>document.write(adultticketqty);</script>";
//echo $adultticketqty;
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "speedway", "speedwayticketsales");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt insert query execution
$sql = "INSERT INTO stdsalesrecords (qtyadulttickets, qtyconcessiontickets, qtystudenttickets, qtychildtickets, qtyprograms, totalsell) VALUES ($adultticketqty, '4', '0', '2', '1', '212')";
if(mysqli_query($link, $sql)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
phpsqlget.php contains
<?php
$db = new PDO('mysql:host=localhost;dbname=speedwayticketsales', 'root', 'speedway');
// Lookup Adult Ticket price from SQL Table
$sql = "SELECT ticketprice FROM stdevent_prices WHERE tickettype = 'Adult'";
$select = $db->prepare($sql);
$select->bindParam('Adult', $Adult, PDO::PARAM_INT);
$select->execute();
$AdultPriceSQL = $select->fetch(PDO::FETCH_ASSOC);
$AdultPrice = $AdultPriceSQL['ticketprice'];
// Lookup Concession Ticket price from SQL Table
$sql = "SELECT ticketprice FROM stdevent_prices WHERE tickettype = 'Concession'";
$select = $db->prepare($sql);
$select->bindParam('Concession', $Concession, PDO::PARAM_INT);
$select->execute();
$ConcessionPriceSQL = $select->fetch(PDO::FETCH_ASSOC);
$ConcessionPrice = $ConcessionPriceSQL['ticketprice'];
// Lookup Student Ticket price from SQL Table
$sql = "SELECT ticketprice FROM stdevent_prices WHERE tickettype = 'Student'";
$select = $db->prepare($sql);
$select->bindParam('Student', $Student, PDO::PARAM_INT);
$select->execute();
$StudentPriceSQL = $select->fetch(PDO::FETCH_ASSOC);
$StudentPrice = $StudentPriceSQL['ticketprice'];
// Lookup Child Ticket price from SQL Table
$sql = "SELECT ticketprice FROM stdevent_prices WHERE tickettype = 'Child'";
$select = $db->prepare($sql);
$select->bindParam('Child', $Child, PDO::PARAM_INT);
$select->execute();
$ChildPriceSQL = $select->fetch(PDO::FETCH_ASSOC);
$ChildPrice = $ChildPriceSQL['ticketprice'];
// Lookup program price from SQL Table
$sql = "SELECT ticketprice FROM stdevent_prices WHERE tickettype = 'Program'";
$select = $db->prepare($sql);
$select->bindParam('Program', $Program, PDO::PARAM_INT);
$select->execute();
$ProgramPriceSQL = $select->fetch(PDO::FETCH_ASSOC);
$ProgramPrice = $ProgramPriceSQL['ticketprice'];
?>