Jump to content

Adamhumbug

Members
  • Posts

    583
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. Thanks all for this - opened the door a little for me
  2. I wasnt sure where best to put this question. I have a website that i built locally using mamp, i now have this hosted with 1&1 and its working online. I am trying to continue development locally rather than playing with the live version but when i now try and navigate to it via local host i get the following error: SSL_Error_rx_record_too_long Anyone got any hints?
  3. So it was uploading the image and putting it in the correct folder. It was also adding the file name to the person table image column. None of these things are currently happening. I will have a look into that.
  4. I have a form that includes uploading a headshot. This is the form handling f ($_SERVER['REQUEST_METHOD']=='POST'){ $fn = $_POST['fname']; $ln = $_POST['lname']; $ad1 = $_POST['ad1']; $ad2 = $_POST['ad2']; $city = $_POST['city']; $post = $_POST['postcode']; $tel = $_POST['phone']; $email = $_POST['email']; $crole = $_POST['comRole']; $OFA = $_POST['OFA']; $playerType = $_POST['playerType']; $team = $_POST['primaryTeam']; $dob = $_POST['dateOfBirth']; if(!empty($_FILES['fileToUpload'])){ $errors= array(); $file_name = $_FILES['personHeadshot']['name']; $file_size =$_FILES['personHeadshot']['size']; $file_tmp =$_FILES['personHeadshot']['tmp_name']; $file_type=$_FILES['personHeadshot']['type']; $file_ext=strtolower(end(explode('.',$_FILES['personHeadshot']['name']))); $newFileName = $fn."-".$ln.".".$file_ext; $extensions= array("jpeg","jpg","png"); if(in_array($file_ext,$extensions)=== false){ $errors[]="extension not allowed, please choose a JPEG or PNG file."; } if($file_size > 2097152){ $errors[]='File size must be smaller than 2 MB'; } if(empty($errors)==true){ move_uploaded_file($file_tmp,"img/people/".$newFileName); echo "Success"; }else{ print_r($errors); } $personHeadshot = $newFileName; } $stmt = $conn->prepare(" INSERT IGNORE INTO person (fname, lname, committee_role_id, player_type_id, team_id, ad1, ad2, city, postcode, mobile, email, on_field_auth_id, image, dob) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param('ssiiissssssiss', $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA, $personHeadshot, $dob); $stmt -> execute(); header("location: admin-people-list.php"); } I also have this file <?php $target_dir = "img/people/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?> This was working locally but now i have uploaded it i cannot get it to work. All of the person data gets put into the DB asside from the file name I appreciate you may need more info to help me which i will provide on request
  5. I think the issue is that the values going into the array are strings not integers. I used this to solve my problem function existingTags(){ var plta = $('#peopleLinkedToArticle').val() plta = plta.split(',') taggedPeople = plta for (a in taggedPeople ) { taggedPeople[a] = parseInt(taggedPeople[a], 10); } console.log(taggedPeople) }
  6. Hi All, I have a function: function existingTags(){ var plta = $('#peopleLinkedToArticle').val() window.taggedPeople = [plta] console.log(taggedPeople) } This console log shows the following which is correct. Array [ "11,2" ] I have a second function that needs to use tagged people function removeTaggedPeople(){ console.log(taggedPeople) var e = event.target $(e).attr('onclick','tagInArticle()') var taggedPerson = $(e).data('id') var i = 0; while (i < window.taggedPeople.length) { if (window.taggedPeople[i] === taggedPerson) { window.taggedPeople.splice(i, 1); } else { ++i; } } console.log(window.taggedPeople) var tp = window.taggedPeople.toString() $('#peopleLinkedToArticle').val(tp) $(e).remove() } The first console log in the second function which runs on a button click also shows Array [ "11,2" ] Ids are not being removed from this array and i cannot figure out why
  7. That works sometimes, if it looking to remove 1, it will also remove one of the 1's from 11,
  8. Hi All, I have a number of buttons that when clicked, add their id to a hidden input with a comma. I would like the ability to click another button and remove its id from this input. I have the following that works well function removeTaggedPeople(){ var e = event.target var tagButton = $(e); $(e).attr('onclick','tagInArticle()') var taggedPerson = $(e).data('id') var orig = $('#peopleLinkedToArticle').val() var t = new RegExp(taggedPerson, 'g') var newval = orig.replace(t,'') $('#peopleLinkedToArticle').val(newval) $(e).remove() } The issue is that if i have the id "1" and the id "11" in the input and i click the button with id "1" it will remove every instance of the number 1 in the string. I would like it to only remove "1" Im not sure if you need a little more to go on here but thats my predicament. Thanks in advance
  9. i went this route in the end and didnt bother with data attributes. function getMoreNews(limit, offset){ $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger mb-3' onclick='getMoreNews(1,"+offset+");' data-limit='1' data-offset="+offset+">-- Load More News --</div>") } }) };
  10. Hi All, I have a function that pulls data in php form my db and uses a limit and an offset. This is currently called like this <?=getAllNews(0,1)?> with 0 being the offset and 1 being the limit. The line after this is a button triggering ajax <div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='1' data-offset='1'>-- Load More News --</div> and the ajax $('.loadMoreNewsTrigger').click(function(){ var offset = $(this).data('offset'); var limit = $(this).data('limit'); $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='limit' data-offset='$offset'>-- Load More News --</div>") } }) }); I am trying to increment the data values before appending the new button to the end but im getting tangled up. help is always appreciated
  11. The following allowed me to create an array that is seen by post $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); var taggedPerson = $(this).data('id') $('#peopleLinkedToArticle').val($('#peopleLinkedToArticle').val()+taggedPerson+',') tagButton.appendTo('#taggedInArticleContainer') $('#searchForPeopleBox').val('') $('#searchForPeopleBox').focus(); });
  12. I think i am getting pretty close. I have added a text field that i am trying to append the ids to to give me an array of linked people. Issue is, its overwriting not appending. This is jq $('#peopleLinkedToArticle').append().val(taggedPerson+',') this forms part of the selection process shown below. $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); var taggedPerson = $(this).data('id') $('#peopleLinkedToArticle').val(taggedPerson+',') tagButton.appendTo('#taggedInArticleContainer') $('#searchForPeopleBox').val('') });
  13. Hi, I have a form for news articles. It has a title and a body which is fine. I also have a search box that allows the user to search for a memeber and click their name when it appears. This moves a div with a data-id into another div. The purpose of this is to tag them in the article. I am able to post all of the simple stuff but how would i post these value. I am assuming that i would need to create an array of said values but i am struggling to get them showing in post at all. Here is the code i have so far <?php function searchForPeople($searchVal, $exclude = '0'){ $sv1 = $searchVal; $sv2 = $searchVal; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).") AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('ss', $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle' name='taggedPerson[]' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> ...... <div id="searchResultsHere"> <!-- ajax content here --> </div> <hr> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> ....... <div class="col-lg-2"> <button type="submit" name="PublishNewNews" class="btn btn-primary w-100 mb-3">Publish</button> <button class="btn btn-primary w-100">Save</button> <hr> <div class="btn btn-warning w-100 mb-3">Private</div> <input type="hidden" name="howVisible" value="Private"> <hr> <p class="text-justify">Private news articles will only be avilable to logged in users</p> </div> ....... <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = '0' var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ return $(this).data('id'); }).get(); $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script> I hope this is enough to go on. I am sure it is simple but i just cant get it. Thanks all in advance.
  14. I fixed this by using the following: WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).")
  15. I have made some changes and now have this in there to deal with the Undefined Index. I am now getting array to string conversion errors in the WHERE id != ?
  16. The sent payload of the ajax is ajax=one&val=John+Sm Nothing is mentioned about the exclude data. When i console log tagged after searchval i get a blank array
  17. Sorry its been a while. This nearly works but i get: Which is this line exit(searchForPeople($_POST['val'], $_POST['exclude'])); Here is a code dump <?php if(isset($_POST['ajax'])){ switch($_POST['ajax']) { case 'one': exit(searchForPeople($_POST['val'], $_POST['exclude'])); break; } } function searchForPeople($searchVal, $exclude = 0){ $sv1 = $searchVal; $sv2 = $searchVal; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id != ? AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('sss', $exclude, $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle$pid' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> <div id="searchResultsHere"> <!-- ajax content here --> </div> <div>Tagged</div> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ console.log(tagged) return $(this).data('id'); }).get(); console.log(searchVal) $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script>
  18. Hi, i have a search box that when searched brings back names of people in the form of a button. This is ajax. When you click a button with names on, the button gets moved with JS. I would like to be able to collect the ids of the butons that are clicked and put them back into the php function that gets them in the first place. Once they have been clicked, they shouldnt appear in the search results. Ajax and JS that moves the button $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() console.log(searchVal) $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); function tagInArticle($pid){ var tagButton = $('.tagInArticle'+$pid) tagButton.appendTo('#taggedInArticleContainer') }; My PHP function to get the results function searchForPeople($searchVal){ $sv1 = $searchVal; $sv2 = $searchVal; $ids = ''; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id != ? AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('sss', $ids, $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle$pid' onclick='tagInArticle($pid)'>$fn $ln</div>"; } return $out; }
  19. I have a function in JS that i would like to pass 2 variables to. One is an int and one is a string. I am struggling to get the string part right as it needs to be wrapped in quotes. My code is : $out.="<div onclick='newTransactionLine(".$r['id'].",".$r['direction'].")' class='transactionItem btn $class d-block mb-2' data-id='".$r['id']."' >".$r['item']."<br/>£".$r['price']."</div>"; which outputs: <div onclick="newTransactionLine(1,OUT)" class="transactionItem btn btn-primary d-block mb-2" data-id="1">Adult Membership (£85)<br>£85.00</div> When i click the button that gets made, i get a reference error on the word out. I have no doubt it is very simple but i just cannot get this to work for me.
  20. Turns out this did it moneyValues.push(parseInt(transIN[i].getAttribute('value')))
  21. I am creating an array of numbers that i would like to add together and get a sum. JS thinks that these are string and when i try and add one to another, they get appended to the end. This is the code that i have: The second console log gives me 85.00 for example. When the code runs again i end up with 85.0085.00 function financialsReCalc(){ var transIN = document.getElementsByClassName("newTransValue"); console.log(transIN); moneyValues = []; for (i = 0; i < transIN.length; i++) { moneyValues.push(transIN[i].getAttribute('value')) } var moneyvals = moneyValues.reduce(myFunc); function myFunc(total, num) { return total + num; } console.log(moneyvals) } All i am looking to do is add up the numbers in the array
  22. Yes that was the answer. Thanks so much
  23. It is dynamic - you think onClick() on the where the div is created?
×
×
  • 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.