Jump to content

I-AM-OBODO

Members
  • Posts

    442
  • Joined

  • Last visited

Everything posted by I-AM-OBODO

  1. I didn't. I did just as he suggested but got same result.
  2. I guess i'd have to change the way the form fields are displayed. instead of getting the subjects from the database, i guess i will just create them in a form, with this way, the validation will/should work! still beats me why it cant validate though! Thanks all
  3. Thanks. In the code proper, i did validation for the inputs. i did not include the validation while posting. some things you mention are done in the code proper but overall i learnt some interesting things from your list. thanks again
  4. Thanks. But its same behavior like mine. If nothing is inputted, the validation works but when you fill the first subject, the other empty fields will be saved as empty! I guess i'd have to change the way the form fields are displayed. instead of getting the subjects from the database, i guess i will just create them in a form, with this way, the validation will/should work!
  5. Thanks for the pointers. Will work on it.
  6. Hello all. I have worked my head out but i cant seem to figure out why i am getting error/entering empty stings. I have tried different things but none seems to work as expected. i know the problem is from the array field validation but cant seem to figure out how to get it done. If i submit without entering any field, the error works fine. But if i fill only one field, it gives error and saves empty strings. Thanks if(isset($_POST['submit'])) { $test_score = $_POST['test_score'][0]; $exam_score = $_POST['exam_score'][0]; if(empty($test_score)) { $error['test_score'] = "Test Score Field is Required"; }if(empty($exam_score)) { $error['exam_score'] = "Exam Score Field is Required"; } if(empty($error)) { foreach ($_POST['subject'] as $key => $value) { $sql = "INSERT INTO $table_name( subject, test_score, exam_score ) VALUES( :subject, :test_score, :exam_score )"; $stmt = $pdo->prepare($sql); $stmt->execute([ 'subject' => $value, 'test_score' => $_POST['test_score'][$key], 'exam_score' => $_POST['exam_score'][$key] ]); } if($stmt->rowCount()){ echo '<div class="alert alert-success text-center">Data Saved</div>'; }else{ echo '<div class="alert alert-danger text-center">Data Not Saved</div>'; } }else{ echo '<br><div class="alert alert-danger text-center">Fields Empty!</div>'; } } //my form <table class="table table-borderless"> <thead> <tr> <th>SN</th> <th>Subject</th> <th>Continuous Assesment Score</th> <th>Examination Score</th> </tr> </thead> <tbody> <div> <form action="" method="post"> <?php $i = 1; $stmt=$pdo->query(" SELECT subjects FROM tbl_subjects_secondary "); WHILE($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?> <tr> <th><?php echo $i++ ?></th> <td><input type="text" name="subject[]" class="form-control border-0" readonly value="<?php if(isset($row['subject_name'])) { echo $row['subject_name']; } ?>"></td> <td><input type="number" name="test_score[]" class="form-control"><span style="color: red; font-size: .8em;"><?php if(isset($error['test_score'])){ echo $error['test_score'];} ?></span></td> <td><input type="number" name="exam_score[]" class="form-control"><span style="color: red; font-size: .8em;"><?php if(isset($error['exam_score'])){ echo $error['exam_score'];} ?></span></td> </tr> <?php } ?> <tr> <td></td><td></td> <td colspan="2"><button type="submit" name="save" class="btn btn-primary w-50">Save</button></td> </tr> </form> </div> </tbody> </table>
  7. Oops! In reverse! Thank you so much
  8. How can it be read from bottom, that is 2027-2028 be at the top? What is order by alternative in php
  9. I found a way around to get it done as well. $startYear = 2020; $endYear = 2024; for($year = $startYear; $year <= $endYear; $year++){ $nextYear = $year + 1; echo "<option value='$year-$nextYear'>$year-$nextYear</option>"; }
  10. Hi all I am trying to create something like 2023-2024 in a loop so that each year it generate the session for me. I don't want to manually add it. What I did did not work (though I know it won't work but just did it anyway) $cur_yr = date('Y'); $nxt_yr = date('Y', strtotime('+1 year,); $cur_session = $cur_yr."-".$nxt_yr; $strt_session = "2020-2021"; for($i = $strt_session; $i<= $cur_session; $i++){ echo $i; } Mine won't work. But how can I get it done. Thanks in anticipation
  11. I agree with you. Some fields are redundant. I will definitely remove the redundant fields. Thanks
  12. What I am trying to say and mean is that I do not want the form input field to show. Even when I used css to make the input field less visible, it still shows. It gives it an aesthetic that I don't like which is why I used table and make the input fields hidden. Thanks
  13. Thank you so very much
  14. Thank you. Oversight! I later noticed it as well. Thank you so much 💓
  15. No other reason. Its just so the value be available for the form. I don't want the table to tags to have form input inside them cos it will make it not look nice. How would you approach it? Thanks
  16. Thanks for the pointer. Now it only applies for the bottom checkbox regardless of the number of checkbox ticked. <td><input type='checkbox' name='check_list[$prod_id]' value='<?= $prod_id ?>' ></td> <input type='text' name='prod_id[$prod_id]' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[$prod_id]' value='<?= $cost_price ?>' hidden> <input type='text' name='prod_name[$prod_id]' value='<?= $prod_name ?>' hidden> <input type='text' name='size_type[$prod_id]' value='<?= $size_type ?>' hidden> <input type='text' name='sold_price[$prod_id]' value='<?= $sold_price ?>' hidden> <input type='text' name='prod_qty[$prod_id]' value='<?= $prod_qty ?>' hidden> <input type='text' name='total_price[$prod_id]' value='<?= $total_price ?>' hidden> <td><?= $prod_name ?></td> <td><?= $size_type ?></td> <td><?= $prod_qty ?></td> <td><?= $sold_price ?></td> <td><?= $total_price ?></td> Array ( [prod_id] => Array ( [$prod_id] => 116154 ) [cost_price] => Array ( [$prod_id] => 200.00 ) [prod_name] => Array ( [$prod_id] => Bread ) [size_type] => Array ( [$prod_id] => By 10 ) [sold_price] => Array ( [$prod_id] => 300.00 ) [prod_qty] => Array ( [$prod_id] => 5 ) [total_price] => Array ( [$prod_id] => 1500.00 ) [check_list] => Array ( [$prod_id] => 116154 ) [delete] => ) with this, the value for bread (going by example: 5) is added to whichever checkbox is checked foreach($_POST['check_list'] as $k => $prod_id){ $update->execute( [ ':prod_id' => $prod_id, ':stock_qty' => $_POST['prod_qty'][$k] ] ); with this, the value for bread (going by example: 5) is added to only bread regardless of the checkbox checked foreach($_POST['check_list'] as $k => $prod_id){ $update->execute( [ :prod_id' => $_POST['prod_id'][$k], ':stock_qty' => $_POST['prod_qty'][$k] ] ); Thanks
  17. thanks for your reply. i dont get you
  18. Hello all, i have worked my head out with different solution but none have given me the desired result and so i have to seek help. I dont know why only the first check box is working. even when i select the last checkbox, the first checkbox will work. Thanks <?php if(isset($_POST['delete'])){ if(empty($_POST['check_list'])){ echo "<div class='bg-warning alert alert-warning text-center margin-top'>YOU DID NOT MAKE ANY SELECTION</div>"; }else{ if(!empty($_POST['check_list'])){ $update = $pdo->prepare(" UPDATE tbl_stock SET stock_qty = stock_qty + :stock_qty WHERE prod_id = :prod_id "); foreach($_POST['check_list'] as $k => $prod_ids){ // if i use $prod_id it gives a weird result // i also did ':prod_id' => $prod_id to no avail $update->execute( [ ':prod_id' => $_POST['prod_id'][$k], ':stock_qty' => $_POST['prod_qty'][$k] ] ); $cnt = $update->rowCount(); } if($cnt){ $query = " UPDATE tbl_sales SET status=2, date_deleted = NOW() WHERE trans_ref='$_SESSION[temp_trans_ref]' AND prod_id = :prod_id "; $stmt = $pdo->prepare($query); foreach($_POST['check_list'] as $k => $prod_name){ $stmt->execute([ ':prod_id' => $_POST['prod_id'][$k] ]); } echo "<div class='bg-success alert alert-success text-center text-white'>RECORD(S) DELETED</div>"; }else{ echo "<div class='bg-danger alert alert-danger text-center text-white'>RECORD NOT DELETED</div>"; } } } } ?> <form action="" method="post"> <div class="sales-form"> <?php if( isset($error_msg)){ echo $error_msg; } ?> <table class='table'> <thead> <tr> <th></th> <th>Item Name</th> <th>Product Size/Type</th> <th>Quantity</th> <th>Price (₦)</th> <th>Total (₦)</th> </tr> </thead> <tbody><tr> <?php $t_price = 0; $stmt = $pdo->query(" SELECT * FROM tbl_sales s LEFT JOIN tbl_sales_total st ON s.trans_ref = st.trans_ref LEFT JOIN tbl_products p ON s.prod_id = p.prod_id WHERE s.trans_ref = '$_SESSION[temp_trans_ref]' AND s.status = 0 "); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $prod_id = $row['prod_id']; $cost_price = $row['cost_price']; $prod_name = $row['prod_name']; $size_type = $row['size_type']; $prod_qty = $row['prod_qty']; $sold_price = $row['sold_price']; $total_price = $row['total_price']; $t_price += $row['total_price']; ?> <td><input type='checkbox' name='check_list[]' value='<?= $prod_id ?>' ></td> <input type='text' name='prod_id[]' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[]' value='<?= $cost_price ?>' hidden> <input type='text' name='prod_name[]' value='<?= $prod_name ?>' hidden> <input type='text' name='size_type[]' value='<?= $size_type ?>' hidden> <input type='text' name='sold_price[]' value='<?= $sold_price ?>' hidden> <input type='text' name='prod_qty[]' value='<?= $prod_qty ?>' hidden> <input type='text' name='total_price[]' value='<?= $total_price ?>' hidden> <td><?= $prod_name ?></td> <td><?= $size_type ?></td> <td><?= $prod_qty ?></td> <td><?= $sold_price ?></td> <td><?= $total_price ?></td> </tr> <?php } ?>
  19. Thanks for the pointer.
  20. Yes I know my syntax is the problem. How can I get the right syntax to use? I have already called the CreateProduct controller but the right syntax to use to get the category is where I am having problem Thanks
  21. Yes. It's Laravel. I can get this list in the CategoryController but if I try to get it from the create page which happens to be on ProductCategory I couldn't, cos obviously the category is not defined in in the ProductController. Basically what i want to achieve is select a category while filling the product form
  22. Hi all. I have two tables. categories and products. On the create product page, I have a select dropdown field that I want to populate all the available categories. How can I archive that? This is what I did but I am having error: MY FORM <form> <select name="cat_name" > <option value="">Select One</option> @foreach($categories as $category) <option value="{{ $category->cat_name}}"> {{ $category->cat_name}} </option> @endforeach </form> MY CONTROLLER use App\Http\Controllers\ProductController; use App\Http\Controllers\CategoryController; public function create() { return view('products.create', [ $result = (new CategoryController)->Category() ]); } } Thanks
  23. Hi, I am trying to get this bootstrap modal to run on page load. It works fine on button click but i want it to run on page load thanks <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content"> <div class="modal-header"> <h1 class="modal-title fs-5" id="staticBackdropLabel">Downloading...</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="progress" style="height: 30px;"> <div id="myBar" class="progress-bar progress-bar-striped bg-success progress-bar-animated" role="progressbar" style="width: 0%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">50%</div> </div> <p id="myP" class="p-3">Downloading: <span id="demo">0</span></p> </div> <div class="modal-footer"> <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> --> <button type="button" class="btn btn-secondary" onclick="location.href='start-download'">Close</button> </div> </div> </div> </div> <script> $(window).on('load', function() { $('#staticBackdrop').modal('show'); function move() { var elem = document.getElementById("myBar"); var width = 0; var id = setInterval(frame, 50); function frame() { if (width >= 100) { clearInterval(id); document.getElementById("myP").className = "text-danger p-3 text-center"; document.getElementById("myP").innerHTML = "Successfully uploaded 10 photos!"; } else { width++; elem.style.width = width + '%'; elem.innerHTML = width * 1 + '%'; var num = width * 1 / 1; num = num.toFixed(0); document.getElementById("demo").innerHTML = num; } } } }); </script>
  24. In between, The download attribute is not supported by older browsers though
  25. The concatenation does the job. The work of concatenation(the dot) is to join. So mine as well is very ok. So whichever way you feel like, its up to you!
×
×
  • 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.