sent dynamic table to mysql - php

I am trying to send my dynamic table to mysql database but I am having difficulties. I've tried using a for to get it to send but I'm not getting very far. At the moment I am just displaying it but I really want to send it to mysql. I want all the data to be in one row with the rest of the data like test case name, test case number and so on. But the dynamic table must be put into the same row where the rest of the data goes.
Below you will see what I have done and maybe you can see what my intentions are...
<div class="col-md-6">
<label>Test Case Number:</label>
<?php
$sql = "SELECT test_case_number FROM qa_testing_application ORDER BY id desc LIMIT 1";
$result = mysqli_query($database, $sql) or trigger_error("SQL", E_USER_ERROR);
while ($row = mysqli_fetch_assoc($result)) {
?>
<input class="form-control" style="display: none" type="text" name="test_case_number" readonly="readonly" value="<?php echo $row['test_case_number']+3?>">
<?php } ?>
<label>Company Name:</label>
<input class="form-control" type="text" name="test_case_company_name"/>
<label>Tester:</label>
<input class="form-control" style="display: none" type="text" name="user_username" value="<?php echo $user_username ?>" readonly/>
<label>System:</label>
<input class="form-control" type="text" name="test_case_system"/>
<label>URL:</label>
<input class="form-control" type="text" name="test_case_url"/>
</div>
<div class="col-md-12" style="border: 1px solid #28415b; padding-bottom: 12px; padding-top: 12px;margin-top: 20px; margin-bottom: 15px">
<p>
<INPUT class="btn btn-primary ladda-button" type="button" value="Add row" onclick="addRow('dataTable')" />
<INPUT class="btn btn-primary ladda-button" type="button" value="Delete row" onclick="deleteRow('dataTable')" />
</p>
<div class="clear"></div>
<p>'All fields below are compatible to use markdowns for editing' </p>
<table class="table table-hover">
<thead>
<tr>
<th style="width: 15px">Chk</th>
<th style="width: 335px">Action:</th>
<th style="width: 326px;">Expected System Response:</th>
<th style="width: 151px;">Pass/ Fail</th>
<th>Comment</th>
</tr>
</thead>
</table>
<table id="dataTable" class="table table-hover">
<tbody>
<tr>
<td style="width:20px;"><INPUT type="checkbox" name="chk[]" id="chk"/></td>
<td><INPUT class="form-control" type="text" name="step[]" autocomplete="on" placeholder="Action" required/></td>
<td><INPUT class="form-control" type="text" name="url[]" autocomplete="on" placeholder="Expected Outcome" required/></td>
<td>
<select name="passfail[]" class="form-control" style="width:120px;">
<OPTION value="Pass">....</OPTION>
<OPTION value="Pass">Pass</OPTION>
<OPTION value="Fail">Fail</OPTION>
</select>
</td>
<td>
<TEXTAREA class="form-control" type="text" name="comment[]" rows="2" cols="15" placeholder="Comment" required></TEXTAREA>
</td>
</tr>
</tbody>
</table>
Thats my table that i am dynamically making...
In my PHP file i display the dynamic table as follows:
<table class="table table-bordered">
<thead>
<tr>
<td>Step</td>
<td>process</td>
<td>Expected System Response</td>
<td>
<center>Pass/ Fail</center>
</td>
<td>Comment</td>
</tr>
</thead>
<?php
if (isset($_POST)) {
$step = $_REQUEST['step'];
$url = $_REQUEST['url'];
$pass_fail = $_REQUEST['passfail'];
$comment = $_REQUEST['comment'];
$countPass = 0;
$countFail = 0;
foreach ($step as $key => $row) {
?>
<tbody>
<tr>
<td><?php echo $key + 1; ?></td>
<td><?php echo $step[$key]; ?></td>
<td><?php echo $url[$key]; ?></td>
<td style="color:<?php if ($pass_fail[$key] == 'Fail') {
echo 'color: red';
} else {
echo 'limegreen';
} ?>"><b>
<center><?php echo $pass_fail[$key]; ?></center>
</b></td>
<td><?php echo $comment[$key]; ?>
</td>
</tr>
</tbody>
</table>
Now how do i insert it into mysql???

So basically what you need to do to insert it into your database is doing a sql query in PHP.
Let me show you an code example:
//establish db connection
$con=mysqli_connect("dbhost","username","dbpassword","dbname");
$sql = "INSERT INTO tablename (name_of_row1,
name_of_row2,
name_of_row3)
VALUES ('".$value1."',
'".$value2."',
'".$value3."')";
mysqli_query($con, $sql);
mysqli_close($con);
So you have to open a sql connection and then insert your data to the table you want. I hope this it's clear enough. Now if the PHP file gets called the SQL query is beeing made.

Related

Why I only get the value of the last row in my table when I click the 'AddToCart' in other row

I have this code in php
<div style="width:75%;height: 600px;float: left;overflow-x: auto;">
<form method="POST" action="addtocart.php">
<table class="table" style="overflow-x: auto; width: 900px;">
<tr>
<th class="danger" id="th">Items</th>
<th class="danger" id="th">Price(PhP)</th>
<th class="danger" id="th">Quantity</th>
<th class="danger" id="th">Action</th>
</tr>
<?php
$item=mysqli_query($conn,"select * from store");
while($pqrow=mysqli_fetch_array($item)){
$iid=$pqrow['id_item'];
?>
<tr>
<td class="warning" id="td">
<?php echo $pqrow['item']; ?></td>
<td class="warning" id="td"><input type="hidden" name="price" value="<?php echo $pqrow['price']; ?>"><?php echo $pqrow['price']; ?></td>
<td class="warning" id="td"><input type="number" style="width: 70px;" name="qty" value="1"></td>
<td class="warning" id="td"><input type="hidden" name="item" value="<?php echo $iid; ?>"><input class="btn btn-success btn-md" type="submit" name="addtocart" value="AddToCart<?php echo $iid; ?>"></td>
</tr><?php } ?>
</table></form>
</div>
When I click AddToCart in first row, the value of the last row has been fetch. I want to get the id and the input quantity when I click the AddToCart in 1st row.
As you have only one form tag and multiple inputs with same name on this form, value of next input overwrites previous one. As a result you always have value of the last row.
You can fix it for example with creating a separate form for every row, e.g:
<div style="width:75%;height: 600px;float: left;overflow-x: auto;">
<table class="table" style="overflow-x: auto; width: 900px;">
<tr>
<th class="danger" id="th">Items</th>
<th class="danger" id="th">Price(PhP)</th>
<th class="danger" id="th">Quantity</th>
<th class="danger" id="th">Action</th>
</tr>
<?php
$item = mysqli_query($conn,"select * from store");
while ($pqrow=mysqli_fetch_array($item)) {
$iid=$pqrow['id_item'];?>
<tr>
<td class="warning" id="td">
<?php echo $pqrow['item']; ?></td>
<td class="warning" id="td"><?php echo $pqrow['price']; ?></td>
<td class="warning" id="td"><input type="number" style="width: 70px;" name="qty" value="1"></td>
<td class="warning" id="td">
<!-- Separate form for each record -->
<form method="POST" action="addtocart.php">
<input type="hidden" name="price" value="<?php echo $pqrow['price']; ?>">
<input type="hidden" name="item" value="<?php echo $iid; ?>">
<input class="btn btn-success btn-md" type="submit" name="addtocart" value="AddToCart<?php echo $iid; ?>">
</form>
</td>
</tr>
<?php } ?>
</table>
</div>
In this case you should track with javascript the value of quantity field. Of course, you can move <input type="number"> in a form too, but this will break your markup.
Also, if you're familiar with javascript, you can add some client preprocessing (getting values from inputs of a certain row) and use ajax-request to send these values to server.

Update data in table row [PHP]

I have a standard HTML table, each row in the table is generated from a database table using a loop.
At the end of each row I have an update button, I'd like this to update data in the table fields.
The image below shows the concept.
The table itself
<div class="container" id="users">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<form method="post" action="">
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th width="10%" style="text-align:left">Forename</th>
<th width="15%" style="text-align:left">Surname</th>
<th width="35%" style="text-align:left">Email</th>
<th width="30%" style="text-align:left">Permissions</th>
<th width="5%" style="text-align:left">Update</th>
<th width="5%" style="text-align:left">Delete</th>
</tr>
</thead>
<tbody>
<tr>
<!--here showing results in the table -->
<?php
$adminquery = "SELECT * FROM admin ORDER by user_id DESC";
$IDlist = mysqli_query($dbconEDB, $adminquery);
while($rowlist=mysqli_fetch_array($IDlist))//while look to fetch the result and store in a array $row.
{
$user_id = $rowlist["user_id"];
$admin_email = $rowlist["admin_email"];
$forename = $rowlist["forename"];
$surname = $rowlist["surname"];
$JPortal = $rowlist["JPortal"];
$Tenders = $rowlist["Tenders"];
$News= $rowlist["News"];
$Events = $rowlist["Events"];
$Users= $rowlist["Users="] ;
?>
<td style="text-align:left">
<div class="form-group">
<input name="user_id" id="user_id" type="text" class="form-control" value="<?php echo $user_id;?>">
<input name="forename" id="forename" type="text" class="form-control" value="<?php echo $forename;?>">
<div class="hidden"> <?php echo $forename;?></div>
</div>
</td>
<td style="text-align:left">
<div class="form-group">
<input name="forename" id="surname" type="text" class="form-control" value="<?php echo $surname;?>">
<div class="hidden"> <?php echo $surname;?></div>
</div>
</td>
<td style="text-align:center">
<div class="form-group">
<input name="admin_email" id="admin_email" type="text" class="form-control" value="<?php echo $admin_email;?>">
<div class="hidden"> <?php echo $admin_email;?></div>
</div>
</td>
<td style="text-align:center">
<label>
<input name="JPortal" type="checkbox" id="JPortal" value="1" <?php if ($JPortal == 1) echo "checked='checked'" ;?>> Jobs
</label>
<label>
<input type="checkbox" name="Tenders" value="1" id="Tenders" <?php if ($Tenders == 1) echo "checked='checked'" ;?>> News
</label>
<label>
<input type="checkbox" name="News" value="1" id="News" <?php if ($News == 1) echo "checked='checked'" ;?>> Tenders
</label>
<label>
<input type="checkbox" name="Events" value="1" id="Events" <?php if ($Events == 1) echo "checked='checked'" ;?>> Events
</label>
<label>
<input type="checkbox" name="Users" value="1" id="Users" <?php if ($Users == 1) echo "checked='checked'" ;?>> Users
</label>
</td>
<td style="text-align:center">
<input class="btn btn-newable " type="submit" value="Update" name="EDBsubmit">
</td>
<td style="text-align:center">
<button class="btn btn-newable">update2</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
</div>
</div>
</div>
I'm thinking I've just had an off day and could of in fact wrapped the form around each row of the table.
An easy way to do this is to have a form in each TD containing the update button.
Just make this button a input[type=submit], then add a input[type=hidden] in this form containing the ID of you line row. Then, you could basically get the ID in $_POST.
Example :
<td class="actions">
<form method="post">
<input type="hidden" name="row_id" value="<?php echo $line['id']; ?>"/>
<input type="submit" value="Update"/>
</form>
</td>

Multiple select checkbox to display the table record

I want to filter the table by using multiple select checkbox by selecting multiple Company Name and the table will display the record related to the selected checkbox. It only able to select one checkbox and display one related record only but it cannot multiple select checkbox.
<form name="frmSearch" id="frmSearch" method="post" action="">
<label>Company Name </label>
<select id="multiple-checkboxes" multiple="multiple" name="COMPANYNAME">
<?php
$query = mysqli_query($conn_connection, "SELECT * FROM sl_iv GROUP by COMPANYNAME");
while ($row = mysqli_fetch_assoc($query)) {
echo "<option value='".$row["COMPANYNAME"]."'".($row["COMPANYNAME"]==$_POST["COMPANYNAME"] ? " selected" : "").">".$row["COMPANYNAME"]."</option>";
}
?>
</select>
<br></br>
<button type="submit" id="submit" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button>
<a href="cust_due_list.php">
<button type="button" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-refresh"></span> RESET</button>
</a>
<br></br>
<table id="table">
<center>
<thead>
<tr class="item-row">
<th width="15%" style="text-align:center"><span>Doc No.</span></th>
<th width="10%" style="text-align:center"><span>Due</span></th>
<th width="5%" style="text-align:center"><span>Age</span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Ammount</span></th>
<th width="10%" style="text-align:center"><span>Payment</span></th>
<th width="10%" style="text-align:center"><span>OutStanding</span></th>
</tr>
</thead>
</center>
<tbody>
<?php
if(isset ($_POST['COMPANYNAME']))
{
$COMPANYNAME = $_POST['COMPANYNAME'];
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME = '".$COMPANYNAME."' or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$docamt = $row['DOCAMT'];
?>
<tr class="item-row">
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DocNo" id=DocNo0 " name="DocNo " value="<?php echo htmlspecialchars($row[ 'DOCNO']);?>" readonly></td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DueDate" id="DueDate0" name="DueDate" value="<?php echo htmlspecialchars($row['DUEDATE']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DateAge" id="DateAge0" name="DateAge" value="<?php echo $dateage;?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm CompanyName" id="CompanyName0" name="CompanyName" value="<?php echo htmlspecialchars($row['COMPANYNAME']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly>
</td>
</tr>
<?php
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#multiple-checkboxes').multiselect();
});
</script>
When you receive multiple-select POST it cames as array, so you should use "IN" operator in your mysql request instead of comparison.
Try to change one part of your code:
if(isset ($_POST['COMPANYNAME'])) {
$COMPANYNAME = $_POST['COMPANYNAME'];
$COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
$companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME IN (".$companiesParam.") or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}

Updating mysql database when data is passed through as sessions

I've got the sessions working to display the child information, I now want to be able to edit that information and update the database. I've tried every youtube video and website but nothing uses $_SESSION they all use $_POST.
<div class="post">
<h1 class="title">Child Details: </h1>
<p class="title"><img src=" <?php echo "".$_SESSION['sourcepath']; ?>"
</p>
<p class="title"><?php echo "".$_SESSION['ChildID']; ?></p>
<table style="width: 100%">
<tr>
<td style="width: 106px">Name</td>
<td style="width: 252px"><?php echo "".$_SESSION ['Firstname']; ?> <?php echo "".$_SESSION['Surname']; ?></td>
<td style="width: 94px">School</td>
<td><form method="post">
<br />
<textarea name="School" cols="20" rows="5"><?php echo "".$_SESSION['School']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Date of Birth</td>
<td><?php echo "".$_SESSION['DateOfBirth']; ?></td>
<td style="width: 94px">English</td>
<td><form method="post">
<br />
<textarea name="English" cols="20" rows="5"><?php echo "".$_SESSION['English']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Age</td>
<td><?php echo "".$_SESSION['Age']; ?>;</td>
<td style="width: 94px">Science</td>
<td><form method="post">
<br />
<textarea name="Science" cols="20" rows="5"><?php echo "".$_SESSION['Science']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Address</td>
<td><form method="post">
<br />
<textarea name="Address" cols="20" style="height: 89px"><?php echo "".$_SESSION['Address']; ?></textarea></form>
</td>
<td style="width: 94px">Maths</td>
<td><form method="post">
<br />
<textarea name="Maths" cols="20" rows="5"><?php echo "".$_SESSION['Maths']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Postcode:</td>
<td><?php echo "".$_SESSION['PostCode']; ?>;</td>
<td style="width: 94px">Homework</td>
<td><form method="post">
<br />
<textarea name="Homework" cols="20" rows="5"><?php echo "".$_SESSION['Homework']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Contact Number</td>
<td><form method="post">
<textarea name="ContactNumber" cols="20" rows="2"><?php echo "".$_SESSION['ContactNumber']; ?></textarea></form>
</td>
<td style="width: 94px">Additional</td>
<td><form method="post">
<br />
<textarea name="Additional" cols="20" rows="8"><?php echo "".$_SESSION['Additional']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Mother Name</td>
<td><?php echo "".$_SESSION['MotherName']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">Last Update</td>
<td><?php echo "".$_SESSION['TimeStamp']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">
</td>
<td>
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
</td>
<?php session_start(); ?>
<?php
$connect = mysql_connect("127.0.0.1" , "root" , "") or die ("Couldnt connect to database");
mysql_select_db("travellerfile") or die ("couldnt find the database");
$School = $_SESSION['School'];
$Maths = $_SESSION['Maths'];
$English = $_SESSION['English'];
$Science = $_SESSION['Science'];
$Homework = $_SESSION['Homework'];
$Additional = $_SESSION['Additional'];
$id = $_SESSION['ChildID'];
$q = "SELECT * FROM child WHERE ChildID = $_SESSION[ChildID]";
$result = mysql_query($q);
$person = mysql_fetch_array($result);
$u = "UPDATE child SET Maths= '$_SESSION['Maths']', Science= '$_SESSION['Science']';
?>
$_SESSION['School'] = $_POST['School'];
$School = $_SESSION['School'];
Somewhere you'll have to declare that $_SESSION['School'] contains the value of the Textarea with the name 'School'. You can't just expect PHP to put POST variables into SESSION variables
For example:
$_SESSION['ChildID'] = 5;
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
This will post you:
$_POST['id'] = 5;
So:
UPDATE table SET col = $_POST['id'];
Update $_SESSION end grab $_POST for database;
...
$School = $_['School'] = $_POST['School'];
$Maths = $_SESSION['Maths'] = $_POST['Maths'];
$English = $_SESSION['English'] = $_POST['English'];
$Science = $_SESSION['Science'] = $_POST['Science'];
$Homework = $_SESSION['Homework'] = $_POST['Homework'];
$Additional = $_SESSION['Additional'] = $_POST['Additional'];
$id = $_SESSION['ChildID'];
...
Both $_POST and $_SESSION are merely arrays. The only thing that makes them special is that they are global. So, if you have code that works for $_POST, just substitute in the corresponding $_SESSION values.
What your real issue is, is that you are submitting a form. Forms can submit using get or post methods. There is no session method. So your values are arriving at your php script in the $_POST variable. You could then copy them to the $_SESSION variable before running your update, but there's really no good reason to. The only reason they would need to be in $_SESSION is so that they can be output if the form needs to be re-displayed with the submitted values.

How do I submit a Web page with PHP?

I've created a three step order form and I need help with the third step.
1. form is filled out by the business and clicks on "preview order"
2. business views their order and clicks "confirm" (should be on "bizform.php" but I haven't tried it because I have no clue on how to do it.)
3. by clicking "confirm" the "Web page" or data from "bizform.php" is sent to the business and myself.
Questions: Is it possible? If so, can you point me in the right direction? TYVM
My form:
<div class="span4 diff">
<h3>Business Information</h3>
<br/>
<form action="bizform.php" method="post">
<label for="bizName" class="control-label">
Business:</label>
<input type="text" id="bizName" name="bizName" class="input-large">
<label for="bizAddress" class="control-label">
Business Address:</label>
<input type="text" id="bizAddress" name="bizAddress" class="input-large">
<label for="bizCity" class="control-label">
City:</label>
<input type="text" id="bizCity" name="bizCity" class="input-large">
<label for="bizState" class="control-label">
State:</label>
<input type="text" id="bizState" name="bizState" class="input-large">
<label for="bizZip" class="control-label">
Zip code:</label>
<input type="text" id="bizZip" name="bizZip" class="input-large">
<label for="fullName" class="control-label">
Full Name:</label>
<input type="text" id="fullName" name="fullName" class="input-large">
<label for="bizEmail" class="control-label">
E-mail:</label>
<input type="text" id="bizEmail" name="bizEmail" class="input-large">
</div>
<div class="span7">
<h3>Choose Products</h3>
<br/>
<table class="table table-bordered table-striped">
<thead>
<tr class="diffhead">
<th>Product</th>
<th>Price</th>
<th>Training</th>
<th>Total</th>
<th>Qty</th>
</tr>
</thead>
<tbody>
<tr>
<td>Product One</td>
<td>$1000.00</td>
<td>$100.00</td>
<td>$1100.00</td>
<td>
<label class="input" for="productOne"></label>
<input type="text" class="input-mini" value="0" id="productOne" name="productOne">
</td>
</tr>
<tr>
<td>Product Two</td>
<td>$1000.00</td>
<td>$100.00</td>
<td>$1100.00</td>
<td>
<label class="input" for="productTwo"></label>
<input type="text" class="input-mini" value="0" id="productTwo" name="productTwo">
</td>
</tr>
<tr>
<td>Product Three</td>
<td>$1000.00</td>
<td>$100.00</td>
<td>$1100.00</td>
<td>
<label class="input" for="productThree"></label>
<input type="text" class="input-mini" value="0" id="productThree" name="productThree">
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="form-actions">
<button class="btn btn-danger" type="reset" style="float:left">
<i class="icon-remove-sign icon-white"></i> Cancel Order</button>
<button class="btn btn-primary" type="submit" style="float:right">Preview Order
<i class="icon-circle-arrow-right icon-white"></i></button>
</form>
<?php
include '_inc/footer.html';
?>
My form processor:
<?php
include '_inc/header.html';
?>
<?php
$bizName = $_POST['bizName'];
$bizAddress = $_POST['bizAddress'];
$bizCity = $_POST['bizCity'];
$bizState = $_POST['bizState'];
$bizZip = $_POST['bizZip'];
$fullName = $_POST['fullName'];
$bizEmail = $_POST['bizEmail'];
$productOne = $_POST['productOne'];
$productTwo = $_POST['productTwo'];
$productThree = $_POST['productThree'];
$moneyOff = '';
$totalPro = $productOne + $productTwo + $productThree;
define('PRODPRICE', 1100);
$totalMoney = $productOne * PRODPRICE
+ $productTwo * PRODPRICE
+ $productThree * PRODPRICE;
if ( $totalMoney == 2200 )
{
echo '<div class="alert alert-success">Go Back! You can get a product for free!</div>';
}
if ( $totalMoney == 3300 )
{
$moneyOff = 1100;
}
else
{
$moneyOff = 0;
}
define('STOCKFEE', 10);
$stockFee = $productOne * STOCKFEE
+ $productTwo * STOCKFEE
+ $productThree * STOCKFEE;
?>
<h1 align="center">Order Agreement</h1>
<br/>
<?php
echo '<strong>' .$bizName. '</strong> is purchasing the following products and services from CBE:</p>';
echo '<div class="well">
<table cellspacing="0" cellpadding="0" width="800px">
<thead>
<th>Qty</th>
<th>Product</th>
<th>Price</th>
</thead>
<tbody>
<tr>
<td align="center">'. $productOne .'</td>
<td align="center">Product One</td>
<td align="center">$1,100.00</td>
</tr>
<tr>
<td align="center">'. $productTwo .'</td>
<td align="center">Product Two</td>
<td align="center">$1,100.00</td>
</tr>
<tr>
<td align="center">'. $productThree .'</td>
<td align="center">Product Three</td>
<td align="center">$1,100.00</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="right">Sub Total:</td>
<td align="center">'.number_format($totalMoney,2).'</td>
</tr>
<tr>
<td> </td>
<td align="right">Discount:</td>
<td align="center">'.number_format($moneyOff,2).'</td>
</tr>
<tr>
<td> </td>
<td align="right">Grand Total:</td>
<td align="center">'.number_format($totalMoney - $moneyOff,2).'</td>
</tr>
</tbody>
</table>
</div>';
echo '<p>Business agrees to pay <strong> '.number_format($totalMoney - $moneyOff,2).' </strong>for these products and services. In addition, Business will pay an additional <strong> '.number_format($stockFee,2).' </strong>to cover stock fee.</p>';
?>
<div class="row"> </div>
<div class="row">
<div align="left">
<table cellspacing="10" cellpadding="10" width="850px">
<tbody>
<tr><td> </td></tr>
<tr>
<td valign="top">
<?php
echo '<strong>' .$bizName. '</strong> <br/>';
echo $bizAddress.'<br/>';
echo $bizCity.', ';
echo $bizState.' ';
echo $bizZip.'';
?>
</td>
<td valign="top">
<strong>CBE</strong><br/>
Corporate Headquarters<br/>
555 Main Street<br/>
PHPLAND, DB 78987-3849<br/>
888-098-3049
</td>
</tr>
</tbody>
</table>
</div>
</div>
<?php
include '_inc/footer.html';
?>
To store the the data across multiple forms:
<?php
session_start(); // Initiates the session, and loads the _SESSION variable
var_dump($_SESSION); // Show the data in the _SESSION variable
// Load data into the sessions
$_SESSION['a'] = 1;
$_SESSION['b'] = 'hello world';
if (!isset($_SESSION['c'])) $_SESSION['c'] = 0;
else $_SESSION['c'] += 2;
At first, you should see an empty array. Then, refresh and you will see your session data.
http://php.net/manual/en/features.sessions.php - for reference and further education...
Since you can easily access the data via $_POST array, to send all this information to the respective recipients use the mail() function of php to create an email and send it over to whoever you want.
When you submit the form to bizform.php, store you post variables in hidden input fields, and submit those to your form processor on step 3.
EDIT:
In other words, have your Confirm process post your hidden fields to another processor that creates your email content from the POST, and send TO the business, and yourself as a CC or BCC header.
<input name="AID" type="hidden" id="AID" value="<?php echo $_POST['AID']; ?>" size="32" />

Categories