显示新页面上当前表单提交的结果

时间:2016-12-16 23:02:30

标签: php html mysql forms

我有这个表单,我想在提交时在另一个页面上显示表单条目的结果。这些值都进入数据库中的表。我不知道如何将结果记录中的所有值显示在该新页面上。

这是表格:

<?php
session_start();
//connect to database
//$mysqli = mysqli_connect("localhost", "root", "", "hestonw0355");
//$mysqli = mysqli_connect("localhost", "hestonw0355", "1Password!", "hestonw0355"); //for the school server
//$mysqli = mysqli_connect("localhost", "sungr_RobW", "O+N7?Pa%Go*T&", "sungraff_hestonw0355"); //for dailyrazor.com

?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
</head>
<body style="background-color: #f9ecf2;">
<div class="col-md-8 col-sm-8 grad" style="background-color:  ; margin-right: 0px; margin-left: 0px;  border-bottom-style: solid; border-bottom-color: #4d004d; border-bottom-width: 1px; padding-left: 0px;"><!-- begin middle column -->
<!-- InstanceBeginEditable name="EditRegion3" -->
<div style='width: 85%; margin-left: auto; margin-right: auto;'>
            <br><br><br>
            <form action="check-checkout.php" method="post" name="checkout">
                <table width="100%" border="0" class="responsive">
                <tr><td><input name="order_date" type="hidden" value="<?php echo date('Y-m-d H:i:s');?>" ></td></tr>
                    <tr>
                        <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">First Name:</b5></td>
                        <td><b3 style="font-size: 12pt;"><input name="order_first_name" id="order_first_name" type="text" size="50" maxlength="50"  required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Last Name:</b5></td>
                        <td><b3 style="font-size: 12pt;"><input name="order_last_name" id="order_last_name" type="text" size="50" maxlength="40"  required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Address:</b5></td>
                        <td><b3 style="font-size: 12pt;"><input name="order_address" id="order_address" type="text" size="50" maxlength="255"  required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">City:</b5></td>
                        <td><b3 style="font-size: 12pt;"><input name="order_city" id="order_city" type="text" size="50" maxlength="50"  required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Select State:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><select name="order_state" id="order_state" >
                                                <option value="AL">Alabama</option>
                                                <option value="AK">Alaska</option>
                                                <option value="AZ">Arizona</option>
                                                <option value="AR">Arkansas</option>
                                                <option value="CA">California</option>
                                                <option value="CO">Colorado</option>
                                                <option value="CT">Connecticut</option>
                                                <option value="DE">Delaware</option>
                                                <option value="DC">District of Columbia</option>
                                                <option value="FL">Florida</option>
                                                <option value="GA">Georgia</option>
                                                <option value="HI">Hawaii</option>
                                                <option value="ID">Idaho</option>
                                                <option value="IL">Illinois</option>
                                                <option value="IN">Indiana</option>
                                                <option value="IA">Iowa</option>
                                                <option value="KS">Kansas</option>
                                                <option value="KY">Kentucky</option>
                                                <option value="LA">Louisiana</option>
                                                <option value="ME">Maine</option>
                                                <option value="MD">Maryland</option>
                                                <option value="MA">Massachusetts</option>
                                                <option value="MI">Michigan</option>
                                                <option value="MN">Minnesota</option>
                                                <option value="MS">Mississippi</option>
                                                <option value="MO">Missouri</option>
                                                <option value="MT">Montana</option>
                                                <option value="NE">Nebraska</option>
                                                <option value="NV">Nevada</option>
                                                <option value="NH">New Hampshire</option>
                                                <option value="NJ">New Jersey</option>
                                                <option value="NM">New Mexico</option>
                                                <option value="NY">New York</option>
                                                <option value="NC">North Carolina</option>
                                                <option value="ND">North Dakota</option>
                                                <option value="OH">Ohio</option>
                                                <option value="OK">Oklahoma</option>
                                                <option value="OR">Oregon</option>
                                                <option value="PA">Pennsylvania</option>
                                                <option value="RI">Rhode Island</option>
                                                <option value="SC">South Carolina</option>
                                                <option value="SD">South Dakota</option>
                                                <option value="TN">Tennessee</option>
                                                <option value="TX">Texas</option>
                                                <option value="UT">Utah</option>
                                                <option value="VT">Vermont</option>
                                                <option value="VA">Virginia</option>
                                                <option value="WA">Washington</option>
                                                <option value="WV">West Virginia</option>
                                                <option value="WI">Wisconsin</option>
                                                <option value="WY">Wyoming</option>
                                            </select></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Zip Code:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="order_zip" id="order_zip" type="text" size="50" maxlength="10" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Phone:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="order_tel" id="order_tel" type="text" size="50" maxlength="25" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Email Address:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="order_email" type="email" id="order_email" size="50" maxlength="100" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Select Card Type:</b5></td>
                        <td style=" padding-top: 5px; font-size: 24pt; color: #4d004d"><p><b5>
                        <img src="img/cc-mastercard.png" width="75" height="49" alt=""/><input type="radio" name="cc_type" value="Mastercard">
                        <img src="img/cc-visa.png" width="75" height="49" alt=""/><input type="radio" name="cc_type" value="Visa">
                        <img src="img/cc-american-express.png" width="75" height="49" alt=""/><input type="radio" name="cc_type" value="American Express">
                        <img src="img/cc-paypal.png" width="75" height="49" alt=""/><input type="radio" name="cc_type" value="PayPal">
                        </b5></p></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Card Number:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="cc_number" type="integer" id="cc_number" size="50" maxlength="16" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Expiration:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="cc_expmonth" type="integer" id="cc_expmonth" size="2" maxlength="2" required="required" /><span Style='font-size: 18pt; color: #4d004d'><b3>&nbsp/&nbsp</span></b3><input name="cc_expyear" type="integer" id="cc_expyear" size="2" maxlength="2" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"><b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">CVC Code:</b5></td>
                        <td style=" padding-top: 5px;"><b3 style="font-size: 12pt;"><input name="cc_cvc" type="integer" id="cc_cvc" size="3" maxlength="3" required="required" /></b3></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"></td>
                        <td style=" padding-top: 5px;"><b5 style="font-size: 12pt;"><input name="submit" type="submit" value="Submit" /><span>&nbsp&nbsp&nbsp</span><input name="reset" type="reset" value="Reset" /></b5></td>
                    </tr>


                </table>
                </form>
                </div>
            <br><br><br> 
<!-- InstanceEndEditable --> 
      </div><!-- end middle column -->

</body>
<!-- InstanceEnd --></html>

那里还有很多其他的东西,但这是形式......而且...... 这是表单的处理页面(check-checkout.php)

<?php
session_start();

//connect to database
$mysqli = mysqli_connect("localhost", "root", "", "hestonw0355");
//$mysqli = mysqli_connect("localhost", "hestonw0355", "1Password!", "hestonw0355") or die("Error " . mysqli_error($mysqli)); //for the school server
//$mysqli = mysqli_connect("localhost", "sungr_RobW", "O+N7?Pa%Go*T&", "sungraff_hestonw0355") or die("Error " . mysqli_error($con)); //for dailyrazor.com
?>
<?php
$datetime = $_POST['order_date'];
$fname = $_POST['order_first_name'];
$lname = $_POST['order_last_name'];
$address = $_POST['order_address'];
$city = $_POST['order_city'];
$state = $_POST['order_state'];
$zip = $_POST['order_zip'];
$phone = $_POST['order_tel'];
$email = $_POST['order_email'];
$cardtype = $_POST['cc_type'];
$cardnumber = $_POST['cc_number'];
$cardmonth = $_POST['cc_expmonth'];
$cardyear = $_POST['cc_expyear'];
$cardcvc = $_POST['cc_cvc'];

$mysqli = "INSERT INTO store_orders (`order_date`, `order_first_name`, `order_last_name`, `order_address`, `order_city`, `order_state`, `order_zip`, `order_tel`, `order_email`, `cc_type`, `cc_number`, `cc_expmonth`, `cc_expyear`, `cc_cvc` ) VALUES ('".$datetime."','".$fname."','".$lname."','".$address."','".$city."','".$state."','".$zip."','".$phone."','".$email."','".$cardtype."','".$cardnumber."','".$cardmonth."','".$cardyear."','".$cardcvc."')";

if (isset($_POST['checkout'])) {
    header ("location:checkout-view.php");
}
    else { header("location:checkout-form.php"); }

mysqli_close($mysqli);
?>

这是表格输入的表格:

    CREATE TABLE `store_orders` (
  `id` int(11) NOT NULL,
  `order_date` varchar(70) NOT NULL,
  `order_first_name` varchar(50) NOT NULL,
  `order_last_name` varchar(50) NOT NULL,
  `order_address` varchar(255) NOT NULL,
  `order_city` varchar(50) NOT NULL,
  `order_state` char(50) NOT NULL,
  `order_zip` varchar(10) NOT NULL,
  `order_tel` varchar(25) NOT NULL,
  `order_email` varchar(100) NOT NULL,
  `cc_type` varchar(30) NOT NULL,
  `cc_number` int(16) NOT NULL,
  `cc_expmonth` int(2) NOT NULL,
  `cc_expyear` int(2) NOT NULL,
  `cc_cvc` int(3) NOT NULL
)

这是我想要显示表单提交结果的页面。我已经有一个页面显示他们购物车的内容,总计了他们所选项目的价格。一旦我将表单结果显示在其下,我将有一个页面显示所有用户的选择,价格的价格和总数,以及他们在结帐表单中输入的所有内容。我现在并不关心进入最终购买流程或任何安全性的所有内容,只需将所有内容显示在用户的页面上。

这是我需要把它放入的页面(checkout_view.php)我al:

<?php
session_start();
//connect to database
$mysqli = mysqli_connect("localhost", "root", "", "hestonw0355");
//$mysqli = mysqli_connect("localhost", "hestonw0355", "1Password!", "hestonw0355"); //for the school server
//$mysqli = mysqli_connect("localhost", "sungr_RobW", "O+N7?Pa%Go*T&", "sungraff_hestonw0355") or die("Error " . mysqli_error($mysqli)); //for dailyrazor.com
$sub_total = 0;
$display_block = "<h1>Your Shopping Cart</h1>";

//check for cart items based on user session id
$get_cart_sql = "SELECT st.id, si.item_title, si.item_price,
                st.sel_item_qty, st.sel_item_size, st.sel_item_color FROM
                store_shoppertrack AS st LEFT JOIN store_items AS si ON
                si.id = st.sel_item_id WHERE session_id =
                '".$_COOKIE['PHPSESSID']."'";
$get_cart_res = mysqli_query($mysqli, $get_cart_sql)
                or die(mysqli_error($mysqli));



if (mysqli_num_rows($get_cart_res) < 1) {
    //print message
    $display_block .= "<p>You have no items in your cart.
    Please <a href=\"seestore.php\">continue to shop</a>!</p>";
} else {

    while ($cart_info = mysqli_fetch_array($get_cart_res)) {
        $id = $cart_info['id'];
        $item_title = stripslashes($cart_info['item_title']);
        $item_price = $cart_info['item_price'];
        $item_qty = $cart_info['sel_item_qty'];
        $item_color = $cart_info['sel_item_color'];
        $item_size = $cart_info['sel_item_size'];
        $total_price = sprintf("%.02f", $item_price * $item_qty);
        $sub_total += $total_price;
        $grand_total = sprintf("%.02f", $sub_total * .06 + $sub_total);
        $ship_count += $item_qty;
        $total_ship = sprintf("%.02f", $ship_count * 3.5 + $grand_total);

    //get info and build cart display
    $display_block .= <<<END_OF_TEXT

    <table width='100%'>
    <tr>
    <th>Title</th>
    <th>Size</th>
    <th>Color</th>
    <th>Price</th>
    <th>Qty</th>
    <th>Total Price</th>
    <th>Action</th>
    </tr>
    <tr>
    <td>$item_title <br></td>
    <td>$item_size <br></td>
    <td>$item_color <br></td>
    <td>\$ $item_price <br></td>
    <td>$item_qty <br></td>
    <td>\$ $total_price</td>
    <td><a href="removefromcart.php?id=$id">remove</a></td>
    </tr>
    <tr>
    <td colspan='5'></td>
    <td style='text-align: right;'>Subtotal: </td>
    <td>\$ $sub_total </td>
    </tr>
    <tr>
    <td colspan='4'></td>
    <td style='text-align: right;'>Add 6% Sales Tax</td>
    <td style='text-align: right;'>Total with tax.: </td>
    <td>\$ $grand_total </td>
    </tr>
    <tr>
    <td colspan='4'></td>
    <td style='text-align: right;'>Add $3.50 per item for shipping.</td>
    <td style='text-align: right;'>Grand Total: </td>
    <td>\$ $total_ship </td>
    </tr>
END_OF_TEXT;
    }
    $display_block .= "</table>";
}
//free result
mysqli_free_result($get_cart_res);

//close connection to MySQL
mysqli_close($mysqli);
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<style>
table {
        border: 2px solid #4d004d;
        border-collapse: collapse;
        margin-top: 5px;
    }
    th {
    border: 1px solid #4d004d;
    padding: 6px;
    font-weight: bold;
    background: #d9b3ff;
    text-align: center;
    color: black;
    font-family: 'Roboto Condensed', sans-serif; font-weight: 700;  font-style: normal;
    font-size: 12pt;
    }
    td {
    border: 1px solid #4d004d;
    padding: 6px;
    vertical-align: top;
    text-align: center;
    background-color: #f5ecfe;
    font-family: 'Roboto Condensed', sans-serif; font-weight: 400;  font-style: normal;
    font-size: 12pt;
    color: black;
    }

</style>
</head>
<body style="background-color: #f9ecf2;">
<div class="col-md-8 col-sm-8 grad" style="background-color:  ; margin-right: 0px; margin-left: 0px;  border-bottom-style: solid; border-bottom-color: #4d004d; border-bottom-width: 1px; padding-left: 0px;"><!-- begin middle column -->
<!-- InstanceBeginEditable name="EditRegion3" -->
            <br><br><?php echo $display_block; ?><br><br><br> 
<!-- InstanceEndEditable --> 
      </div><!-- end middle column -->
</body>
<!-- InstanceEnd --></html>

页面上还有很多其他内容,但不需要在此处显示。我希望在现有的PHP中添加表单结果的显示代码,如项目选择,然后在html中添加另一个(echo $ display_block;),但我不在乎......任何方式我都可以获取刚刚提交到页面中显示的当前记录将成为我的一天!我对这些东西很陌生 - 但是学习 - 所以我只需要一些帮助。解决这个问题对大多数人来说可能是幼儿园的事情。感谢...

1 个答案:

答案 0 :(得分:0)

如果我理解你正确做了什么......

您需要做的是存储插入数据库中的ID并将其发送回checkout_view.php页面,然后您可以在该页面上按该ID进行搜索。

所以&#34; check-checkout.php&#34;你会做这样的事情:

使用ID(如果我了解你如何正确使用mysql)

$last_id = mysqli_insert_id($mysqli);

点击此处了解详情:http://php.net/manual/en/mysqli.insert-id.php

然后:

if (isset($_POST['checkout'])) {
    header ("location:checkout-view.php?id=$last_id");
}
    else { header("location:checkout-form.php"); }

然后调整sql查询以使用以下方法从URL中的ID中获取行:

$_GET['id']

真正基本的东西,但你会得到它的手:)

聚苯乙烯。我希望那些不是真正的密码;)