Jump to content

Recommended Posts

Hi

 

I am trying to Post form fields into an XML file and it doesn't seem to be working for me, I know I got most of the code right but just can't place a finger on why its not posting into the allocated folder and creating the xml file.

 

<?php
session_start ();

$date = date('h:i a , D d M Y');

	$errors = array ();

  if (isset ($_POST['submit']))
  {
  	$ord_date = $_POST['odate'];
  	$ord_first = $_POST['first'];
  	$ord_sur = $_POST['surname'];
  	$ord_address = $_POST['paddress'];
  	$ord_country = $_POST['country'];
  	$ord_city = $_POST['pcity'];
  	$ord_state = $_POST['state'];
  	$ord_zip = $_POST['zip'];
  	$ord_total = $_POST['total'];
  	$ord_card = $_POST['cards'];
  	$visa = $_POST['visa'];
  	$mcard = $_POST['master'];
  	$ord_cardno = $_POST['cardno'];
  	$ord_exp = $_POST['expiry'];
  	  	
  }
if($ord_first == ''){
	$errors[] = 'First Name is blank';
}
if($ord_sur == ''){
	$errors[] = 'Surname Name is blank';
}
if($ord_addres <= ''){
	$errors[] = 'Address is blank';
}
if($ord_country == ''){
	$errors[] = 'Country is blank';
}
if($ord_city == ''){
	$errors[] = 'City is blank';
}
if($ord_state == ''){
	$errors[] = 'State is blank';
}
if($ord_zip == ''){
	$errors[] = 'Zip is blank';
}
if($cardno == ''){
	$errors[] = 'Enter Card Number';
}
if($ord_exp == ''){
	$errors[] = 'Card Must have Expiry Date';
}

function validateCC($cardno, $card) {

//Make sure there are only digits
$cardno = ereg_replace("[-[:space:]]","",$card);

// Check each credit card type
switch ($card) {
case "visa":
$cardCheck = ereg("^4[0-9]{12}$¦^4[0-9]{15}$",$cardno);
break;

case "mcard":
$cardCheck = ereg("^5[1-5][0-9]{14}$", $cardno);
break;

}

//Now, check against the Luhn forumula

$cardNumber = strlen($cardno);
$total = 0;

for($i = 0; $i < strlen($cardNumber); $i++)
{
$currentNum = substr($cardNumber, $i, 1);
if(floor($currentNum / 2)!= $currentNum / 2)
{
$currentNum *= 2;
}
if(strlen($currentNum) == 2)
{
$firstNum = substr($currentNum, 0, 1);
$secondNum = substr($currentNum, 1, 1);
$currentNum = $firstNum + $secondNum;
}
$numSum += $currentNum;
}

// If the total has no remainder, it's OK

$passCheck = ($numSum % 10 == 0? true : false);

/*If both $validateCC and $passCheck are true, then we return true, indicating that the card number is valid. If not, we return false, indicating that either the card number was in an incorrect format, or it failed the Mod 10 check:*/

if($validateCC && $passCheck)
{
return true;
} else {
return false;
}
}

if(count($errors) == 0){
  $xml = new SimpleXMLElement('<order></order>');
	$xml->addChild('date', $ord_datet);
	$xml->addChild('fname', $ord_first);
	$xml->addChild('sname', $ord_sur);
	$xml->addChild('sname', $ord_address);
	$xml->addChild('sname', $ord_country);
	$xml->addChild('sname', $ord_city);
	$xml->addChild('sname', $ord_state);
	$xml->addChild('sname', $ord_zip);
	$xml->addChild('sname', $ord_total);
	$xml->addChild('sname', $ord_card);
	$xml->addChild('sname', $ord_cardno);
	$xml->addChild('sname', $ord_exp);
	$xml->asXML('orders/' . $first. '.xml');
	header('Location: order_summary.php');
	die;
}	



include ('includes/head.php');

echo '
<div id="wrapper">
<div id="header"></div>';

echo '<h1>ORDER SUMMARY</h1>';

echo "<br/><br/>";

  echo '
  <Form id="t5" method="post" action="" name="t5">';
  
	if(count($errors) > 0){
		echo '<ul>';
		foreach($errors as $e){
			echo '<li>' . $e . '</li>';
		}
		echo '</ul>';
	}

  echo'<table border="0" cellpadding="10">';
  echo '<tr><th>Date of Order</th bgcolor=#efefef>
  <th>Name</th>
  <th>Quantity</th>
  <th>Price</th>
  <th colspan="2">Subtotal</th></tr>';
   foreach($_SESSION['itemname'] as $key => $value)
  
  
{
//Loop sum of Subtotals to produce Grand Total
$total += $_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key];
$subtotal = $_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key];
//Table showing Item Id reference, price per item and subtotal
echo
'<tr>
<td header="odate">'.$date.'</td>
<td header="oid">'.$_SESSION['itemname'][$key].'</td>
<td header="oqty">'.$_SESSION['itemqty'][$key].'</td>
<td header="oprice">$'.$_SESSION['itemprice'][$key].'</td>
<td header="sub">$'.$subtotal.'</td>
</tr>
';

}
//Echoing Grand total.
  echo '
  <tr>
<td colspan="4" header="gtotal"><b>GRAND TOTAL</b></td><td colspan="2"><b>$'.$total.'</b></td>
  </table>
  
  <h1>Enter Details</h1>
<table border="0">
<tr>
<td>Date of Order</td><td name="odate">'.$date.'</td>
</tr>
<tr>
<th colspan="2">Personal Details</th>
   <tr>
  <td>First Name:</td><td><input type="text" name="first"></td>
  </tr>
  <tr>
  <td>Surname Name:</td><td><input type="text" name="surname"></td>
   </tr>
  <tr>
  <td>Postal Address:</td><td><input type="text" name="paddress"></td>
   </tr>
  <tr>
  <td>Country:</td><td><input type="text" name="country"></td>
   </tr>
  <tr>
  <td>City:</td><td><input type="text" name="pcity"><br/></td>
   </tr>
  <tr>
  <td>State:</td><td><input type="text" name="state"><br/></td>
   </tr>
  <tr>
  <td>Zip Code/Postcode:</td><td><input type="text" name="zip"></td>
   </tr>
   <tr>
   <th colspan="2">PAYMENT</th>
   </tr>
   <tr>
  <td>Total Amount Payable:</td><td><input type="text" name="total" value=$'.$total.'><br/><td>
  </tr>
  <tr>
  <td>Card Type:</td>
  <td>
  <select name="cards">
  	<option value="visa">VISA</option>
  	<option value="master">MASTERCARD</option>
  </select>
  </td>
  </tr>
  <tr>
  <td>Card Number:</td><td><input type="text" name="cardno"</td>
  </tr>
  <tr>
   <td>Expiry Date:</td><td><input type="text" name="expiry"></td>
  </tr>
  <tr>
   <td><input type="submit" value="Confirm Details"></td>
  </tr>
  
  </form>
';


  
  
?>

Link to comment
https://forums.phpfreaks.com/topic/228254-posting-form-values-to-an-xml-file/
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.