Jump to content

Sepodati

Members
  • Posts

    234
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by Sepodati

  1. You have to remember or pass $industry and $position back to Search-Result.php. Keeping them in a session may work. If they are passed as a part of a form, prefer those values, but otherwise look in a session for "previous" values of the two search terms.

  2. You need to learn that when dealing with forms, there are two actions that take place. The first action is to display your form and the second action is to process the form once it's submitted. You're blending these actions in the same file (which is okay), but the form creation and form processing are being handled all within each other and it's confusing.

     

    $sname_array is only set when you're processing the form, not before. Because it's only defined in a block of code that's run when a $_POST variable is present.

     

    Structure your code so that it's clear when the form is being processed versus when it's being displayed.

     

    if(isset($_POST['submit'])) {

    //process form

    } else {

    //display form

    }

     

    Also, I don't think these lines are doing what you think they're doing...

          while ($sline = fgets ($sfile)) {
              $name = explode (',', $sline);
     
          }
  3. Your logic is flawed. The loop will only continue if the conditions evaluate to true. $headcount is not equal to 2 and $loopcount is not equal to 5, so the condition fails and the loop exists after the first go.

     

    What I think you want is the loop to continue while $headcount is less than 2 or $loopcount is less than 5.


  4. <strong>Repair Status:</strong>
    <select name="status">
    <option value="In Queue">In Queue</option>
    <option value="Working on">Working on</option>
    <option value="Awaiting Parts">Awaiting Parts</option>
    <option value="Ready for Collection/Delivery">Ready for Collection/Delivery</option>
    <option value="Complete">Complete</option>
    <option value="Unable To Repair">Unable To Repair</option>
    </select>
    Where exactly are you applying any PHP logic to set the option value?
  5. I still think this is a naming issue with being able to relate a checkbox to a text box.

     

    Consider this. I created a form that asks for a Name, Age and has a checkbox on whether that person should be validated. I supplied four names, four ages and clicked validate on two of the names. With the below dump of the $_POST data, can you tell me what two names I checked?

     

    array(3) {
      ["name"]=>
      array(4) {
        [0]=>
        string(4) "John"
        [1]=>
        string(5) "Roger"
        [2]=>
        string(7) "Rebecca"
        [3]=>
        string(5) "Bobby"
      }
      ["age"]=>
      array(4) {
        [0]=>
        string(2) "29"
        [1]=>
        string(2) "33"
        [2]=>
        string(2) "65"
        [3]=>
        string(2) "12"
      }
      ["validate"]=>
      array(2) {
        [0]=>
        string(3) "Yes"
        [1]=>
        string(3) "Yes"
      }
    }
    Hint, it wasn't John and Roger.

     

    Now... consider this method. Instead of just naming the form elements name[], age[] and validate[], I instead use the following code:

    for($i = 0; $i < 4; $i++) {
    ?>
    	<p>Person #<?=$i?></p>
    	<p>Enter Name: <input type="text" name="name[<?=$i?>]" value="" /></p>
    	<p>Enter Age: <input type="text" name="age[<?=$i?>]" value="" /></p>
    	<p>Validate: <input type="checkbox" name="validate[<?=$i?>]" value="Yes" /></p>
    	<hr>
    <?php
    }
    Now that produces a form like this:

    <p>Person #0</p>
    <p>Enter Name: <input type="text" name="name[0]" value="" /></p>
    <p>Enter Age: <input type="text" name="age[0]" value="" /></p>
    <p>Validate: <input type="checkbox" name="validate[0]" value="Yes" /></p>
    Where $i keeps getting put in the [] for each element. So I have name[0], name[1], name[2] and name[3], along with the same for age[] and validate[]. Now when I submit the form with the same data and same boxes checked as before, can you tell which two names I checked to validate?

    array(3) {
      ["name"]=>
      array(4) {
        [0]=>
        string(4) "John"
        [1]=>
        string(5) "Roger"
        [2]=>
        string(7) "Rebecca"
        [3]=>
        string(5) "Bobby"
      }
      ["age"]=>
      array(4) {
        [0]=>
        string(2) "29"
        [1]=>
        string(2) "33"
        [2]=>
        string(2) "65"
        [3]=>
        string(2) "12"
      }
      ["validate"]=>
      array(2) {
        [0]=>
        string(3) "Yes"
        [2]=>
        string(3) "Yes"
      }
    }
    
  6. $catCategory = "INSERT INTO category_assoc (prod_id, cat_id, p_order)

    VALUES('$lastID', '". $together[$i]."','". $together['p_order'] . "')";

    $together['p_order'] doesn't make any sense, notwithstanding that there's no p_order element in your form, as mentioned.

     

    Can you post a var_dump() of $_REQUEST once you've submitted this form, with some boxes checked and others not checked? An actual copy/paste of the generated HTML form would be helpful, too.

  7. You're including date and time, down to the second, in the string to hash. So the hashes will only be calculated the same on the same second. Assuming wherever you post this form to does the same hash, it'd also have to do so within the same exact second to get a matching value.

  8. The only "value" from the button is the text that's displayed on it. Why would you need that?

     

    If $_POST['search'] is set (check using isset(), as shown), then the form has been submitted, i.e. the button has been clicked.

     

    The click process causes the page to reload and set the $_POST['search'] and $_POST["product_category"] values. The $_POST["product_category"] value is the option that was chosen in the select, before the button was clicked.

     

    So taking your code where you create the <select> and button, you'd need to add some PHP code to process those values once the button is clicked (submitting the form).

     

        <?php
        include 'dbconn.php';
        ?>
    
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Register</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="java.js"></script>
    </head>
    <body>
        <div class="headerBar">
            TOP
        </div>
        <div class="sideBar">
                <?php require 'productCatagory.php' ?>
        </div>
        <div class="mainArea">
            <form action="" method="post">
    <p>Select category: <select name="category">
    
    <?php
    
    
    $sql = "SELECT DISTINCT(product_catagory) FROM `products`";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $pro_cat = $row["product_catagory"];
    
    echo <<< "EOT"
    <option value="$pro_cat">$pro_cat</option>
    EOT
    ;
    }
    } else {
    echo <<< "EOT"
    <option value="None_Found">No Products Found</option>
    EOT
    ;
    }
    // $conn->close();
    
    
    
    ?>
    </select> <button type="submit" name="search">Search</button></p>
    </form>
    
    <?php
    //Assuming it's okay to show the results of clicking the button here?
    if(isset($_POST['search'])) {
    
      $stmt = $this->conn->prepare("SELECT * FROM products WHERE product_category=?");
      $stmt->bind_param("s", $_POST["product_category"]);
      $stmt->execute();
      $result = $stmt->get_result();   
      if($result->num_rows => 1) {    
        echo 'Results: ';
        while ($data = $result->fetch_assoc()) {
          // your echo goes here, showing whatever you want from the database query
      } else {
        echo 'No results found';
      }
    }
    
    ?>
    
            <div class="buttonArea">
                <?php require 'productButtons.php' ?>
            </div>
            <div class="itemArea">
                <div class="itemisedArea">
                    <textarea class="FormElement" name="term" id="term" style="width: 98%; height: 100%;"></textarea>
                </div>
                <div class="keypadArea">
                </div>
            </div>
        </div>
    </body>
    </html>
    
    Watch your spelling on category (vs catagory), by the way.

     

    I think the flow Req. is taking you through, btw, is to get the basic functionality working with vanilla HTML and PHP. Then you can start moving parts of this to specific PHP scripts that can receive and send data via AJAX calls. Then you'll have to move into JavaScript to receive the data and modify the page to show the results.

    • Like 1
  9. I don't think that's what you want.

     

    Walk me through the sequence here. When I check "USA Guitars" which as a category of "3", you also want to know that the orderp value relating to USA Guitars/category 3 is "2", right?

     

    And when you build your query, you want to know that category 3 has an orderp value of 2, right?

     

    If you used your above code, and checked the second checkbox for "Guitars" category "1", you'd have the following two arrays in $_POST or $_REQUEST:

     

    ['prodCategories'] = array(3=>'3')

    ['orderp'] = array(2=>'2', 5=>'5')

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