Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. A simple way of fixing this (and reducing the amount of code and data you have) is to simply COUNT() (inside a query statement) the number of participants for any event. By storing a separate number, you are creating redundant data that now must be maintained.
  2. Course_Name cannot be two different values at the same time. You actually need to use an OR condition to select the rows where Course_Name='COSC 3312' OR Course_Name='COSC 2430'. Give the following query a try - SELECT Course_ID FROM Course where Student_ID='$Stud_ID' AND (Course_Name='COSC 3312' OR Course_Name='COSC 2430') Or even more simpler - SELECT Course_ID FROM Course where Student_ID='$Stud_ID' AND Course_Name IN ('COSC 3312','COSC 2430')
  3. ^^^ Since you are just doing year/month date math, you need to use a day number that exists in every month. Use '1' as a value for the day parameter instead of date('d').
  4. Error_reporting should be set to E_ALL (or even better a -1) and display_errors should be set to ON in your master php.ini on your development system. Stop and start your web server to get any changes made to the master php.ini to take effect. Confirm that the settings actually got changed by using a phpinfo statement in a script in case the php.ini that you changed is not the same one that php is using. The Loaded Configuration File value in the output from a phpinfo() statement is the php.ini that php is using. The reason for setting these settings in the master php.ini is because putting the settings into your script won't show fatal parse errors in your main file (fatal parse errors in included files would be shown) because your main script never runs when there is a parse error in it and the settings won't take effect. Also, by putting these settings in to the master php.ini on your development system, you don't need to remember to put them into your files for debugging purposes and you don't need to remember to remove them when you put your files onto a live server. The post by stenbom concerning white-space at the start of your file causing a blank page is irrelevant. The only time that would cause a blank page is if your page was performing a header redirect. The white-space would prevent the redirect and if error_reporting/display_errors settings are off, you would not get any indication of why the redirect failed.
  5. Further to the above: The $percentage calculation in the first piece of code isn't even being used, so the two queries returning a huge number of rows aren't needed at all. For the 2nd code piece that Psycho rewrote, since the file has been saved as a file, readfile (instead of file_get_contents) would read and output the file without consuming php's available memory.
  6. One of the reasons you are having a memory problem is because you are selecting all the data in your tables just to get a count of the total number of rows and of the active number of rows, but you are not using the rows of data that were returned. The first two queries in the code you posted should be SELECTing a COUNT() of the number of rows (your current code should be using mysql_free_result to free up the memory right after you use mysql_num_rows statement.) Edit: You also have a lot of ridiculous queries and code following that. The first 'real' query where you are selecting all the matching rows is all you need. Just retrieve that data into an array and if you do actually need to split it into parts for downloading, which I doubt at this point, use array_chunk to break it into specifically sized pieces. Edit2: Based on the excessive amount of queries and code, I would say that your memory problems are due to the code. You can likely replace everything you have shown with one query that gets the data that you want in the order that you want it, then simply output it the way you want as one CSV file per table.
  7. The code you posted doesn't contain anything that references and index: id. That's not the code where the error is occurring at.
  8. And after you fix the above mentioned php syntax errors, there is yet another one a few lines later due to some missing punctuation.
  9. After you fix the in-line html tag problem I mentioned above, you will find that you have another fatal php parse/syntax error in your code (edit: which thorpe posted a fix for in reply #1.) I won't specifically mention what it is because it is imperative that you get the error_reporting/display_errors settings set as suggested on your development system to get php to help you find these basic/fundamental problems in your code so that you can get past them on your own without wasting time running to a help forum for each one. Programming is an exact science. Computers only do exactly what their code tells them to do. The syntax errors you are currently getting are the same as the red marks your language teacher put on the papers you turned in for spelling errors, grammar errors, and punctuation errors. The code you write must have perfect spelling, grammar, and punctuation before the computer will even execute it.
  10. You have a fatal php parse (syntax) error in your code because you have some HTML tags (<HTML><BODY> and </BODY></HTML>) in-line inside your php code block. Only php statements can go inside of your php code block. You would either need to echo the HTML tags or exit php 'mode' by putting a closing ?> php tag before the html tags and then re-start php 'mode' by putting an opening <?php tag after the html tags. As it will save you a HUGE amount of development and debugging time by getting the php error_reporting/display_errors settings to work, you need to debug why the change you made to the php.ini did not take effect. Did you restart your web server to get the changes made to the php.ini to take effect? Did you change the php.ini that php is using? The Loaded Configuration File value in the output from a phpinfo statement is the php.ini that php is using.
  11. Also, your HTML is far from being valid. The opening <form > tag is inside your looping code, so you will be producing multiple opening <form > tags, but your closing </form> tag (one of them) is after the end of the loops.
  12. You would need to post the actual code that you need help with. All the statements I posted above were function calls. User written functions consist of the function definition and then actually calling that function at the point where you want to use it. A function definition (i.e. the function keyword is used along with {} to delineate the start and end of the function code) - function displayMembers($someParameterName){ // your code and variables that implement the useful operation you have defined for this function } Calling the function at some point in your code - displayMembers($session->username); // it's a program statement, therefore it is terminated with a ;
  13. I looked in your code. Your <form ...> tag is missing the enctype attribute that would allow the form to upload a file. <form method="post" action="update.php" enctype="multipart/form-data">
  14. The warning is because your code is not testing if the file uploaded before accessing the uploaded file information. To avoid that warning, you would need to put that line of code inside the else { ... } logic, right before the header() redirect. The warning also means that the upload isn't working or you didn't select a file to upload.
  15. In the script that handles the post
  16. $_FILES['uploaded_file']['tmp_name'] contains the location of the uploaded image, which will be destroyed once the script on your page ends. You would need to read the image data and store it into a session variable - $_SESSION['raw_image_data'] = file_get_contents($_FILES['uploaded_file']['tmp_name']);
  17. No. That's why Muddy_Funster suggested doing so would be masochistic. You first need to determine what requirements there are and why it is not working now. You could go through the trouble of using a phpmailer class only to learn that there is a problem with a firewall between your web server and the mail server. Does your web host have any FAQ information available? If they gave you information about the mail server's hostname, mail.mysamplewebsite.com, you should be using that as the "SMTP" setting instead of 'localhost'. Yes, you can open a socket connect to the mail server and directly send and parse smtp commands and replies (this is what the phpmailer classes do for you.)
  18. The error message you posted at the start of this thread is from a Windows/wamp system. Did that error message come from a php script running on your web host? If you are not using SMTP Authentication and the mail server requires it, you would be likely (but not always) getting errors indicating permission problems/authentication required/relaying restrictions... and your web host would have probably told you if you need to SMTP Authentication. There error message you did get indicates that there is no mail server listening on that port number (or it was not running) on the localhost computer where the web server/php is running at.
  19. Then you should consult with them/their FAQ as to the hostname and port number that you should be using in your php script. If the default values in the php.ini (localhost, port 26) didn't connect to a valid mail server, then either the mail server was down at the time you tried or you are expected to set the "SMTP" and "smtp_port" settings to the correct values using ini_set() statements in your script, as the error message suggests.
  20. Network-wise, what is the relationship between your localhost computer and where the mail server is at? Are they on the same local network AND the mail server has been configured to trust the IP address of your localhost web server or are they on completely separate networks, such as your mail server is at your ISP or a web host and your localhost computer is at your office or home? A general purpose solution would be to use one of the popular php mailer classes and use SMTP Authentication (i.e. supply a username/password for a mail box on that mail server), because the php mail() function does not support SMTP Authentication.
  21. NNNNnnnnoooooo...... That just makes more work for you. This is more than just keeping variables straight. It is about writing code that is general purpose and can be easily used/reused in any situation or in different situations within one application. Functions should be 'black boxes'. They optionally accept inputs that they need as call time parameters, perform some useful processing, and return or output the result they were designed to do. If you use call time parameters, you can directly call your function with a literal value, a variable, or another function result - displayMembers('admin'); // a literal value displayMembers($session->username); // the currently logged in user displayMembers($value); // a 'random' variable, such as from looping over a list of usernames displayMembers(someOtherFunction()); // a function that returns a username displayMembers(trim($_POST['username'])); // a built in function that does something you need You don't need to add yet another $myUname variable in your code. That just makes more work and takes more memory (both your's, keeping track of it and all the other ones that are brought into functions using the global keyword, and the computers memory.) Also, there's a reason that built in functions (optionally) take call time parameters, perform some useful processing, and return the result back to the calling code, it's so that you can use them as building blocks in your code. Your user written functions should do the same. Here's an argument that your global $database variable should be a call time parameter to your function. What if you had an application where you needed to call your function at different points for different databases that happen to require different database connections? You already have 100's of lines of code that expect your main program's $database variable to contain the main database connection, but you have a second database connection in $db2. For using global $database to get the db connection into your function, at a point before you call your function to operate on the $db2 database connection, you must assign $database = $db2; What just happened to your main database connection in $database? It got overwritten. Did you remember to copy it to some temporary variable? Did you remember to copy the temporary variable back into $database after you called the function so that the remainder of your code on the page will have the expected database connection in $database? However, if the database connection was passed as a call time parameter into your function, all this goes away. You just call your function with the database connection it needs - displayMembers($database, $session->username); // the main database and the currently logged in user displayMembers($db2, $session->username); // the second database connection and the currently logged in user displayMembers($db3, $session->username); // oops, the boss just added a requirement that this work for a 3rd separate database connection that we cannot change and the currently logged in user The theme throughout this is simplification and writing clean and clear code. Would you rather have one line of code to call your function displayMembers($session->username); or would you like to be typing extra lines of code - $myUname = $session->username; displayMembers(); to accomplish the same thing?
  22. ^^^ Do you have a mail server installed and running on your localhost Windows computer that is listening on that port number? The php mail function acts like a simple unauthenticated email client (i.e. Outlook/Thunderbird but without a username/password.) It needs a locally installed mail server (that it accesses through a command line interface - sendmail) or an SMTP mail server that has been configured to trust the IP address of the web server that your php script is running on. Do you actually need to send email from your localhost computer or are you just trying to test a script that uses the mail() function in it?
  23. You need to have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that all the php detected errors will be reported and displayed. You will save a TON of time. You would be getting undefined variable error messages, first for your $myUname variable, then for your $session object when you reference them inside the function. Your problem is because variables inside of functions are local to that function (this so that you can write any code you need inside of a function without needing to keep track of what variables you are using in that code so that they don't interfere with the application you happen to be using the function inside of - once you write large applications with 1000's of variables and hundreds of functions, you will see why this is important.) You need to pass values into your functions as call time parameters.
  24. The error is occurring at the mysql_query statement, because you have not made a mysql connection before calling code that needs a mysql connection. You also need to get all the @ error suppressors out of your code. There's absolutely no reason to put @'s in any code (when developing and testing code, you want to see all the errors, not hide them and on a live server display_errors should be turned off, so having @'s in your code would just slow it down without serving any purpose.) The @'s you have now are hiding php error messages that would help you find the problems in your code. You are also trying to put an instance of a mysqli database connection into the second parameter of a mysql_query() statement. That won't work. You cannot mix mysql (non-i ) and mysqli (with-i ) statements together. Edit: Also, any WHERE clause you use on your page must be present in both query statements so that the queries will find the same set of data.
  25. I recommend that you re-generate the code using that site, using names that are valid (it's kind of funny that someone would go to the trouble of writing a php code generator but wouldn't validate the input or even mention on the input form what is permitted as a name and what isn't.)
×
×
  • 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.