Jump to content

MartynLearnsPHP

Members
  • Posts

    56
  • Joined

  • Last visited

MartynLearnsPHP's Achievements

Member

Member (2/5)

0

Reputation

  1. I don't get what's hard to follow. All there is here is a form and the code to process the form.
  2. Thanks, ginerjm. I've shared too much unnecessary code. I hope this simplifies things. $q has been acquired from a previous form to determine which project we are updating permissions for (ie. budgets, epenses, invites, transport, etc). So I GET $q to determine which project we are updating. With this project selected, the user gets a list of the Members within the project in order to update whether they have permission to view this project. If I am just looking at the budget project, the relevant part of this form is below: <?php require 'core/init.php'; $adminid = $user->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); echo "<form action='permissionupdate.php' method='post'>"; if ($q==="budget") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='budget[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } echo "<input type='submit' value='Update' name='project-update'> </form>"; } This form is then processed with the following php code: if (is_array($_POST['project-update'])){ if(is_array($_POST['id'])) { foreach ($_POST['id'] as $index => $id){ if(Token::check(Input::get('token'))) { $db = DB::getInstance(); if(is_array($_POST['budget'])) { $sql = "UPDATE `members` SET `" . $_POST['budget'][$index] . " WHERE `id`='" . $id . "'"; $memberUpdate = $db->query($sql); } ////Similar code for expense, invites, etc would be here in case Get_$ had been those values//// } } Redirect::to('permissionupdate.php'); } } } I hope I've made things a bit clearer.
  3. Hi. Whilst I keep ploughing through the internet in search of tutorials/examples, can anyone see an obvious flaw in my coding because this is the first time that I have tried to do this and it's doing my noggin' in. In essence, I am trying to create a form where an Admin User, once logged in, will get a list of all the projects associated to the event that they are organising (ie. budgets, expenses, table plan, food, drink, etc.). Once they have selected the project they will get a list of all their attendees/members with a view of which members have been granted permission to contribute to this project and, with checkboxes, edit the list of members by authorising or withdrawing project permissions. My current coding is: The Form to Select the Project (which works just fine) is:: <h3>Update Project Permissions</h3> <form action="" method="post" class="form-horizontal wb-form wb-new-reg"> <fieldset> <h6>Please select a Project</h6> <select name="projectmembers" onChange="showGlobalProject(this.value)"> <option value="">Select a Project</option> <option value="budget">Managing Budgets</option> <option value="expense">Managing Expenses</option> <option value="invites">Guest Invites</option> <option value="transport">Transport</option> <option value="food">Food</option> <option value="drink">Drink</option> <option value="tableplan">Table Plan</option> <option value="entertainment">Entertainment</option> <option value="other">Any Other Items</option> </select> </form> <script src="js/globalprojects.js"></script> <div id="txtGlobalProjects"></div> The Form which is then displayed (based on the above Project Selection Form and where $q represents the selected project is: <?php require 'core/init.php'; $adminid = $user->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); echo "<form action='permissionupdate.php' method='post'>"; if ($q==="budget") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='budget[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="expense") { <h6>Managing Expenses</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='expense[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="invites") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='invites[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="transport") { <h6>Transport</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='transport[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="food") { <h6>Food</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='food[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="drink") { <h6>Drink</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='drink[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="tableplan") { <h6>Table Plan</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='tableplan[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="entertainment") { <h6>Entertainment</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='entertainment[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="other") { <h6>Any Other Items</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='other[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } echo "<input type='submit' value='Update' name='project-update'> </form>"; } And my php to process the form (which I guess is where my issue is, is: if (is_array($_POST['project-update'])){ if(is_array($_POST['id'])) { foreach ($_POST['id'] as $index => $id){ if(Token::check(Input::get('token'))) { $db = DB::getInstance(); if(is_array($_POST['budget'])) { $sql = "UPDATE `members` SET `" . $_POST['budget'][$index] . " WHERE `id`='" . $id . "'"; $memberUpdate = $db->query($sql); } if(is_array($_POST['expense'])) { $sql = "UPDATE `members` SET `expense`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['expense'][$index],$id)); } if(is_array($_POST['invites'])) { $sql = "UPDATE `members` SET `invites`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['invites'][$index],$id)); } if(is_array($_POST['transport'])) { $sql = "UPDATE `members` SET `transport`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['transport'][$index],$id)); } if(is_array($_POST['food'])) { $sql = "UPDATE `members` SET `food`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['food'][$index],$id)); } if(is_array($_POST['drink'])) { $sql = "UPDATE `members` SET `drink`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['drink'][$index],$id)); } if(is_array($_POST['tableplan'])) { $sql = "UPDATE `members` SET `tableplan`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['tableplan'][$index],$id)); } if(is_array($_POST['entertainment'])) { $sql = "UPDATE `members` SET `entertainment`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['entertainment'][$index],$id)); } if(is_array($_POST['other'])) { $sql = "UPDATE `members` SET `other`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['other'][$index],$id)); } } Redirect::to('permissionupdate.php'); } } } I appreciate that I can cut down a lot of code on the 2nd bit above, but I thought I'd focus on trying to get it to work before doing that. Any help on spotting an obvious mistake or drawing my attention to the bit of code that I should be focusing on would be very much appreciated.
  4. Aha! I've found it! I knew it was going to be a schoolboy error but it's taken me about 3 weeks to find it! I've used normal apostrophes for the SET adminid instead of using the backward tick.
  5. Sorry. The html/php flipping is just cutting the form down to the relevant elements to post here. Using Psycho's debugging code (sligthty adapted to suit my form as follows: if (!empty($_POST['position-guests'])) { if(!Input::exists()) { echo "Error: Input does not exist."; } else { if(!Token::check(Input::get('token'))) { echo "Error: Token check failed."; } else { $db = DB::getInstance(); $sql = "UPDATE `guests` SET `admin` = ?, 'adminid' = ?, `tableposition` = ?, `seat` = ? WHERE `id` = ?"; $guestUpdate = $db->query($sql, array( $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] )); if(!$guestUpdate) { echo "Error: Guest update failed."; } else { Redirect::to('membertableguests.php'); } } } } else { echo "Error: No POST data provided"; } It appears that my form just isn't submitting because I am getting the following: "Error: No POST data provided validate" I'm completely at a loss as to why the form isn't submitting the information. If I echo out $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] it does give me the right information that was submitted in the form.
  6. Hi. I am trying to write an "update" form and I'm sure that I have done it correctly, but it's just not working. I've spent days staring at the code and trying to tweak it. Can anyone else see what I have missed? The form is: <form action='membertableguests.php' method='post'> <input type='hidden' name='admin' value='{$admin}'> <input type='hidden' name='adminid' value='{$adminid}'> <input type='hidden' name='tableposition1' value='{$q}'> <input type='hidden' name='seat1' value='1'> <input type='hidden' name='token' value='" .Token::generate(). "'> <input type='submit' value='Submit Seating Update' name='position-guests'> <select name='id1'> <option value=''>-Please Select a Guest-</option>"; $guest = "SELECT id, firstname, lastname FROM guests WHERE adminid='{$adminid}' && invite='Yes' && attend!='No' ORDER BY lastname, firstname"; $guestquery = DB::getInstance()->query($guest); foreach ($guestquery->results() as $guestresults) { echo "<option value='" . $guestresults->id . "'>" . $guestresults->firstname . " " . $guestresults->lastname . "</option>"; } </select> </form> And the Update php code is: if (!empty($_POST['position-guests'])) { if(Input::exists()) { if(Token::check(Input::get('token'))) { $db = DB::getInstance(); $sql = "UPDATE `guests` SET `admin` = ?, 'adminid' = ?, `tableposition` = ?, `seat` = ? WHERE `id` = ? "; $guestUpdate = $db->query($sql, array( $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] )); Redirect::to('membertableguests.php'); } } } I've tried echoing out $admin, $adminid and $q and they are all correct. I'm simply asking here if anyone can spot an obvious mistake or typo that I have made in my code.
  7. Thanks, Ch0cu3r. That's opened my eyes. When I was previously echoing $q it was showing the table position, which is what I wanted, but but dumping the results it is showing results from my table database rather than my guests database so I can see that the problem is coming from the AJAX GET transfer of data which means that I now know where to start looking to try and resolve my issue. An analogy that I once heard and quite liked. "I now have a torch and know where to shine it rather than trying to fumble around in the dark."
  8. Sorry. I misunderstood your post. I thought you were suggesting an alternative line. I'll come back to that later then and first try to work out why $q isn't being recognised in my select query.
  9. OK. I'm just trying to break this all down so that I can rebuild from the bottom up. But one quick question. What reason could there be for... $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { if ($q=="positiontop1") { $seats=$seatresults->seattop1; } else { if ($q=="positiontop2") { $seats=$seatresults->seattop2; } else { if ($q=="positiontop3") { $seats=$seatresults->seattop3; } else { if ($q=="positiontop4") { $seats=$seatresults->seattop4; } else { if ($q=="position1") { $seats=$seatresults->seat1; } else { if ($q=="position2") { $seats=$seatresults->seat2; } else { if ($q=="position3") { $seats=$seatresults->seat3; } else { if ($q=="position4") { $seats=$seatresults->seat4; } else { if ($q=="position5") { $seats=$seatresults->seat5; } else { if ($q=="position6") { $seats=$seatresults->seat6; } else { if ($q=="position7") { $seats=$seatresults->seat7; } else { if ($q=="position8") { $seats=$seatresults->seat8; } else { if ($q=="position9") { $seats=$seatresults->seat9; } else { if ($q=="position10") { $seats=$seatresults->seat10; }}}}}}}}}}}}}}}}} outputing an answer whereas $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { $seats=$seatresults->seat[$q]; } does not?
  10. There is only ever one row per adminid. I think my database is fairly simple in it's design. In the guests database which I am trying to select from the columns are simply: id firstname lastname admin adminid table seat So I am just trying to select from the table where the adminid = that one row and the table = the selected table. My previous query was on a much more complicated private messaging system which is why that got over complicated - but as far as I can see this one should be quite straight forward - if only I could understand why $q isn't being recognised as a search option.
  11. Thanks for the input Ch0cu3r and Barand. You've unearthed a problem that I hadn't yet encountered with the '==' issue. And I can see the benefit of using an array and that is something that I will definitely come back to and address, although I will need to go back and amend my database first because I have tried to simplify my code above by reducing it so that it is not unnecessrily long. Not all tables are called position1, position2, position3, etc (ie. there are 4 top table options and some side tables which I will need to rename for database purposes before I can use the array). EDIT: It occurred to me that I could implement Barand's suggestion as top tables are just positiontop1, positiontop2, etc and so the option codes could be top1, top2, etc so it would still apply. However after implementing that it is no longer working and giving me the number of seats allocated to a table. However, my primary issue at the moment is using $q to select from my guests database. That code just isn't recognising the table='$q' in: $seatedguests = DB::getInstance()->query("SELECT * FROM guests WHERE adminid='{$adminid}' && table='$q'");
  12. I am currently trying to write a page for people to log on and allocate guests to seats for their event. I am working on 3 files. The main page whereby they select the table that they want to allocate guests to, a js file and a php file which takes the selected table and allows the information to be managed. My main select a table page is set up so that the user only views the tables that they have chosen to use for their event and shows the name or number that they have allocated to that table. <form action="" method="post"> <label>Select Table</label> <select name="table guest" onChange="showUser(this.value)"> <option value="">-Please Select-</option> <?php $selectguest = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid='{$adminid}' && admin='{$admin}'"); foreach ($selectguest->results() as $selectguestresults) if ($selectguestresults->position1=="1") {echo "<option value ='position1'>" . $selectguestresults->name1 . "</option>";} if ($selectguestresults->position2=="1") {echo "<option value ='position2'>" . $selectguestresults->name2 . "</option>";} if ($selectguestresults->position3=="1") {echo "<option value ='position3'>" . $selectguestresults->name3 . "</option>";} if ($selectguestresults->position4=="1") {echo "<option value ='position4'>" . $selectguestresults->name4 . "</option>";} if ($selectguestresults->position5=="1") {echo "<option value ='position5'>" . $selectguestresults->name5 . "</option>";} if ($selectguestresults->position6=="1") {echo "<option value ='position6'>" . $selectguestresults->name6 . "</option>";} if ($selectguestresults->position7=="1") {echo "<option value ='position7'>" . $selectguestresults->name7 . "</option>";} if ($selectguestresults->position8=="1") {echo "<option value ='position8'>" . $selectguestresults->name8 . "</option>";} if ($selectguestresults->position9=="1") {echo "<option value ='position9'>" . $selectguestresults->name9 . "</option>";} if ($selectguestresults->position10=="1") {echo "<option value ='position10'>" . $selectguestresults->name10 . "</option>";} if ($selectguestresults->position11=="1") {echo "<option value ='position11'>" . $selectguestresults->name11 . "</option>";} if ($selectguestresults->position12=="1") {echo "<option value ='position12'>" . $selectguestresults->name12 . "</option>";} ?> </SELECT> </form> <script src="js/allocatetables.js"></script> <div id="txtALLOCATE"></div> My js file is: function showUser(str) { if (str=="") { document.getElementById("txtALLOCATE").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtALLOCATE").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","allocatetables.php?q="+str,true); xmlhttp.send(); } And my referenced php file is: <?php require 'core/memberinit.php'; $member = new Member(); $admin = $member->data() ->admin_username; $adminid = $member->data() ->adminid; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { if ($q="position1") {$seats=$seatresults->seat1; } else { if ($q="position2") {$seats=$seatresults->seat2; } else { if ($q="position3") {$seats=$seatresults->seat3; } else { if ($q="position4") {$seats=$seatresults->seat4; } else { if ($q="position5") {$seats=$seatresults->seat5; } else { if ($q="position6") {$seats=$seatresults->seat6; } else { if ($q="position7") {$seats=$seatresults->seat7; } else { if ($q="position8") {$seats=$seatresults->seat8; } else { if ($q="position9") {$seats=$seatresults->seat9; } else { if ($q="position10") $seats=$seatresults->seat10; } else { if ($q="position11") {$seats=$seatresults->seat11; } else { if ($q="position12") {$seats=$seatresults->seat12; }}}}}}}}}}}}} $seatedguests = DB::getInstance()->query("SELECT * FROM guests WHERE adminid='{$adminid}' && table='$q'"); foreach ($seatedguests->results() as $seatedguestsresults) { echo "Guest: " . $seatedguestsresults->firstname . " " . $seatedguestsresults->lastname . " (Seat Number: " . $seatedguestsresults->seat . ")<br>"; } echo $q; echo "<br>"; echo $seats; } Obviously I have a lot more to write on my last page, but I am coming unstuck at the first hurdle. My echoed out $q is showing the correct reference (ie. position1, position2, etc) and $seats is showing the correct number of seats allocated to a table. However, my request to view guests seated at the table ($seatedguests) isn't recognising $q in the search option. I am sure this is a basic flaw in my knowledge, but I've spent nearly 2 weeks trying to get past this and I am at my wits end, so any help, prompting or suggestions on how I should be using $q to select the appropriate table would be very, very gratefully appreciated.
  13. Thanks, mac_gyver. That information is a huge help because it points me in the direction I should be going (or rather puts a big 'Road Closed' sign in the route that I was trying to follow). It's bedtime for me now, but tomorrow I will look at implementing a seperate "Select Search" where I don't group them and then cross reference originalid with the group search. If they match? Then that is the unique link that I am looking for and will hopefully give me the result that I need.
  14. Aha! I've made another small step forward. Not so much in resolving the problem, but in identifying the cause. I've tried echoing out all the results, and my code is identifying the first line in my database as the one to reference, whereas it will always be the last line that has not been read. So I need my "if" statement to select the last line in the search option. Anyone know how I can do this>
  15. OK. This is really starting to blow my mind. I have this lovely group of data that Groups all of the data into a nice column of discussions. As so: $query2 = DB::getInstance()->query("select c.id as cid, c.originalid, c.title, max(c.time) as timestamp, c.read1, c.read2, c.member1, c.member2, m.id as membersid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$memberid}' and c.removed1='No' and m.id=c.member2) or (c.member2='{$memberid}' and c.removed2='No' and m.id=c.member1)) group by c.originalid order by MAX(c.id) DESC"); foreach ($query2->results() as $result2) I then want that list to be echoed out so that a user can view the lists. And again, that is working fine. However, I want to have one argument that puts a "NEW" message next to any items on the list where the list contains one item that has ($results2->member1==$memberid && read1=='No') OR ($results2->member2 && read2=='No') within the group. But I just can't seem to get that argument working. Any suggestions?
×
×
  • 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.