Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I sumbit a php form to text file and an email? This is what i have so fa

ID: 659188 • Letter: H

Question

How can I sumbit a php form to text file and an email?

This is what i have so far.

<?php # DISPLAY SHOPPING CART PAGE.

# Access session.
session_start() ;

# Redirect if not logged in.
//if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

# Set page title and display header section.
$page_title = 'Cart' ;
include ( 'header.html' ) ;

# Check if form has been submitted for update.
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
# Update changed quantity field values.
foreach ( $_POST['qty'] as $item_id => $item_qty )
{
# Ensure values are integers.
$id = (int) $item_id;
$qty = (int) $item_qty;

# Change quantity or delete if zero.
if ( $qty == 0 ) { unset ($_SESSION['cart'][$id]); }
elseif ( $qty > 0 ) { $_SESSION['cart'][$id]['quantity'] = $qty; }
}
}

# Initialize grand total variable.
$total = 0;

# Display the cart if not empty.
if (!empty($_SESSION['cart']))
{
# Connect to the database.
require ('connect_db.php');
  
# Retrieve all items in the cart from the 'shop' database table.
$q = "SELECT * FROM shop WHERE item_id IN (";
foreach ($_SESSION['cart'] as $id => $value) { $q .= $id . ','; }
$q = substr( $q, 0, -1 ) . ') ORDER BY item_id ASC';
$r = mysqli_query ($dbc, $q);

# Display body section with a form and a table.
echo '<form action="cart.php" method="post"><table><tr><th colspan="5">Items in your cart</th></tr><tr>';
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC))
{
# Calculate sub-totals and grand total.
$subtotal = $_SESSION['cart'][$row['item_id']]['quantity'] * $row['item_price'];
$total += $subtotal;

# Display the row/s:
echo "<tr> <td>{$row['item_name']}</td> <td>{$row['item_desc']}</td>
<td><input type="text" size="3" name="qty[{$row['item_id']}]" value="{$_SESSION['cart'][$row['item_id']]['quantity']}"></td>
<td>@ {$row['item_price']} = </td> <td>".number_format ($subtotal, 2)."</td></tr>";
}
  


?>

<?php
# Close the database connection.
mysqli_close($dbc);
  
# Display the total.
echo ' <tr><td colspan="5">Total = '.number_format($total,2).'</td></tr></table><input type="submit" name="submit" value="Update My Cart"></form>';
}
else
# Or display a message.
{ echo '<p>Your cart is currently empty.</p>' ; }
?>
<form method=post name=f1 action=''><input type=hidden name=todo value=submit>
<table border="0" cellspacing="0" >
<tr><td align=left >
<select name=month value=''>Select Month</option>
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>

</td><td align=left >
Date<select name=dt >
<option value='01'>01</option>


<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>


</td><td align=left >
Year(yyyy)<input type=text name=year size=4 value=2005>
<input type=submit value=Submit>
</table>


</form>
<?php
# Create navigation links.
echo '<p><a href="shop.php">Shop</a> | <a href="checkout.php?total='.$total.'">Checkout</a> | <a href="forum.php">Forum</a> | <a href="home.php">Home</a> | <a href="goodbye.php">Logout</a></p>' ;

# Display footer section.
include ( 'footer.html' ) ;

?>

Explanation / Answer

How can I sumbit a php form to text file and an email?

This is what i have so far.

<?php # DISPLAY SHOPPING CART PAGE.

# Access session.
session_start() ;

# Redirect if not logged in.
//if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

# Set page title and display header section.
$page_title = 'Cart' ;
include ( 'header.html' ) ;

# Check if form has been submitted for update.
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
# Update changed quantity field values.
foreach ( $_POST['qty'] as $item_id => $item_qty )
{
# Ensure values are integers.
$id = (int) $item_id;
$qty = (int) $item_qty;

# Change quantity or delete if zero.
if ( $qty == 0 ) { unset ($_SESSION['cart'][$id]); }
elseif ( $qty > 0 ) { $_SESSION['cart'][$id]['quantity'] = $qty; }
}
}

# Initialize grand total variable.
$total = 0;

# Display the cart if not empty.
if (!empty($_SESSION['cart']))
{
# Connect to the database.
require ('connect_db.php');
  
# Retrieve all items in the cart from the 'shop' database table.
$q = "SELECT * FROM shop WHERE item_id IN (";
foreach ($_SESSION['cart'] as $id => $value) { $q .= $id . ','; }
$q = substr( $q, 0, -1 ) . ') ORDER BY item_id ASC';
$r = mysqli_query ($dbc, $q);

# Display body section with a form and a table.
echo '<form action="cart.php" method="post"><table><tr><th colspan="5">Items in your cart</th></tr><tr>';
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC))
{
# Calculate sub-totals and grand total.
$subtotal = $_SESSION['cart'][$row['item_id']]['quantity'] * $row['item_price'];
$total += $subtotal;

# Display the row/s:
echo "<tr> <td>{$row['item_name']}</td> <td>{$row['item_desc']}</td>
<td><input type="text" size="3" name="qty[{$row['item_id']}]" value="{$_SESSION['cart'][$row['item_id']]['quantity']}"></td>
<td>@ {$row['item_price']} = </td> <td>".number_format ($subtotal, 2)."</td></tr>";
}
  


?>

<?php
# Close the database connection.
mysqli_close($dbc);
  
# Display the total.
echo ' <tr><td colspan="5">Total = '.number_format($total,2).'</td></tr></table><input type="submit" name="submit" value="Update My Cart"></form>';
}
else
# Or display a message.
{ echo '<p>Your cart is currently empty.</p>' ; }
?>
<form method=

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote