Jump to content

[SOLVED] Checking the fields in form


Paymemoney

Recommended Posts

Hi i am having trouble with making a code that checks all fields are filled in before proceeding.

 

Here are some of the codes i have tried to use.

<?php
if (($_POST[order_name]) || ($_POST[order_state])|| ($_POST[order_city])|| ($_POST[order_zip])|| ($_POST[order_tel])|| ($_POST[order_email])|| ($_POST[payment])) {
		header("form.htm");
	exit;
} 

if ((!$_POST[$name]) || (!$_POST[$state])|| (!$_POST[$city])|| (!$_POST[$zip])|| (!$_POST[$phone])|| (!$_POST[$email])|| (!$_POST[$payment])|| (!$_POST[$shipping])) {
	header("form.htm");
	exit;
}

if ((!$_POST[order_name]) || (!$_POST[order_state])|| (!$_POST[order_city])|| (!$_POST[order_zip])|| (!$_POST[order_tel])|| (!$_POST[order_email])|| (!$_POST[payment])) {
header("form.htm");
exit;
}

if (empty($_POST['order_name']) || empty($_POST['order_state'])|| empty($_POST['order_city'])|| empty($_POST['order_zip'])|| empty($_POST['order_tel'])|| empty($_POST['order_email'])|| empty($_POST['payment'])) {
	header("form.php");
	exit;
}?>

 

The two files i have is one for the form and the second one where this coding will go.

Here are the codes for first and second file:

 

First File form.htm

<html>
<head>
<style type="text/css">
body
{
background-color:#99FFCC;
}
h1 {text-align:center}
</style>
<title>Checkout Form</title>
</head>
<body>
<b><h1>Checkout Form</h1></b>
<table border="0" align="center">
<form style="text-align:center" action="results.php" method="post">
<tr><td><P><strong>*First/Last Names:</strong><br></td>
<td><input type="text" name="order_name" size=30 maxlength=75></td></tr>


<tr><td><P><strong>*Address:</strong><br></td>
<td><input type="text" name="order_address" size=30></tr></td>

<tr><td><P><strong>*City/State/Zip:</strong><br></td>
<td><input type="text" name="order_city" size=30 maxlength=50>
<input type="text" name="order_state" size=5 maxlength=3>
<input type="text" name="order_zip" size=10 maxlength=4></tr></td>

<tr><td><P><strong>*Telephone Number:</strong><br></td>
<td><input type="text" name="order_tel" size=30 maxlength=10></td></tr>

<tr><td><P><strong>*Email Address:</strong><br></td>
<td><input type="text" name="order_email" size=30 maxlength=50></td></tr>

<tr><td><P><strong>*Shipping Option:</strong><br></td>
<td><select name="shipping_total">
<option value="10">Local</option>
<option value="15">Local Express</option>
<option value="20">International</option>
<option value="25">International Express</option>
</select></tr></td>

<P>
<tr><td><P><strong>*Payment Method:</strong></td>
<td>Credit Card:<input type="radio" name="payment" value="credit">
Paypal:<input type="radio" name="payment" value="paypal"></tr></td>

<tr><td><p>* Required Fields<br></td>
<td></td></tr>

</table>
<p style="text-align:center"><input type="Submit" name="Proceed" value="Proceed">
</form>
<p style="text-align:left"><a href = "showcart.php">Back to cart</a>
</body>
</html>

 

Second File results.php

<?php
$name=$_POST['order_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'];
$payment=$_POST['payment'];
$shipping=$_POST['shipping_total'];

//This is where the code is going to go.

$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sportinggoods",$conn)  or die(mysql_error());

$query = "INSERT INTO store_orders VALUES ('',now(),'$name','$address','$city','$state','$zip','$phone','$email','$item_total','$shipping','$payment','$authorization','$status')";
mysql_query($query);

mysql_close();

$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sportinggoods",$conn)  or die(mysql_error());

$query="SELECT * FROM store_orders";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>

 

Hope someone can help me.

 

P.S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.