Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. You need to have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects. You use mysql_fetch_xxxxx() statements on the result resource that the mysql_query statement returns.
  2. Then your original query (and what I posted) would never have worked for at least two reasons - 1) You are forming a YYYY-MM-DD HH:MM:SS value in the $datex variables and trying to compare that with what is in your table. The format of the two values must be identical for the comparison to work. 2) The September 2011 format cannot be used in a greater-than/less-than comparison because the year would need to be the left most field (most significant digits) and the month would need to be numeric (the month names when compared alphabetically are not in the actual month order.) In general, you should store data that is associated with a date using the full actual date it occurred on. This will let you easily do any kind of manipulation of the data you may need.
  3. The following query should (untested) work - $string = "SELECT SUM(premium), SUM(repcom) FROM commission WHERE repnum = '$repnum' AND EXTRACT(YEAR_MONTH FROM `date`) = EXTRACT(YEAR_MONTH FROM CURDATE() - INTERVAL $nummonth MONTH)"; I assumed that your date or datetime information is in a column named `date` since that portion of your query statement was missing. Just get the data that matches the year/month you are interested in. Edit: I hope you are not calling your commiss() function inside of a loop, passing it a series of month numbers to get the results for a range of years/months. What you would do in this case is select the rows that cover the overall range of dates you are interested in and GROUP BY EXTRACT(YEAR_MONTH FROM `date`) to give you the SUM() information for each year/month within that overall range of dates. If you are just calling your commiss() function once on a page to get the results for one month only, no problem, but executing queries inside of loops,even if the query is inside of a function, is not efficient.
  4. Your processing code must check for a successfully uploaded file before it can access any of the uploaded file information.
  5. There's something that is setting both the master and local value to http://localhost/ http://localhost/ Search through that php.ini file for all occurrences of session.cookie_domain
  6. The php.ini that you are looking at is probably not the one the php is using. The Loaded Configuration File line in the phpinfo() output is the php.ini that php is using. In most cases, an empty session.cookie_domain setting should be used. The session id cookie will automatically be set to and match the host name of the server.
  7. ^^^ That's not a domain. It is a URL. I recommend that you find where that value is being set at and clear it.
  8. Find out the reason it is failing by displaying all the php detected errors. Add the following two lines of code immediately after the first opening <?php tag on the page - ini_set("display_errors", "1"); error_reporting(-1);
  9. You need to determine why the session_start() on page1.php didn't send a session id cookie to your browser. Create a php script file with a phpinfo() statement in it and browse to the file. Post ALL settings from the session section of the output. The first line should be Session Support enabled. The last line will probably be session.use_trans_sid Is there any chance that you have disabled cookies in your browser settings?
  10. Based on the output your code was producing, here's how you can use one query - <?php include 'connect.inc.php'; // use a .php file so that someone cannot get your database connection information $query = "SELECT year,month,COUNT(*) as cnt FROM images GROUP BY year DESC, month DESC"; if(!$result = mysql_query($query)){ // query failed, handle the error here... die(mysql_error()); } else { // query executed without any errors if(!mysql_num_rows($result)){ // query returned zero rows echo "There are no matching rows in the database!"; } else { // query returned row(s), process the data here... $last_heading = null; // remember the heading, initialize to a value that will never exist in the data while($row = mysql_fetch_assoc($result)){ // detect a change in the heading if($last_heading != $row['year']){ $last_heading = $row['year']; // remember the new heading // heading changed, output the new heading here... echo "{$row['year']}<br />"; } // output each piece of data echo "<a href=''>{$row['month']}</a>{$row['cnt']}<br />"; } } } ?>
  11. So, do you actually have the `year` and `month` stored in separate columns or do you have the DATE (YYYY-MM-DD) stored in a column with a DATE data type? Also, you may have seen this suggestion posted in the forum, but it is almost never a good design to perform queries inside of loops. You can perform one query using a SELECT COUNT(*) term and a GROUP BY year, month term to get mysql to do everything you need.
  12. That sets it to ON, with a specific buffer size. The following will set it to off - output_buffering = off Stop/start your web server to get any changes made to the master php.ini to take effect and use a phpinfo() statement to confirm that the setting was actually changed in case the php.ini that php is using is not the one that you changed.
  13. The most likely reason your code 'works' on your development system is because output_buffering is turned on in your master php.ini. That allows your code to improperly output content/html to the browser (it gets buffered instead) before it sends a http header to the browser or tries to set a cookie. If output_buffering is ON, on your development system, turn it off so that the code you develop will work on the widest range of server configurations. You have two choices, either add output buffering to your page (not recommended as it adds to the memory usage and slightly adds processing overhead) OR rearrange the logic on your page so that you put the php code that makes any decisions about redirecting before you output any content/html to the browser.
  14. ^^^ How exactly is your page reloading itself after you log in? I suspect this has something to do with sending output (perhaps only a space or something) before a header() redirect that prevents the redirect. However, when you refresh the page, the session variable indicating logged in/out is already in the proper state so that the code displays the expected content. For debugging purposes, add the following two lines of code immediately after your first opening <?php tag on the main page - ini_set("display_errors", "1"); error_reporting(-1);
  15. As an added bonus, here is what your form code could be reduced to by using php to produce it (the form processing code would be similarly reduced) - <?php $fields = explode(',','Artist Profile Image,Art Image ' . implode(',Art Image ',range(1,24))); echo '<form action="pdregisterres.php" method="POST" enctype="multipart/form-data" onSubmit="return checkrequired(this)">'; echo "<table>"; foreach($fields as $key=>$field){ echo '<tr><td colspan = "2"><hr></td></tr>'; echo '<tr><td align = "left">'.$field.':</td><td align = "left"><input type = "file" name = "artimage['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price['.$key.']"></td></tr>'."\n"; } echo "</table><input type='submit'></form>";
  16. A) You should have used an array for the form field name and a simple loop in the php code to iterate over the images instead of copy/pasting/altering the code 25 times. You should have also dynamically produced the form using a loop instead of copy/pasting/altering the code 25 times. B) As to the problem -
  17. ^^^ And some relevant information, such as what the old server was (operating system and web server) and what the new server is (operating system and web server)? ^^^ I'll bet it did do something. Even a blank page is something and is a symptom that would help pin down what the offending code is actually doing.
  18. Browse to page1.php and check in your browser if there is a cookie named PHPSESSID for the domain/localhost you are using to access the page.
  19. I'm going to guess that in your actual code, the code you have posted is actually inside of some other logic that is false and is being skipped over or you have a fatal parse error and are getting a blank page because the code never runs at all or you are using short open tags and that setting is not enabled on your server so all the code is seen as a HTML tag and not php code.
  20. Setting error_reporting to E_ALL and display_errors to ON would (definitely) help expose the problem. $rowb["QD"] doesn't exist and would be producing an undefined index error message because you are selecting MAX(QD). You would reference that using $rowb["MAX(QD)"], or more clearly, use an alias name for that select term in the query and reference the alias name or you could reference the value using $rowb[0] (when using mysql_fetch_array or mysql_retch_row)
  21. You would want to use an INSERT ... ON DUPLICATE KEY UPDATE ... query -
  22. Ultimately, you would want to write a script that scrapes the data from the same source you are manually getting it now and 'automatically' enter it into your database table by simply running the script. However, for a starting project, you would want to display the list of names (either all at once or broken up by some scheme to give a more manageable amount of data to enter at one time) with either an input field next to each name or a drop down select menu next to each name to enter/pick the score. You would typically use an array for the field name with the player's id as the index to the array so that the value you enter/select is associated with the id. See this link for how to use an array for the html field name - http://us2.php.net/manual/en/faq.html.php#faq.html.arrays Once the data is submitted, you can use php's array functions (such as foreach) to iterate over the data to get the id (the key/index of the array) and the score that was entered/picked.
  23. FYI - using the md5 hashing function on a password does not make your code more secure and it does not make logging in more secure. It makes the stored passwords more secure in case someone obtains the contents of your database, because the actual passwords are not stored, the md5 hashed value of the password is what is stored. ^^^ You need an exit statement after the header() redirect to prevent the remainder of the code on your 'protected' page from executing. The only thing a header statement does is send a http header to the browser. The php code continues running until it gets to the end of your page or to an exit; statement.
  24. The following is your code, modified to build the two different queries. The first line If (isSet($username) && $_GET['act']=='myservers') and the last line $nr = mysql_num_rows($result); are your original logic. Replace everything between those two lines with the suggested code. There are comments in the code indicating where you would add portions of the pagination logic. <?php If (isSet($username) && $_GET['act']=='myservers'){ // query for username $query = "SELECT * FROM servers WHERE username='$username' ORDER BY id DESC"; } else { If ($_GET['act']=='sponsored'){ // query for sponsored $query = "SELECT * FROM servers WHERE sponsored='Yes' ORDER BY id DESC"; } else { If (isSet($_GET['country'])){ // query for country $query = "SELECT * FROM servers WHERE country='$_GET[country]' ORDER BY votes DESC"; } else { // query for all $query = "SELECT * FROM servers ORDER BY $sortby DESC"; } } } // at this point, $query contains the basic query $count_query = str_replace('*','COUNT(*)',$query); // produce the query to get the count of the matching rows // code to execute the $count_query and get the count into $numrows would go here... // code to calculate the $offset and $rowsperpage would go here... // add the LIMIT clause onto the end of the $query variable to produce the actual query to retrieve the data in the following code - $query = "$query LIMIT $offset, $rowsperpage"; $result = mysql_query($query) or die(mysql_error()); $nr = mysql_num_rows($result);
  25. Also, is the id column just a numerical value (if so all that "XSS protection" logic can be simplified to an (int) cast statement.) Basically, the logic needs to be cleaned up, simplified, and understandable before worrying about adding pagination to it.
×
×
  • 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.