Jump to content

Adamhumbug

Members
  • Posts

    581
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. In my application, i want to be able to create web portals that can be accessed from the internet - the user will need permission to get to the portal and will need to log in. In order to achieve this i think i need to create a folder in my file structure dynamically. So for example, you name the website "portal1" click "make new website" and a folder called "portal1" is ceated in the file structure and several files dropped into it. Is this possible and if so how would i go about it - or as always, is there another way i should be dealing with this?
  2. $("#newZones").submit(function(ev) { ev.preventDefault() let fdata = $(this).serialize() + "&ajax=addNewZones"; $.ajax({ type: 'post', data: fdata, success: function(resp) { console.log(resp); $('.alert-container').html(resp).show() // if (resp == "User Created") { // $(':input', '#createNewUser') // .not(':button, :submit, :reset, :hidden') // .val('') // .prop('checked', false) // .prop('selected', false); // } } }) }) function addNewZones($pdo) { $sql = "INSERT INTO zones (name, print_value, event_site_attachment_id, zone_type_attachment_id) values (:name, :printVal, :siteId, :zTypeId)"; $stmt = $pdo->prepare($sql); echo "<pre>"; var_dump($_POST); echo "</pre>"; } This is now showing what looks like the right output array(4) { ["zoneType"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } ["zoneName"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "3" } ["printValue"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } ["ajax"]=> string(11) "addNewZones" } How does one go about looping through this array to insert it into the DB but only when a zone name is present.
  3. is that becuase my code is "wrong" - should i be switching to your way that works or is there another way around.
  4. in the function to insert the data function addNewZones($pdo, $zoneArr){ foreach ($zoneArr as $k => $v) { } } is throwing : foreach() argument must be of type array|object, string given
  5. This seems to suggest that i have got it how i need it - i think function addNewZones($pdo, $zoneArr) { $params = array(); parse_str($zoneArr, $params); echo ("<pre>"); var_dump($params); echo "</pre>"; } array(3) { ["zoneType"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" } ["zoneName"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "3" [2]=> string(1) "5" } ["printValue"]=> array(3) { [0]=> string(1) "2" [1]=> string(1) "4" [2]=> string(1) "6" } }
  6. Thanks for this. I will certainly have a look at <template> and great tip on the lables.
  7. Amazing, i have modified your code a little so that it fits with how i have done everything else (and i can understand it in the future) $("#newZones").submit(function(ev) { ev.preventDefault() let fdata = $(this).serialize() console.log(fdata) $.ajax({ type: 'post', data: { 'ajax': 'addNewZones', 'data': fdata, }, success: function(resp) { $('.alert-container').html(resp).show() } }) }) and if (isset($_POST['ajax'])) { switch ($_POST['ajax']) { case 'addNewZones': exit(addNewZones($pdo, $_POST['data'])); break; } } Once the data has been sent into PHP function. Do i need to unserialise it to insert it? Also, if the zone name field is blank the whole row of 3 fields need to be removed from the array that is sent. Would this be a filter?
  8. Landed here: Seems to be working but i dont know if there is a more optimal way of doing this. Feels a bit like a hack. $('#addZonesButton').on('click', function() { $zNameArr = [] $zPrintArr = [] $zTypeArr = [] $data = []; $('.zoneType').each(function() { $zType = $(this).val() $zTypeArr.push($zType) }) $('.zoneName').each(function() { $zName = $(this).val() $zNameArr.push($zName) }) $('.printValue').each(function() { $pVal = $(this).val() $zPrintArr.push($pVal) }) for (i = 0; i < $zNameArr.length; i++) { $data[i] = Array($zTypeArr[i], $zNameArr[i], $zPrintArr[i]); } $filteredData = $data.filter(function(x) { /* here, x is an array, not an object */ return !(x.some(element => element === (undefined || null || ''))) }); }) The data is output as: [ [ "1", "1", "p1" ], [ "1", "3", "p3" ], [ "1", "2", "p2" ] ] Would have preferred this to have keys also. Now i need to send it to php with ajax and insert it.
  9. I am not sure if this is getting me closer or further away. $('#addZonesButton').on('click', function() { $zNameArr = [] $zPrintArr = [] $('.zoneType').each(function() { $zType = $(this).val() }) $('.zoneName').each(function() { $zName = $(this).val() $zNameArr.push($zName) }) $('.printValue').each(function() { $pVal = $(this).val() $zPrintArr.push($pVal) }) })
  10. I seem to be collecting the data with the following $('#addZonesButton').on('click', function() { $zTypes = $('.zoneType').each(function() { $zType = $(this).val() console.log($zType); }) }) but how would i then create the array needed in order to post it
  11. Hi All, I have a form that allows the user to provide data in input boxes) I have a button that allows the user to add more rows (the same as row 1 repeated) I am using Ajax to post this form but my question is, how do i build the array in jquery of all of the inputs that will then be posted to PHP to insert into the database. The form looks like this: <div class="row mb-3 zone-row"> <div class="col"> <label for="zoneType" class="form-label">Zone Type</label> <select id="zoneType" class="form-select zoneType"> <option value="1">Normal Zone</option><option value="2">Special Zone</option> </select> </div> <div class="col"> <label for="zoneName" class="form-label">Zone Name</label> <input type="text" class="form-control simple-string zoneName" id="zoneName"> </div> <div class="col"> <label for="printValue" class="form-label">Print Value</label> <input type="text" class="form-control simple-string printValue" id="printValue"> </div> </div> when clicking the button to add another row - it adds: <div class="row mb-3 extra-row"> <div class="col"> <select id="" class="form-select zoneType"> <option value="1">Normal Zone</option> <option value="2">Special Zone</option> </select> </div> <div class="col"> <input type="text" class="form-control simple-string zoneName" id=""> </div> <div class="col"> <input type="text" class="form-control simple-string printValue" id=""> </div> </div> i expect that this will need to be some sort of each function?
  12. This is a a really great answer and i appreciate it. Again, alot of this is very new to me and there will be a lot of research required. I think the s3 option could be a good one for me as i plan to host on AWS. You have also raised a lot of very good points that i am yet to look into. When, would you suggest in the application build do you start testing load. I am pretty early in the process at the minute but as i have never load tested an application before, i wonder when would be the best time to start?
  13. Thanks for this - the simple answer is that i have learned a language (learning) and i am yet to have any expereience of the concepts that you are describing. I havnt yet explored the world of OOP and clearly this is something that i will need to have a look into. I havnt used any frameworks at all. I think this is going to need to be something that i explore to help me move from very amateur. I appreciate your comments and i will certainly look at adding frameworks to the reading list while i try to "master" the basics.
  14. Thank you all for the explanation. I am learning and many of the concepts in discussion are new to me so takes a while for me to properly understand. I appreciate your patience while i learn.
  15. Thank you for this. You will be happy to know that i am now using the function($pdo, $var, $var) way of working. Should probably have included in the previous post. Single function - got it.
  16. So i could have a set of functions that get a single piece of data: getFirstName($id) getLastName($id) getEmail($id) getDietary($id) getX($id) and a function that calls these singles and builds the view: getUserInfo($id){ getFirstName($id) getLastName($id) getEmail($id) getDietary($id) getX($id) } or i could just getAllUserData() and just send one query to the database.
  17. This is what i thought and hoped the answer would be and is the approach that i am taking. Thanks for confirming that for me.
  18. So i have a user form that collects: First Name Last Name Email Dietry Requirements Gender X Y Z When pulling up this user information i could create one function getAllUserData() that gets all the user data from the DB and builds the display. But later i will need to get the users name - which would be its own function or maybe the email address that would be its own function. The question is, if i know that i am going to have a function that pulls the users name and a function that pulls the users email address, do i bother with a function that pulls all the user data in one - or would just pulling individual fields in their own function be a better option. The database connection comment was more about each function having to establish a connection and send a query to the database - it could be 10 or more queries to get all of the data that i need for the user rather than just one. I am just trying to weigh up benefits of each approach and wondered what may be concidered standard. I have always pulled all the data that i need in one function and if there is a case where i need slightly different data, i just make another function.
  19. Thanks for this - there are likely going to be 10's of thousands of users. Does this make the database approach more favourable. I actually dont want the general internet to be able to see the images, they are used for ID purposes.
  20. Hi All, I have an application with users - users need to have a photo stored on their account. In the past i have literally saved the image in a folder on the server but i wondering what the best, most efficient, most secure, most space saving method would be to deal with user pictures. Any suggestions here would be welcome. Thanks
  21. Hi All, I am building an application that has users. My questions is, when showing the user information, would it be better to have a seperate function for every item that i want to retrieve (first name, last name, email address) or should i just have a function that builds the whole data set and gets all the fields that i need in one go. I am thinking about not duplicating my work as i will need to get the users name in other places and will need to get their email in other places. Is it is a good idea to have a function to get each piece of data one by one or is this overkill? I will need 10 functions to run and 10 database connections just to show basic user info.
  22. Hi All, I have a page that lists users - clicking a user will take you to a page where you edit the user. I know that i can use get to pass the users ID from page A to page B but i am trying to avoid users being able to hijack the URL and navigate around like that. I am trying to make sure that i prevent people seing what they shouldnt with permissions and sessions but i wanted to enquire if there was a better way to get around rather than get. I have read that sessions could be an option but how would i set the session on a button click when i would need JS for the button click and PHP to set the session. Would this be an AJAX job calling a php function. Any suggestions on the best way would be appreciated.
  23. OK, will give that a try. Is this how i should be structuring all of my queries to interact with the database? I have never used try / catch / throw
×
×
  • 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.