Jump to content

kerbdog

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kerbdog's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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> '; ?>
  2. Hi Requnix No I am posting code in php. Full code below.... <?php //Script to delete product from cart. if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' cellpadding='10' id='shopping_cart'>"; echo '<tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>'; echo "<tr><th bgcolor=#efefef>Date of Order</th bgcolor=#efefef> <th bgcolor=#efefef>Name</th> <th bgcolor=#efefef>Quantity</th> <th bgcolor=#efefef>Price</th> <th colspan='2'bgcolor=#efefef>Subtotal</th></tr>"; $date = date('h:i a , Dd M Y'); foreach($_SESSION['itemname'] as $key => $value) { //Loop sum of Subtotals to produce Grand Total $total += $_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]; //Table showing Item Id reference, price per item and subtotal echo '<tr> <td>'.$date.'</td> <td>'.$_SESSION['itemname'][$key].'</td> <td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td> <td>$'.$_SESSION['itemprice'][$key].'</td> <td header="subtotal">$'.($_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]).'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td> </tr> '; } //Echoing Grand total. echo ' <tr> <td colspan="4" bgcolor=#efefef><b>GRAND TOTAL</b></td><td colspan="2" bgcolor=#efefef><b>$'.$total.'</b></td> </table> '; ?>
  3. Hi all, Can you please advise if this code is right to display currency in a table cell in PHP and advise where I am going wrong????? <td>'number_format(.$_SESSION['itemprice'][$key], 2,".", ",".)'</td>
  4. Hi I need assistance in finding the code to produce a total of all the subtotals in my shopping cart. Not sure how to assign an attribute to the table cell because a new row is generated each time a customer adds to cart. Attached is a pdf of a screenshot and script for the cart. Thanks [attachment deleted by admin]
  5. I am pretty new to php and trying to teach myself. I can't get the values from this form to write to my flat file called orders.txt: browse_index.php <?php include("includes/menu_members.php") ?> <div id="content"> <h1>SHOPPING CART</h1> <a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a> <?php echo ' <table border="0"> <tr> <td><form id="f2" method="post"name="f2"><input type="submit" action="order_summary.php" name="submit2" value="submit order"></td> '; if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' bgcolor='#efefef'>"; echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>"; foreach($_SESSION['itemname'] as $key=>$value) { echo '<tr><td><b>'.$_SESSION['itemname'][$key].'</b></td> <td>'.$_SESSION['itemqty'][$key].'</td> <td>$'.$_SESSION['itemprice'][$key].'</td> <td name="subtotal">$'.($_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]).'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td></tr>' ; } ?> order_summary.php: <?php session_start (); $date = date ("H:i jS F"); $outputstring = $date."/t" .$_POST['h1']. ":" .$_SESSION['itemqty'][$key]. ":" .$_SESSION['subtotal'][$key]. ":" ."\n"; $fp = fopen("orders.txt","a"); fwrite($fp, $outputstring); fclose($fp); ?> Can someone direct me where I am going wrong???
  6. Thanks heaps, that helped alot.....
  7. Hi Can some steer me in the right direction. I am having issues subtotaling 2 session variables: <td>'.$_SESSION['itemqty'][$key].'*'.$_SESSION['itemprice'][$key].'</td> Can you advise if I am doing this right? Cheers
  8. Hi I am having trouble with a login code which keeps producing a true value even when the password is incorrect. Just spent 4 hours writing code and I think I've gone a bit coo coo: <h1>Login</h1> <p>If you are an existing member please login below. If you are new to this site please register to obtain your unqiue login and password by <a href="register.php">clicking here.</a></p> <?php require_once('common.php'); $error = '0'; if (isset($_POST['login'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Try to login the user $error = loginUser($username,$password); } ?> <?php if ($error != '') {?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform"> <table width="100%"> <tr><td>Username:</td><td> <input name="username" type="text" /></td></tr> <tr><td>Password:</td><td> <input name="password" type="password" /></td></tr> <tr><td colspan="2" align="center"><input type="submit" name="login" value="Login" /></td></tr> </table> </form> <a href="register.php">Register</a> <?php } if (isset($_POST['login'])){ ?> <table width="100%"><tr><td><br/> <?php if ($error == '') { echo "<h1>Welcome $username! <br/>You are logged in!</h1><br/><br/>"; echo '<a href="browse_index.php"><h2>Now you can start shopping! ---CLICK HERE---</h2></a>'; } else echo $error; ?> <br/><br/><br/></td></tr></table> <?php } ?> Code for Common.php: ?php function loginUser($user,$pass){ $errorText = ''; $validUser = false; // Check user existance $pfile = fopen("users.txt","r"); rewind($pfile); //$counter=0; while (!feof($pfile)) { $line = fgets($pfile); $temp = explode(':', $line); if ($temp[5] == $user) { // User exists, check password if (trim($data[0]) == trim(md5($pass))){ $validUser= true; $_SESSION['userName'] = $user; //$counter = $counter + 1; //echo $data; } break; } } fclose($pfile); if ($validUser != false) $errorText = "Invalid username or password!"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } function logoutUser(){ unset($_SESSION['validUser']); unset($_SESSION['userName']); } function checkUser(){ if ((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true)){ header('Location: login.php'); } } ?>
  9. Hi I am having issues with the following code. I cannot get the table to produce a subtotal multiplying the value of 'ITEMQTY' which is a text field in the form in which the user enters by the 'ITEMPRICE' field which value is located in a text document. <h1>SHOPPING CART</h1><img src="images/cart.png" alt="Cart" width="100" height="100"/> <a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a> <?php if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' cellpadding='10' >"; echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>"; foreach($_SESSION['itemname'] as $key => $value) $subtotal = ($_SESSION['itemprice']*($_SESSION['itemqty']; { echo '<tr> <td>'.$_SESSION['itemname'][$key].'</td> <td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td> <td>'.$_SESSION['itemprice'][$key].'</td> <td>'.$_SESSION['h2'][$key].'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td> </tr> <tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>'; } echo "</table>"; ?> [attachment deleted by admin]
×
×
  • 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.