1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Adding a Total Variable Dynamically

Discussion in 'PHP' started by Alley Cat, Mar 31, 2007.

  1. #1
    I have a script for ordering screen savers to be custom built, but what I want to do is to dynamically generate a total fee variable from the information that the form is submitting. This is the script that I am using for the order form, which works fine.
    
    <?php
    $subt=$_POST['Send'];    //testing to see if submit button has been clicked
    if ( isset($subt) ) {
    ?>
    
    <?php 
    // ***********************  connectin script  *********************************************
    $cnx = @mysql_connect('localhost','loginname','password');
    if (!$cnx) 
         {
        exit("<p>Can't connect to the database server, please try later.</p>");
         } 
        else {
        
        }
    if (!mysql_select_db('database'))
       {
       mysql_close($cnx);
        exit("<p>Can't connect to the database server, please try later.</p>");
        }
    // ***********************  connectin script  *********************************************
    
       $email=$_POST['email'];
       $title = $_POST['title'];
       $description=$_POST['description'];
       $picture=$_POST['pictures'];
       $display=$_POST['display'];
       $track=$_POST['track'];
       $screen=$_POST['screen_resolution'];
       $transition=$_POST['transition_effect'];
       
       if ($email == "" || $title == "" || $description == "" || $picture == ""  || $display == "" || $track == "" || $screen == "" || $transition == "")
          {
          mysql_close($cnx);
          exit("You forgot to enter some detail please amend your error."); 
          }
             
    //   send them an email with their order details ***********************************
    
    $subject = "Screen Saver Order";
    $body = "Thank you for ordering the screen saver $title.  You have informed us that you have submitted $picture images to display for $display seconds with $transition as your transition effect, and you want them to fit a screen size of $screen.  You have chosen $track as your backing track.  This screen saver will be sent to $email when it is ready";
    
    $didit = mail($email, $subject, $body, "email-address);
    
    if (!$didit)
         {
       echo("Your message has not been received, please try contacting us later");
         // any code you want
         } else{
    
    echo("Thank you for your screen saver order, we will send it to you at $email.");
    
         }
    //   send them an email with their order details ***********************************
    
    $subject = "Screen Saver Order";
    $body = "An order has been placed for a Screen Saver called $title.  It contains $picture images, which will have $transition as transition effect for display upon $screen pixels.  The track required is $track, and they want the description of $description.  When completed, send it to $email.";
    
    mail("email-address", $subject, $body, "another-email-address");
    
    // add order details to Screen_Saver
    
          $myquery = "Insert into Screen_Saver (email, title, description, pictures, display, track, screen_resolution, transition_effect, order_date) values('$email', '$title', '$description', '$picture', '$display', '$track', '$screen', '$transition', NOW())";
          $result = mysql_query($myquery);         //do the update query
          if (!$result){echo("Update unsuccessful");};
    ?>
    
    <?php } else { ?> 
    <?php
    $page_title = ("Screen Saver Order");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
    <head>
    <script type="text/JavaScript">
    <!--
    var ref = document.referrer;
    document.write("<script language=\"JavaScript\" src=\"url/tracker.php?refer=" + escape(ref) + "\"></script>");
    //-->
    </script>
    <meta http-equiv="content-type" content="text/html; ch*beep*t=utf-8"/>
    
    <meta name="keywords" content="Home-Groan, Accident Albums, Home of Accident Recordings, Alley Cat, Brill O'Padd, Alley Cat and Brill O'Padd, Alley Cat and Brill O'Padd Song Writers, Accident Fated to Happen album, Accident Black Spot album, Accident In The Home album, Accident In The Making album, Accident Zone Ahead album" />
    
    <link href="error.css" rel="stylesheet" type="text/css"/>
    
    
    <title><?php echo $page_title; ?></title>
    
    <script type="text/javascript">
    <!--
    currentPic = "Album1";
    
    function hot(name){
       eval(currentPic + ".style.display='none'");
       eval(name + ".style.display='inline'");
       mainPic.src= "images/" + name + ".JPG";
       currentPic = name;
    }
    // -->
    </script>
    
    </head>
    
    <body>
    
    <div class="header">
    <a href="http://www.home-groan.com/"><img src="images/logo2.JPG" alt="Accident Recordings" /></a><p>Home Groan<br /><?php echo $page_title; ?></p>
    
    </div>
    
    <div class="leftcolumn">
    <table>
    
    <tr>
    <td>
    <img src="images/logo_button.JPG" alt="Home-Groan Home" />Home</td>
    </tr>
    
    <tr>
    <td>
    <img src="images/logo2_button.JPG" alt="Accident Albums" />Groan</td>
    </tr>
    
    <tr>
    <td>
    <img src="images/screen-saver_button.JPG" alt="Home-Groan Screen Savers" />Members</td>
    </tr>
    
    <tr>
    <td>
    <img src="images/website_button.JPG" alt="Home-Groan Web Sites"/>Only</td>
    </tr>
    
    <tr>
    <td><a href="http://www.accidentrecordings.com/contact.php">Contact Us</a></td>
    </tr>
    
    </table>
    <p>
    <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88"></img></a><br />
    <br />
     <a href="http://jigsaw.w3.org/css-validator/">
      <img style="border:0;width:88px;height:31px"
           src="http://jigsaw.w3.org/css-validator/images/vcss" 
           alt="Valid CSS!"></img>
     </a>
    </p>
          
    </div>
    <div class="centre">
    <form method="post" action="Screen_Saver.php">
    <p>Enter the your email address here.<br />Email: <input name="email" type="text" size="40" maxlength="60" /></p>
    <p>Enter the name you want to give to your Screen Saver.<br />Title: <input name="title" type="text" size="30" maxlength="40" /></p>
    <p>Please enter a brief description here.<br />Description: <textarea name="description" cols="40" rows="2"></textarea></p>
    <p>How many images have you uploaded?<br />Number: <input name="pictures" type="text" size="5" maxlength="5" /></p>
    <p>Please choose your Screen Resolution (pixels):<br /><input type="radio" name="screen_resolution" value="640 * 480" />640 * 480,   <input type="radio" name="screen_resolution" value="800 * 600" />800 * 600,   <input type="radio" name="screen_resolution" value="1024 * 768" />1024 * 768, <input type="radio" name="screen_resolution" value="1280 * 960" />1280 * 960</p>
    <p>Select your transition effect for the images.<br />
    <?php
    $transition = array ('Clock', 'Clock Back', 'Curtain', 'Double Clock', 'Mist', 'Mosaic', 'Mosaic Large', 'Round Rain', 'Rain', 'Alternate', 'Slide in Left to Right', 'Slide in Right to Left', 'Slide in Top to Bottom', 'Slide in Bottom to Top', 'Roll in Left to Right', 'Roll in Right to Left', 'Roll in Top to Bottom', 'Roll in Bottom to Top', 'Round In', 'Round Out', 'Square In', 'Square Out', 'Circles', 'Squares', 'Horizontal Lines', 'Vertical Lines', 'Power On', 'Power Off', 'Fan', 'Fan Back', 'Circles Spiral', 'Double Circles Spiral', 'Back Circles Spiral', 'Back Double Circles Spiral', 'Sierpinski Fractal', 'Rhombus In', 'Rhombus Out', 'Arrow', 'Towers', 'Muntains');
       echo '<select name="transition_effect">';
       foreach ($transition as $value) {
          echo "<option value=\"$value\">$value</option>\n";
       }
    echo '</select>';
    ?>
    </p>
    <p>Select the track you would like as the backing track to your Screen Saver.<br />
    <?php
    $track = array ('500 A Day', 'Act of Union', 'Angel Eyes', 'Angel of Mercy', 'Angelic Innocense', 'Arizona Boots', 'Big Girl', 'Bug Eyed Sea Monster', 'Can You Hear Me', 'Caravan', 'Child of War', 'Come Along to Me', 'Dancing Between Silk Sheets', 'Dearest Helen', 'Depths of Hell', 'Dreaming of the Sun', 'Drifting', 'Flying High', 'Girl When I Loved You', 'Glencoe', 'Graveyard Sign', 'Harmony in B E D', 'Help Me Nurze', 'Honey To My Lips', 'I Am She', 'Image Makers', 'Indian Lament', 'Is This Our Future', 'It\'s Too Late', 'Lambs to the Slaughter', 'Love It Babe', 'Lovely Lady', 'Macho Man', 'Maybe Tomorrow', 'Misty Was The Morning', 'Moaning Sod', 'Moorland Trip', 'Muddley', 'My Ballerina', 'My Pleasures Are Simple', 'My Poetry Rhymes', 'Never Be Mine', 'Odd Job Man', 'Painting Pictures', 'Passion for Loving', 'Planting Different Seeds', 'Poets Corner', 'Potent Images', 'Pretty Maiden', 'Pretty Princess', 'Remembering', 'Rhythm Method', 'Ring My Bell', 'Rock n Roll Singer', 'Sacrificial Man', 'See The City', 'Sleepless Nights', 'Song of Your Land', 'Songs of Yesterday', 'Supermarket Blues', 'Symphony of Romance', 'Thank God For Love', 'The River', 'Think', 'Tortured Lady', 'Travelling Around', 'Undisputed Magician', 'Warrior Forlorn', 'When I First Came To This Town', 'Wings of Freedom', 'Woman Love Me', 'Zombie');
    echo '<select name="track">';
       foreach ($track as  $value) {
          echo "<option value=\"$value\">$value</option>\n";
       }
    echo '</select>';
    ?>
    </p>
    <?php
    
    $display = range (1, 30);
    echo '<p>Please select the number of seconds each image will display for.&nbsp;
    <select name="display">';
    foreach ($display as $value) {
       echo "<option value=\"$value\">$value</option>\n";
       }
    echo '</select></p>';
    ?>
    <p><input type="submit" name="Send" value="Place Order" /> 
    
    <input type="reset" name="Submit2" value="Amend Order" /></p>
    
    </form> 
    
    </div>
    <div class="footer">
    <h5>&copy; www.home-groan.com 2006, designed and built by www.home-groan.com</h5></div>
    </body>
    
    </html>
    
    <?php
    
    }
    
    ?>
    
    PHP:
    The code below is what I am trying to incorporate into the script, but need help in doing so. What I would like to know is, do I need to add or subtract some code to make it submit to the table?
    
    $total=$_POST['total']; \\ will go into where I have set the other variables.
    || $total == "" \\ this will go into the if query.
    
    The following will go before the submit query.
    $query = "SELECT FROM Screen_Saver (pictures, cost, price) WHERE 'email' = $email";
          $result = mysql_query($query);
          if ($result) {
          
          while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
          $total = $row['pictures'] * $row['cost'] + $row['price'];
          }
    };
    
    , total \\ these 2 will go into the submit query.
    , '$total'
    
    PHP:
    This will go into the form.
    <p>Total cost: <input type="text" name="total" value="<?php echo $row['pictures'] * $row['cost'] + $row['price']; ?>" /></p>
     
    Alley Cat, Mar 31, 2007 IP