Jump to content


  • Content count

  • Joined

  • Last visited

  • Days Won


Everything posted by justsomeguy

  1. Manipulating the $.ajax( ) data Parameter

    According to the documentation for the ajax method, beforeSend is called before the request is even sent. The 2 parameters that the function gets passed are the jQuery XHR object, and the settings object. So in your code, podType is set to the jQuery XHR object. The beforeSend function is really for modifying the request before it goes out (or canceling it), so I would think your code for changing the page should all go in the success function. Inside that success function podType will still have the value it had when you send the request, unless you change the value inside the function. You also need to quote all of those values in your case statements, otherwise you're trying to compare the value with different variables.
  2. im struggling bad here please help

    The reason why your code isn't working is because $con is not defined in those functions (and $pass and $conf_pass are not defined in newUser either). You can use global variables inside the function, but it's better to avoid globals and pass in any variables you want the functions to use. So you should pass $con to the functions. You should add this to the top of your code: ini_set('display_errors', 1); error_reporting(E_ALL); You should switch your database code to use prepared statements instead of trying to manually escape everything. Prepared statements offer better security. You can use prepared statements with mysqli, but it's better to use PDO. The PDO code is shorter and easier to understand, and PDO works with databases other than only MySQL. e.g.: $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); if ($stmt->execute(array($username))) { if ($row = $stmt->fetch()) { // it found a user } } http://php.net/manual/en/book.pdo.php For the code I posted above, I was saying that each function should only do one thing. Your newUser function should only validate and add the user if necessary, it should not also output anything or redirect. Your main code should do that based on what the function returned. If you want to return multiple values you can use an array like I did above to return a "success" value for whether the user was added, and a message to show them. So your main code would call that function and then decide what to do. Those header redirects wouldn't work though, because you sent output to the browser first. $result = newUser(...); if ($result['success']) { // maybe redirect to a thank-you page or something } else { // show the error in $result['message'] }
  3. im struggling bad here please help

    The forum completely wiped out my reply when I tried to edit my post, because the forum software is awesome. I'll try that again.
  4. im struggling bad here please help

    function newUser ($username, $password){ $return = ['success' => false, 'message' => '']; if (!isExist($username)) { if (passChk($pass, $conf_pass)){ // insert into the database here $return['message'] = 'Username Created successfully'; $return['success'] = true; } else { $return['message'] = "Password and confirmed password do not match"; } } else { $return['message'] = 'Username already exists'; } return $return; }
  5. how write a new function without recursion call

    In an easy way? No. You need nested loops, and the number of loops you write is going to set a maximum value for parts of what the function can do. Recursion is how you avoid that, you can use a much more elegant piece of code to do that kind of thing if you use recursion. The code you posted doesn't actually do anything though, it never returns a value other than an empty array when k is greater than 0. It might have gotten messed up because you didn't post it in a code box, maybe there's something left out, I'm not sure.
  6. how write a new function without recursion call

    With a long, messy series of nested loops which will end up resulting in the function only allowing a maximum size for the array or size. You should stop worrying and learn to love recursion.
  7. You might also want to look into that type attribute. Maybe values other than 0 give you other options also.
  8. There's no "or" character. That's not to say the particular program you're using doesn't define and use one (if so, it will be in the documentation), but there's not a specific "or" character. In programming languages you would use "|" to represent a bitwise OR operation (|| for boolean OR), but, again, the program you're using would have to look for and support that. I'm not familiar with that program, so I don't know how it works.
  9. The program you're using might support some kind of syntax for specifying multiple values to search for in the attribute, but you would have to check its documentation to see what it expects. The second one you pasted is not valid XML, commas don't go inside an element attribute list. An attribute's value is a single string, but maybe the program you're using looks for that string in particular formats and can split it up or otherwise use it in different ways.
  10. HTML 5.

    Yeah this whole topic is just bizarre. This is a forum for helping people learn how to program, this is not the correct venue to push your chosen morality or pass personal judgment on other people. If you'd like further help through this forum Rewillis, please leave religion and morality out of it and stick to programming. If you find yourself unable to separate those then it's probably best to look for help elsewhere. I'm going to close this topic, if you'd like to start over you're welcome to do that.
  11. Help needed Compiled source unreadable?

    You don't have to encode it, that looks like a failed Microsoft attempt to hide Javascript. I would be surprised if anything other than IE or Edge knows what to do with that, so it's better to leave it out. Javascript code isn't exactly a trade secret. Although it might be the case that the script tags tell the browser that it is encoded. This is the correct script tag to use: <script type="text/javascript" src="file.js"></script>
  12. How to build multimedia website with html

    If you have a question about how to use shadows in CSS, it would save you a lot of time to go to Google and search for that instead of asking and waiting for a response.
  13. Apache Control panel not coming up via http://localhost approach

    You shouldn't have to move or change anything, I'm sure that the Apache config files define a virtual directory (possibly /xampp) which points to a different location not inside htdocs. If you're not looking for a default dashboard, what exactly are you looking for?
  14. Help needed Compiled source unreadable?

    The opening comment refers to jscript.encode. You can download a decoder here. It looks like this site may also offer decoding. If you search for jscript.encode you'll find other information.
  15. Help me with Using JQuery AJAX code

    Note that the referer header is optional and not considered reliable. There are tools you can use to send your own requests to any server, when you do you'll see that you can write whatever you want in the referer. That header is also sometimes removed by various internet security software, and in some cases the browser will not send it at all to avoid information leakage (e.g., when going from HTTPS to HTTP). I was also checking for a referer header in our application on one file, but enough people reported that they were not able to access that and we replaced it with checking the session. A user can create their own referer header (or any other header, for that matter), but they cannot create their own session.
  16. JSON question - simple

    Yes, you would use an array of objects as shown. As far as file types, it's not very common to have a static file only containing JSON that you read from, they just do that because it's an easy example. It's more likely that you'll be sending ajax requests to PHP or another language on the backend which would dynamically generate the JSON (from a database, as in your example). You can use PHP or whatever language to set the content-type for JSON though, rather than saying it's HTML.
  17. How to Change Angular easily to sharing site

    Do you have an example? Do you mean that you're using ajax requests to change the content on the page?
  18. HTML 5.

    As far as bible verses go, I prefer Matthew 6:5.
  19. How to build multimedia website with html

    That's a really vague question. I suppose you start the same way you start with any other website: at the beginning.
  20. htaccess rule not working

    I don't think you'd want to do that, some of those rules you do want to be the last rule processed. You need to order them based on priority though, which rules do you want to happen first in which order.
  21. Convert old PHP site into responsive one

    I don't know how that was set up, but it's including a file called menu.php in a directory based on the language, so maybe whoever built that expected you to create different files for each page and put them in the appropriate language directories, and then change that code on each page to include the files appropriate for that page and language. You should have the same set of files in every language directory, the menu.php file should exist in the directory for every language. I don't know how the original programmer set that up or what they put inside those files, but that's what it looks like. You can make a regular image link, but the URL should include a lang variable set to whatever language you want to use.
  22. That looks better, yes. You're only sending JSON data, and like you've learned when you specify to jQuery that the data type is JSON, it will automatically parse it and fire the success function only if that worked. If you did not specify a data type of JSON then it would return the response as a string. You can also build that array in PHP so that it is an associative array with string names for the keys instead of numbers, and in Javascript that can be decoded as an object with named properties. So you could have data_array[0].id, data_array[0].title, etc.
  23. Well, you're wrong. If you're going to use it as JSON, then it needs to be JSON, that's about as simple as it gets. If you want to fix the parse error, great, we can do that if we see what data you're trying to parse, and what the error message is. But let's not make incorrect assumptions about what the problem is. There's no reason to assume anything, everything can be tested. I know exactly why it's not producing the expected result, because you're trying to pass a bunch of HTML tags and Javascript code to a JSON parser. That's the reason. But, like I said, there is no reason to make assumptions. Add some debugging code to your success function and you'll see exactly what it's trying to do: success: function(jsonData){ console.log('Success callback'); console.log(jsonData); var data_array = JSON.parse(jsonData); console.log(data_array); alert(data_array[0]['podcast_no_item']); } When I run your page right now, your success function doesn't even get called, and there's a PHP error message in the response. I can put a breakpoint on the ajax call to verify that it sends the ajax request, but if I put a breakpoint inside the success function it never gets hit, that function never gets called. I assume that's because jQuery tries to parse the response as JSON and fails, since it is not JSON, and thus it never calls success. The ajax method will also accept functions for error which it will call if the request failed, and there's another one called complete that it calls after either success or error. Right now your success function isn't being called at all, and I assume it's because of the bad data.
  24. Multiple Slideshows on one page

    That doesn't use jQuery. But it's set up to assume just a single one. If you want multiple ones on the same page then you need to distinguish each one, and you need to adjust the code to look for a specific one. For example, in the main container you could give each one a unique ID. Then, in the Javascript code, you get use getElementById to get a reference to the parent container, and then use that to get the child elements with the various class names. If you use the document object it's going to find elements with that class all over the document, but if you use rootElement.getElementsByClassName then it will only get the elements with the class which are children of rootElement, whatever you set that to. It also uses a global variable called slideIndex, you'll also need to change that to something like an array so that you can have one index per slideshow ID. You'll also need to change the click handlers to pass and use the slideshow ID, so instead of, for example, currentSlide(2), you would do currentSlide(2, 'slideshow2') where you pass the ID for the slideshow container so that everything is looking up the data and elements based on a unique ID for each slideshow.
  25. Which Apache ver to use: 2.2 or 2.4

    Unless you have a particular reason for using an older version, it would make sense to use the newest stable version. MariaDB is a fork of the MySQL project after Oracle made some unwelcome changes to MySQL. MariaDB was forked by the original author of MySQL. It should be compatible, but it's on a different development path from what Oracle wanted to do after buying MySQL.