[英]Display Results of Current Form Submission on a New Page
我有此表单,提交后要在另一个页面上显示该表单条目的结果。 所有值都进入数据库的表中。 我不知道如何使结果记录中的所有值都显示在该新页面上。
形式如下:
<?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> / </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>   </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)我的页面:
<?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中将表单结果的显示代码添加到现有的PHP中,例如项目选择,然后在html中放置另一个(echo $ display_block;),但我不在乎...任何方式我都可以得到刚刚提交到页面中以供显示的当前记录将使我高兴! 我对这些东西真的很陌生-但是要学习-所以我只需要一些帮助。 对于大多数人来说,解决方案可能是幼儿园的事情。 谢谢...
如果我了解您的做法正确...
您需要做的是存储插入数据库中的ID,然后将其发送回checkout_view.php页面,然后可以在该页面上通过该ID搜索。
因此,在“ check-checkout.php”上,您将执行以下操作:
使用获取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']
真的很基础的东西,但是您会得到帮助的:)
PS。 我希望这些不是真实的密码;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.