Jump to content

frshjb373

Members
  • Posts

    42
  • Joined

  • Last visited

Posts posted by frshjb373

  1. I'm trying to use php to echo only the first 10 items of an array.  I have the entire list displaying if there are more than 10 items, but I can't figure out how to display only 10.  Here's the code.  Any help is much appreciated.  Thank you in advance!

    <?php 
    	if (count($all_machines) > 10) {
    		echo '<ul>';
    		foreach($all_machines as $machine) {
    			echo '<li>' . $machine['name'] . '</li>';
    		}
    		echo '</ul>';
    	} else {
    		echo "No machines";
    	}
    ?>
    
  2. I have the following code. Functionally, it's working great, but when you toggle between button 1 and button 2 and the div slides into position, the size of the div collapses.  I'd like to make it so that the page doesn't resize when toggling back and forth.  I'm figuring this is an easy fix, but I can't seem to get it right.  Code is below. Any help is much appreciated.  Thank you in advance!

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    
    <script>
    $(function () {
        $("[name=toggler]").click(function () {
            $('.toHide').hide();
            $("#blk-" + $(this).val()).show('slide');
        });
    });
    </script>
    
    <label>
        <input id="rdb1" type="button" name="toggler" value="1" />
    </label>
    <label>
        <input id="rdb2" type="button" name="toggler" value="2" />
    </label>
    
    
    <div id="blk-0" class="toHide">
    <div class="center-form-img" >
    <img src="{{media url="wysiwyg/form-inactive.jpg"}}" alt="" />
    </div>
    </div>
    <div id="blk-1" class="toHide" style="display:none"> {{block type=core/template name=ContactUs template=cmg/ContactUs1.phtml}}</div>
    <div id="blk-2" class="toHide" style="display:none">{{block type=core/template name=ContactUs template=cmg/ContactUs2.phtml}}</div>
    
  3. So the action looks like the following:

    action="<?php echo $this->getUrl('ccfp/form') ?>index"
    

    This is what it looks like in source code in browser:

    action="http://www.domain.com/ccfp/form/index"
    

    We are using Magento, but I can't figure how to manipulate the dynamic code to be an https rather than http.

     

    Thank you for the help.  Look forward to hearing back if anyone has additional info.

  4. I'm not sure if this is the best place to post this issue, but any help is much appreciated.

     

    We have a form on our Magento site, that when submitted on Firefox, prompts the following security warning:

     

    Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party.

    Are you sure you want to continue sending this information?

     

    I have contacted our hosting and they explained it's an issue with the code, "you would typically getting a notice like that if you're calling assets over an http on a page that is using https."

     

    If anyone has any insights as to how to avoid this from a development perspective, please let me know. Thank you in advance for the help!

     

     

  5. Trying to pass some data through url using some javascript. One of the records in my mysql database contains an ampersand. Not really sure how to encode the url. Any help is much appreciated!

     

    Here's the JS I'm using:

    function reload(form)
    {
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    self.location='sell-iphone.php?cat=' + val ;
    }
    

     

    And here's the PHP. "$cat" is the value I'm pulling from the database. Dont' think the db is relevant to this however:

    <?php
    @$cat=$_GET['cat']; // Use this line or below line if register_global is off
    if(strlen($cat) < 0){ // to check if $cat is numeric data or not.
    echo "Data Error";
    exit;
    }
    ?>
    

  6. After looking at it more, I think it's a Javascript issue. Here's the Javascript and PHP...

     

    Javascript:

    function reload(form)
    {
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    self.location='sell-iphone.php?cat=' + val ;
    }
    

     

    PHP:

    <?php
    @$cat=$_GET['cat']; // Use this line or below line if register_global is off
    if(strlen($cat) < 0){ // to check if $cat is numeric data or not.
    echo "Data Error";
    exit;
    }
    ?>
    

  7. Trying to create a shopping cart that allows user to select not only the product, but the condition of the item (poor condition, good condition, excellent condition), and additional accessories based on the form data submitted. Basically, I'd like to use the same ID for a product with different conditions and accessories. Just not sure how to get there. Any help, advice, or resources is much appreciated! Thank you.

     

    Here is the form data I'm collecting from the user:

    // Phone Type
    $field_Phone = $_POST['field_Phone'] = $_SESSION['field_Phone'];
    // Accessories
    $field_Charger = $_POST['field_Charger'] = $_SESSION['field_Charger'];
    $field_Case = $_POST['field_Case'] = $_SESSION['field_Case'];
    $field_Manual = $_POST['field_Manual'] = $_SESSION['field_Manual'];
    $field_Box = $_POST['field_Box'] = $_SESSION['field_Box'];
    // Item Condition
    $field_Condition = $_POST['field_Condition'] = $_SESSION['field_Condition'];
    

     

    Here's the item from the database:

    <?php
    // DB Query
    $query = "SELECT * FROM phones WHERE name = '{$field_Phone}'";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $output[] = '<a href="cart-demo/cart.php?action=add&id='.$row['id'].'">Add to cart</a>';
    }
    ?>
    

     

    Here's the functions that output the product selected:

    <?php
    function writeShoppingCart() {
    $cart = $_SESSION['cart'];
    if (!$cart) {
    return 'Cart (Empty)';
    } else {
    // Parse the cart session variable
    $items = explode(',',$cart);
    $s = (count($items) > 1) ? 's':'';
    return 'Cart (<a href="cart-demo/cart.php">'.count($items).'</a>)';
    }
    }
    function showCart() {
    global $db;
    $cart = $_SESSION['cart'];
    if ($cart) {
    $items = explode(',',$cart);
    $contents = array();
    foreach ($items as $item) {
    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
    }
    $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
    $output[] = '<table>';
    foreach ($contents as $id=>$qty) {
    $sql = 'SELECT * FROM phones WHERE id = '.$id;
    $result = $db->query($sql);
    $row = $result->fetch();
    extract($row);
    $output[] = '<tr>';
    $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
    $output[] = "<td>" .$name. "</td>";
    $output[] = "<td><img src=\"../images/catalog-images/" .$photo_image. "\" width=\"50\"/></td>";
    $output[] = "<td> ".$_SESSION['accessories']." </td>";
    $output[] = '<td> $ '.$price.'</td>';
    $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
    $output[] = '<td> $'.($base_price * $qty).'</td>';
    $total += $base_price * $qty;
    $output[] = '</tr>';
    }
    $output[] = '</table>';
    $output[] = '<p>Grand total: <strong>$ '.$total.'</strong></p>';
    $output[] = '<div><button type="submit">Update cart</button></div>';
    $output[] = '</form>';
    } else {
    $output[] = '<p>You shopping cart is empty.</p>';
    }
    return join('',$output);
    }
    ?>
    

     

    Here's the cart code:

    $cart = $_SESSION['cart'];
    $action = $_GET['action'];
    $_SESSION['accessories'];
    switch ($action) {
    case 'add':
    if ($cart) {
    $cart .= ','.$_GET['id'];
    } else {
    $cart = $_GET['id'];
    }
    break;
    case 'delete':
    if ($cart) {
    $items = explode(',',$cart);
    $newcart = '';
    foreach ($items as $item) {
    if ($_GET['id'] != $item) {
     if ($newcart != '') {
     $newcart .= ','.$item;
     } else {
     $newcart = $item;
     }
    }
    }
    $cart = $newcart;
    }
    break;
    case 'update':
    if ($cart) {
    $newcart = '';
    foreach ($_POST as $key=>$value) {
    if (stristr($key,'qty')) {
    $id = str_replace('qty','',$key);
    $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
    $newcart = '';
    foreach ($items as $item) {
     if ($id != $item) {
     if ($newcart != '') {
     $newcart .= ','.$item;
     } else {
     $newcart = $item;
     }
     }
    }
    for ($i=1;$i<=$value;$i++) {
     if ($newcart != '') {
     $newcart .= ','.$id;
     } else {
     $newcart = $id;
     }
    }
    }
    }
    }
    $cart = $newcart;
    break;
    }
    $_SESSION['cart'] = $cart;
    

  8. So I'm building a web application that I am currently only using jQuery/Javascript to validate data. I'd like to add some server-side PHP validation in addition to the client-side jQuery, but I'm not so clear on how to achieve this with my current setup...

     

    Here's my setup:

    I have a Form A (a dropdown, a series of checkboxes, and set of radio buttons). Upon submit, this information is used to generate a price quote on Form B. On Form B, I use the information from Form A and some new fields that are used to generate a shipping label (First Name, Last Name, Street, City, State, Zip Code, Email, Phone Number, Radio Buttons, and Terms and Conditions Check Box). I then use all this info on Form B to generate that shipping label in a process script which also sends confirmation email too. (which I'll call "Page 3").

     

    So now, I basically have three pages. What I'd like to do is make the Dropdown and Radio Buttons Required on Form A required before the user can get to Form B and then validate some of this data before the user can get to the process form. I see a lot of tutorials that use same page validation by either processing the form on the same page or to a server, but in my case I want to use this information on following pages. Is there some way to check data on the same page and if the data passes then process to a following page? Any advice, resources, or help is much appreciated! I am happy to share the code if you some working solutions.

     

    Thanks in advance!

  9. Not sure if this is the best place to be posting this topic so please let me know if this can better addressed somewhere else.  Anyways, I have a form, that upon submission creates a return shipping label automatically.  To avoid users going back and attempting to resubmit the form (which will thereby run the script to create another shipping label), I'd like to figure out a way to completely expire that form page...or redirect the user to another page if going back.

     

    Any advice or resources would be much appreciated. Thanks!

  10. Awesome!  Think I figured it out.  Here's what I came up with.  Honestly, not sure if I even need "LIMIT 0,1" at the end of the query.

     

    <?php
    mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed");
    mysql_select_db ($DB_name) or die("Connection Failed");
    $query = "SELECT name2 FROM cell_brands WHERE name = '{$field_Phone}' LIMIT 0,1";
    
    
    $result = mysql_query($query);
    ?>
    
    <?php
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    	$price = $row['name2'];
    }
    
    ?>
    

  11. Ok...I think I'm getting there, but I can't figure quite out how to associate "field_Name" variable on the next page. 

     

    I think basically what I'm trying to say in my code is..."If "field_Phone" is equal to any value in "$row['name1']" then echo the associated "$row['name2"] value."

     

    I'd like to think I'm close, but I haven't nailed it yet.  The code I came up with is below. Am I even close?

     

    Thanks again for all the help!

     

    <?php
    mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed");
    mysql_select_db ($DB_name) or die("Connection Failed");
    $query = "SELECT * FROM cell_brands";
    $result = mysql_query($query);
    ?>
    
    <?php
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if ($field_Phone =  ($row['name1'])) {
    	echo $row['name2'];
    }
    }
    
    ?>
    
    

  12. Basically I'd like to echo "name1" in the browser, which is working fine! But I'd also like to bring over the associated "name2" field value without the user being able to see this value until the form has been processed. I am using "field_Name" to process both these variables at once on the following page so I'd also like to separate these variables as well.

     

    I'm sure it's an extremely simple fix, but I can't figure it out.  Any help is much appreciated!

     

    <?php
    mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed");
    mysql_select_db ($DB_name) or die("Connection Failed");
    $query = "SELECT * FROM table";
    $result = mysql_query($query);
    ?>
    <select name="field_Name">
    <option value="">Select one...</option>
    <?php
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    ?>
    <?php $row['name']; ?>
    <option value="<?php echo $row['name1'];?>  <?php $row['name2'];?>"> <?php echo $row['name1'];?> </option>
    <?php
    }
    ?>
    </select>
    

×
×
  • 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.