Leaderboard


Popular Content

Showing most liked content since 04/23/2017 in all areas

  1. 1 like
    Yep. The alternative is to not list the columns in the table and only give the values: INSERT INTO table VALUES ('val1', 'val2', 'val3') But, like I said, if you ever change the structure of that table then that query is going to break if you've changed the number of columns. It's best to just list everything out explicitly. You don't have to pay per character in your source code, make the code as obvious as possible so that it's easy to maintain. Ease of maintenance should always be a higher priority than something like how long the code is.
  2. 1 like
    If you're using mysqli in PHP then you still need to write the SQL code. mysqli is just an extension for using MySQL, it's not an abstraction layer like you would get with Zend Db or something where you're building PHP method calls instead of writing SQL queries.
  3. 1 like
    I understand that an RSS feed is XML, but the links that go in that XML, the software used to create the XML, and the server security aren't related to XML. That's why I was asking why a question about directory security was in the XML forum. IIS is Internet Information Services, the Microsoft web server that runs on Windows. You didn't say what your environment was so I pointed out that URL rewriting can be done using htaccess in Apache, or another way in IIS. I assume nginx and other web servers also have a way to set up URL rewriting. Linux isn't a web server, it's an operating system, like Windows. Apache, nginx, IIS, etc are web servers. Your Linux server is probably running Apache. Yes. Like I mentioned, browsers often send partial requests for audio or video content. If you don't support that then the client will wait until the entire file finishes downloading before starting to play it. I'm not aware of a class that will do everything, when I implemented directory security and authorization through PHP I wrote that myself. Things might have changed since then. There might be something for your web server, like an Apache module, which is built to take a request and run a PHP script to handle authentication and authorization, or maybe a module that would check your database directly without going through PHP. I looked into some of those things but at the time I didn't find anything that perfectly matched what I was trying to do.
  4. 1 like
    PHP extension is required if you need to process data sent from form whose method is post or get using $_POST, $_GET, or $_REQUEST. IF its action is a link to another php page, then the form page can remain html, if it is sent to itself then the form page should be php.
  5. 1 like
    The container and image are 960px wide, the .picture class element has 5px padding, the image has no percentage sizing to make it responsive, so it remains 960px wide, the 960px image is pushed because of padding 5px to the right forcing the 960px wide image to extend beyond the boundaries of .container and .picture class elements.
  6. 1 like
    You can use indexOf() https://www.w3schools.com/jsref/jsref_indexof_array.asp to check if value already exists in array, if returned value equals -1 it could not be found, so it will be safe to push button non duplicate value into array.
  7. 1 like
    Each time you click a button you will have to loop through the panels array and compare its elements with the button's value. If the value was found then don't add it to the array. A for() loop and a boolean variable should be enough to do that.
  8. 1 like
    You should only need one function. First set up your buttons to each have a value: <button type="button" class="add-panel" data-value="4 Panel Smooth">Add 4 Panel Smooth</button><br><br> <button type="button" class="add-panel" data-value="4 Panel Grained">Add 4 Panel Grained</button><br><br> <button type="button" class="add-panel" data-value="4 Panel Grained 2 Glazed">Add 4 Panel Grained Glazed</button><br><br> Create the list that will contain the values: <ul id="demo"></ul> Set up an event listener for the buttons: var buttons = document.getElementsByClassName("add-panel"); for(var i = 0; i < buttons.length; i++) { buttons[i].addEventListener("click", addPanel, false); } Create the event handler that updates the array and displays its contents in the HTML: var panels = []; function addPanel(e) { // Get a reference to the button that was clicked var button = e.currentTarget; // Add the button's value to the array panels.push(button.getAttribute("data-value")); // Display the contents of the array on the page by generating <li> elements. var demo = document.getElementById("demo"); demo.innerHTML = ""; var li; for(var i = 0; i < panels.length; i++) { li = document.createElement("li"); li.innerHTML = panels[i]; demo.appendChild(li); } }
  9. 1 like
    Program files is a protected directory, did you open command prompt by right clicking it and selecting 'run as administrator'.
  10. 1 like
    You can probably use the manifest to list every file on your site, but that's not going to necessarily make browsing faster, it might just cause the browser to sit there and download everything the first time they visit any page. It's better to have the browser cache everything as it needs it rather than to download your whole site the first time they visit any page.
  11. 1 like
    No! the alt attribute is not useless, it may be useless for those with normal sight, but for those without sight who use a 'screen reader', or hard of hearing it is a necessity.
  12. 1 like
  13. 1 like
    Why use success and error ajax functions when you can use .done and .fail? .done and then you do all the checks in the php script even the return so that way you don't need to do that much of a javascript code in order to display an message. For example my way i use to display messages with jquery is very simple. For example index.php <div id="return_php" style="display: none;"></div> <form id="test"> <input type="text" name="something" placeholder="Insert something ..."> <input type="submit"> </form> <script> $('#test').submit(function(e){ e.preventDefault(); $.ajax({ url: 'path/to/something.php', data: $(this).serialize(), dataType: 'html', type: 'POST' }) .done(function(data){ $('#return_php').fadeIn(400).html(data).delay(5000).fadeOut(400); }) .fail(function(){ $('#return_php').fadeIn(400).html('Something went wrong with the ajax script !').delay(5000).fadeOut(400); }) }); </script> This way you just call the php page in which you do the checks and whatever stuff and then you echo an alert which will then be displayed into the return_php div. The .delay(5000) acts as a delay for the fadeOut function, after 5 seconds the message will fade away. something.php $something = $_POST['something']; if(empty($something)) { echo "Something needs to be filled in !"; //This message will be then returned into the div return_php on the index.php page } else { //Example of database try { $sql = "SELECT something FROM something WHERE something = :something"; $stmt = $db->prepare($sql); //$db is from a config file you have to include $stmt->bindParam(":something", $something); $stmt->execute(); $rowCount = $stmt->rowCount(); //This works for every case, at least i use it this way and for me works just fine. if($rowCount > 0) //let us presume that the something has more rows { echo "Ok, there is something in that something !"; } else { echo "There is nothing in something with the something you typed !"; } } catch (PDOException $e) { echo "Error: " . $e->getMesage(); //This will be showed into the return div aswell as the echo is still a part of this page, and this page is called by ajax. } } Now, this is my way to do it time to time when i need live php script calling on my page without needing my page to refresh. Hope it helped at least for your issue with displaying messages. EDIT I've read again through your post and i think i figured out what is all about. When i try to use that ereg_replace() php function is always throwing me an Uncaught error as the function doesn't exist. This may be influencing how you are selecting the data by that variable. Instead of ereg_replace use preg_replace, It does the same thing. $email = $_POST['email']; $email = preg_replace('/\s+/, '', $email); NOTE! Some of the code i wrote may or may not fit your code if you copy paste it as it doesn't contain the same variables or functions that you wrote. You may need to adapt it to your use.
  14. 1 like
    When you're printing each field you can check if the field ID exists in $non_matches, and style the element appropriately. I'm just suggesting that it is more efficient to print everything correct in the first place, versus printing everything then trying to run client-side code to show errors or whatever else.
  15. 1 like
    It really depends on the users browser setting for pdf file type, most browsers by default will use pdf browser plugin specifically for viewing in browser, but if the user changes from default to use browser plugin, to 'always ask' it will show 'download' or 'open with' which could be browser plugin or operating system Adobe reader program. Since it depends on browser settings, you can still use open pdf directly in browser php script for browsers using pdf plugin, then they will presented with alternative to 'save' or 'open with' with an alternative pdf application option. Note: the 'downloaded' part file can be called anything' even original filename, it just renames filename to 'downloaded.pdf' even if original filename was 'test.pdf'.
  16. 1 like
    The form attribute only applies to form control elements. It doesn't exist on elements like <div> or <p>. What kind of element are you referring to when you say "non-form element"? This is regarding the form attribute from the MDN page for the <input> element: When the element is a descendant of a <form> element the form attribute is not needed. If the element is not inside a <form> then the form attribute will indicate which form the element belongs to so that when the form is submitted the element's value is added to the data that is sent. I'm not certain how fieldset elements behave, I would guess that the fieldset's children would belong to the same form that the fieldset belongs to, but it can be easily confirmed with an experiment. Experiments can be done with the form attribute by submitting the form and seeing which values get sent to the server. My guess before doing experiments is that a child of one form that has a form attribute from a different form will be added as a value when either of the two forms are submitted.
  17. 1 like
    You can use scandir() to list files in a directory and generate the HTML for the images. The line breaks exist, but HTML doesn't render line breaks unless you specifically put a <br> element. You can use nl2br() to show line breaks in the text provided by users. You can't choose the size of a file, but you can give a size limit in the file uploader. There are plenty of PHP file upload tutorials, you should look at some of them. The W3Schools tutorial has sections explaining how to limit the file size and file type. You can use str_replace() to change substrings into something else, such as in the following example: <?php $string = str_replace(':)', '<img src="smiley.gif">', $string); ?>
  18. 1 like
    <?php session_start(); //start the session for the page include("../include/db.php"); //include database file include("../include/settings.php"); //include configuration file //Check if page was entered by a submit button $email=$_POST['email']; //Get username !!FROM FORM!! $email = ereg_replace(" ", "", $email); //take away all spaces from username (if any) !!FROM FORM!! $password=base64_encode($_POST['password']); //Get name !!FROMFORM!! if (empty($email) || empty($password)) { echo "Empty fields";} else{ //check to see if the username or email allready excists $ck=$flash->prepare("SELECT * FROM `user` WHERE `email`=:email AND `password`=:password "); //get rows where the username or email address is allready registered $ck->bindParam(':email',$email); $ck->bindParam(':password',$password); $ck->execute(); //if email address allready excists if($ck->rowCount() > 0){ echo "user loged in successfully"; } else{ echo "Login or password inccorect";} } ?> use that phpand keep the alert(result); it should be clear now
  19. 1 like
    var acc = document.getElementsByClassName("accordion"); for (var i = 0; i < acc.length; i++) { acc.addEventListener("click", accordion); } function accordion() { for (var i = 0; i < acc.length; i++) { // Reset all of the elements but current selected if (acc.item(i) !== this) { acc.classList.remove("active"); acc.nextElementSibling.style.maxHeight = null; } } //check if current selected has 'active' class and remove it and next sibling, else add and show next sibling if (this.className.indexOf('active') !== -1) { this.classList.remove("active"); this.nextElementSibling.style.maxHeight = null; } else { // being a new selection and not a currently active selection add active class // Toggle the "active" class for the current item this.classList.add("active"); // Make the contents visible var panel = this.nextElementSibling; panel.style.maxHeight = panel.scrollHeight + 'px'; } }
  20. 1 like
    Add 'this' to the function called by anchor link event onclick <a onclick="myAccFunc(this)" href="#">First group<i class="fa fa-caret-down"></i></a> Then you need to ref that specifically clicked element, transverse down to next sibling element and change that elements classname function myAccFunc(elem)//amended by dsonesuk { var x = elem.nextElementSibling;//amended by dsonesuk if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; x.previousElementSibling.className += " w3-green"; } else { x.className = x.className.replace(" w3-show", ""); x.previousElementSibling.className = x.previousElementSibling.className.replace(" w3-green", ""); } }
  21. 1 like
    It's never a good idea to dynamically create tables. Database are designed to handle millions of records, so I would recommend having just one table for the tickets.