Jump to content

mik_se7

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by mik_se7

  1. you need to change the code to:

     

    for the name:

    if(isset($_POST['author']))
    {
    $name = $_POST['author']

    and for comments to

    if(isset($_POST['text']))
    {
    $name = $_POST['text']

    now the code should work

     

    just copy and paste this section over that code:

    // check to make sure name exists in POST
    if(isset($_POST['author']))
    {
    $name = $_POST['author'];
    }
    else
    {
    // add error to $errors array
    $errors[] = 'Please enter your name';
    }
    
    // check to make sure email exists in POST
    if(isset($_POST['email']))
    {
    $email = $_POST['email'];
    }
    else
    {
    // add error to $errors array
    $errors[] = 'Please enter your email address';
    }
    
    // check to make sure phone exists in POST
    if(isset($_POST['phone']))
    {
    $phone = $_POST['phone'];
    }
    else
    {
    // add error to $errors array
    $errors[] = 'Please enter your phone number';
    }
    
    // check to make sure comment exists in POST
    if(isset($_POST['text']))
    {
    $comment = $_POST['text'];
    }
    else
    {
    // add error to $errors array
    $errors[] = 'Please enter your comment';
    }
    // end validation
  2. your passing your values but not telling where you want to add them.

     

    INSERT INTO table name (name,email, phone, comments) VALUES ('$name', '$email', '$phoneno''$comments')

     

     

    also you have 2 $result variables i would change the query to $query rather than $result

  3. looking at the HTML code you have posted your not getting the values because your asking php to collect Name, Email, Phoneno, Comments but your id / names of your inputs are Authour, Email, Phone, Text. the $_POST will be looking for the input id / name to get the post from.

    if (isset($_POST['author']) && ($_POST['author'] !='')){
    // get data from post
    $name = $_POST["author"];
    $email = $_POST["email"];
    $phoneno = $_POST["phone"];
    $comments = $_POST["text"]; 
    
    // echo result
    $result = $name - $email - $phoneno - $comments;
    }

    just put the <?php echo $result; ?> between your body tags in the HTML for testing purposes and it should display what is being sent from the form.

  4. can we see your HTML code as it appears that the php cannot find the values name, phone, etc also it might help if at the top of your php you put

    $name = "";
    $email = "";
    $phoneno = "";
    $comment = "";

    this means that the variables are empty because until the forms details are entered they are empty and won't return a value for php to find an index and that should clear those errors

  5. I cannot understand why you would want to convert and show the answer on a different page?

    you could divide your page into div's and have a results div at the bottom of the page near the submit button.

    you could then either have the php code above the HTML on the same page or use the include function to include the php stored on another page.

    that way you would have the user select conversion > submit form > php converts > answer appears in result div.

  6. not sure if you need this or might find it helpful:

     

    a check box on my form:

    <div id="table2a">
            artist:<input id="checkboxes[]" name="artist" type="checkbox" value="Yes" onfocus="emptyElement('status')" maxlength="10">
    </div>

    and more php code for you if you want to get the data for your database after the $variable i gave you before:

    $artist = mysqli_real_escape_string($db_conx, $artist);

    $db_conx is a connection file to my database which is more secure than posting your connection details in a support post and if anyone checks out your source code.

  7. I used this php code for check boxes i had on a form i created:

    $variable = (isset($_POST['artist']) && $_POST['artist'] == 'Yes');

    or you might find javascript more helpful:

    function getArtist(){
            var artist =[];
            var art = document.getElementsByName("artist[]");
            for(var m=0; m<art.length; m++)
              if(art[m].checked){
                artist.push(art[m].value);
                alert("the artist is "+artist);
                }
    }

    the javascript and php may require some work to fit your code and the javascript will require ajax code to send the data back to php for you to add to your database if required.

    you can remove or // the alert i just put that there to help you see if you get the right value your expecting

  8. In my shopping cart i want an alert message when the maximum number of 5 for the item has been reached or ask them to delete the item if the press - when the item quantity is at 1.

     

    i have it working in php:

        //add to quantity of item
        if (isset($_POST['itemadd'])){
        $additem = $_POST['additem'];
        $sqladd = "SELECT quantity FROM orders WHERE id = '$additem'";
        $query_add = mysqli_query($db_conx, $sqladd);
        while($row = mysqli_fetch_array($query_add, MYSQLI_ASSOC)){
            $itemqty = $row['quantity'];
            if ($itemqty < 5){
            $addqty = $itemqty + 1;
            $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'";
            $add_query = mysqli_query($db_conx, $adding);
            header('Location: http://www.quichlicious.co.uk/cart.php');
            //print $additem;
            exit();
            }
            else
            {
            $usemes = "You have reached maximum quantity";
            }
            }

    But rather than display the message in a div i would like a javascript alert box to pop up, i tried the following code:

    <script type="text/javascript">
    function CheckQtyPlus(){
    var qty = '<?php echo $qty; ?>';
    alert("message here"+qty);
    }
    </script>

    but i get the same quantity number for every item in the cart, i had this error with the php update but i got round that by querying sql to give me the quantity of an item by the items id.

    can the same thing be done in javascript / ajax?

     

    $qty by the way is referenced earlier in the script to get information for the cart table to display items.

     

    thanks

    Michael

  9. $qty is grabbed from the database using the query below done just before the add and subtract buttons in php tags

    $sqlfetch = "SELECT * FROM orders WHERE orderid = '$sessionid'";
        $order_query = mysqli_query($db_conx, $sqlfetch);
        $numrows = mysqli_num_rows($order_query);
        if($numrows < 1){
         $result .="Cart is Empty";
         header("location: order.php");
        exit();
        }
        $result .= "<table><tr><th>id</th><th>Quiche Size</th><th>Pastry</th><th>Cheese</th><th>Toppings</th><th>order placed</th><th>Quantity</th><th>Price £</th><th>Remove</th></tr>";
        while($row = mysqli_fetch_array($order_query, MYSQLI_ASSOC)){
        $id = $row["id"];
        $customerid = $row["orderid"];
        $qsize = $row["size"];
        $pastry = $row["pastry"];
        $cheese = $row["cheese"];
        $top1 = $row["top1"];
        $top2 = $row["ordered"];
        date_default_timezone_set('Europe/London');
        $top2date = date("d-m-Y H:i:s", strtotime($top2));
        $qty = $row["quantity"];
  10. I have setup a website that has a shopping basket and it displays the objects ordered in a table before being purchased, i have added a plus and minus button to adjust the quantity using the following code:

    $add ="<form action='cart.php' method='post'><input type='hidden' name='additem' value='$id'/><input type='submit' name='itemadd' onclick='CheckQty()' value='+'/></form>";
        $sub ="<form name='sub' action='cart.php' method='post'><input type='hidden' name='subitem' value='$id'/><input type='submit' name='itemsub' value='-'/></form>";
    
    //add to quantity of item
        if (isset($_POST['itemadd'])){
        $additem = $_POST['additem'];
            if ($qty < 5){
            $addqty = $qty + 1;
            $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'";
            $add_query = mysqli_query($db_conx, $adding);
            header('Location: http://www.quichlicious.co.uk/cart.php');
            //print $additem;
            exit();
            }
            else
            {
            $usemes = "You have reached maximum quantity";
            }
        }
        //subtract to quantity of item
        if (isset($_POST['itemsub']) && ($_POST['itemsub'] !="")){
        $subitem = $_POST['subitem'];
                if ($qty > 1){
                $subqty = $qty - 1;
                $subing = "UPDATE orders SET quantity = '$subqty' WHERE id = '$subitem'";
                $sub_query = mysqli_query($db_conx, $subing);
                header("location: cart.php");
                exit();
                }
                else
                {
                $usemes = "<font color='red'>Please use delete to remove item</font>";
                }
        }

    The issue i have is it works great if just one item is in the basket but if i have more than 1 item in the basket i can only adjust the very last item in the baskets quantity and the others just randomly jump numbers or will not change at all?

     

    $additem gets the item ID from the table.

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