• Content count

  • Joined

  • Last visited

  • Days Won


Everything posted by justsomeguy

  1. If you just want the numbers 50 through 60 in a random order, you can make an array with those numbers and then shuffle it to randomize the order: http://stackoverflow.com/questions/1519736/random-shuffling-of-an-array The other option is to keep generating random numbers and checking if they are already in the array before adding them.
  2. And what is the response from PHP? You can find that in your developer tools if you look at the ajax request. Is PHP responding with whatever Javascript is expecting?
  3. You have a for loop that loops through the records. Inside the loop you start a new table for each record, you have an opening table tag inside the loop. You don't have any closing table tags though. You shouldn't use document.write or document.writeln though, those are ancient and aren't used anymore. You should build an HTML string that you can add to, and then at the end of the code you write that HTML to an element on the page. So you should put a container element on the page like a div: <div id="content"></div> And then build your HTML string in Javascript, e.g.: var html_str = '<table border="1">'; for (var i = 0; i < courseCodeArray.length; i++) { html_str += '<tr>'; html_str += '<td>'+courseCodeArray+'</td>'; ... } html_str += '</table>'; And then at the end write the HTML string to your placeholder element: document.getElementById('content').innerHTML = html_str;
  4. You have a typo in that first for loop line. Your next for loop is going to set every element in myArray to pop. So you're going to end up with every element in myArray set to whatever the last random number was. You're looping through myArray and, if the current element is not set to pop, then you set it to pop, so you set every element to pop. What are you trying to do, are you just trying to get the numbers between 50 and 60 in a random order?
  5. Are you sure that's the right syntax, you don't need EXEC? Again, this is from the documentation that I linked to: // EXEC the procedure, {call stp_Create_Item (@Item_ID = ?, @Item_Name = ?)} seems to fail with various errors in my experiments $sql = "EXEC stp_Create_Item @Item_ID = ?, @Item_Name = ?"; You should really use those placeholders with prepared statements also instead of injecting the variables into your SQL query, maybe those variables have a value which is breaking your SQL code. That's the point of prepared statements, to avoid situations like that.
  6. You need to send the query to the SQL server. Check the examples on that documentation page I linked to, it starts with sqlsrv_connect to connect to the database server, and then you can use sqlsrv_prepare and sqlsrv_execute. Like I mentioned, the first comment on that page shows that process using a stored procedure also.
  7. To avoid SQL injection, you should use prepared statements. The first comment on this page shows an example of using it to execute a stored procedure: http://php.net/manual/en/function.sqlsrv-prepare.php That being said, you build that $sql1 variable but you never execute that query. You're just building a string of SQL in PHP, but not doing anything with it.
  8. Javascript and PHP does not belong in the Java forum.
  9. Well, then you haven't done it right. Show the code you're using.
  10. How do you know the PHP is working fine? What is the response that you see in your developer tools when you validate that with an email that already exists?
  11. fetchAll will return an array of all of the records returned, so comparing that with 0 wouldn't work. You can either just select all of the records, use fetchAll, and see if the length of the array is greater than 0, or give the count an alias and then fetch the row and access the count with the alias name like any other column. SELECT COUNT(email) AS nr_email ... Then you can get the row from that result and check the nr_email column.
  12. https://www.w3schools.com/sql/sql_count_avg_sum.asp
  13. 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.
  14. Instead of using PHP to output Javascript code that changes the appearance of an element, why not just print the element the way you want it to appear?
  15. The PDO rowCount function doesn't return the number of rows returned by the select statement for most databases, so instead of that you should send a query where you select the count.
  16. If you set a unique index on teamnumber, tasknumber, and date, then you can use INSERT IGNORE to insert a new record as long as it doesn't violate the unique index (i.e., as long as it's not already there). You can also use INSERT .. ON DUPLICATE KEY UPDATE to either insert a new row or update an existing row if it already exists.
  17. As long as your MySQL user has access to both databases, you can run queries on one or both of them. You don't have to "open" them, once you connect to the server you can either select a default database, or just include the database name in all of your queries.
  18. The file input ID upld, to get the list of selected files. That's what you do here: if(this.files && this.files[0]) But if that is going to run on a button click, then this will not refer to the file input, so you need to get it by the ID and then check the file list.
  19. I'm not aware of any limitations on use. They have copyright by default but I haven't seen any language about requiring attribution.
  20. This is why it runs when you select a file and the file input field changes: $(":file").change(function() { If you want a button to control that then use a click handler for the button and get the file input by ID to get the list of files.
  21. JSON doesn't "do" anything, it's just a data structure. You need to use Javascript to get the radio buttons (by ID if they have unique IDs, or another selector if they don't) and loop through them to figure out which one is checked, then you can get the value property of the one that was checked.
  22. The forum decided to eat my entire post. src = compImg; img.src = src; You're setting the src of an img element to be another img element. Shouldn't that be this: img.src = compImg.src; Is that what you're trying to do? Create a new img element and set the src of it to the src of an existing img element? For this part: container.appendChild(compImg); compImg is already on the page, is that what you want to append to the new div? Don't you want to append the element you just created? Otherwise you're not doing anything with the new element. Other than that, I would suggest using console.log statements or setting breakpoints to pause the code and look at the values of things. For example, I would check that e.target.result is something that belongs as an img src.
  23. Also, you're never going to see a request in the network console because you're not sending the file over the network, everything is being done in the browser. You're reading the local file and updating the page, not sending it to a server. That's why there's no request to a server.
  24. You'll need to check the documentation for that software to see what it supports. That almost sounds like it's running everything in some strange type of transaction where the previous statements don't have any effect until everything finishes.
  25. Since it wasn't clearly stated, you just copied and pasted the Javascript code twice. You used the same function name, and you overwrote window.onclick. The second time you define myFunction, it removes the first one (or it causes a fatal error, I'm not sure which in this case). And the second time you assign a function to window.onclick, you remove the first function that you assigned to it. You need to name things differently, names in Javascript are unique. You can't name 10 things the same thing and expect to be able to refer to all of them at the same time. And if you need multiple things to happen when an event happens, like window.onclick, then you need to combine that instead of replacing one with the other. This is one way to do that: old_onclick = window.onclick; // save the old function window.onclick = function() { old_onclick(); // run the old handler // then do new stuff } The more modern way is to use window.addEventListener to add a new event handler instead of changing things like window.onclick. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener