Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Here's a different slant on the problem. You wouldn't want to use shared web hosting for an actual ecommerce site anyway. The database server that your account can access can also be accessed by all the other accounts that have been given access rights to that database server and database servers like mysql don't have bad login attempt/lockout protection against brute-force cracking attempts, so a script on any account can sit there 24/7 and try database usernames/passwords until they eventually connect to and have access to your database information. The security is only as strong as the strength of your database username/password. This is one of the two main reasons for hashing passwords that are stored in databases (the other reason being that not protecting against sql injection can allow outputting all the information in your database tables.) For an ecommerce site, at a minimum, you would want either VPS or dedicated hosting where the database server is only accessible by your scripts.
  2. $new_date = date('Y-m-d',strtotime($row['donation_date'] . '+ 1 month')); Or you can do this simply (and much faster) directly in your query - SELECT donation_date + INTERVAL 1 MONTH as new_date ..... You would reference the value as $row['new_date']
  3. Since the constructor stores the $donation into $this->amount, I will guess that your destructor should use $this->amount? The $donation variable only existed as a parameter/local variable in the __construct method/function and does not exist inside the __destruct method/function.
  4. Never-mind, managed to quote my own post instead of modifying it.
  5. I doubt the error was exactly the same. If it was, that meant that you didn't save or upload the new code to the server or you are not looking at the actual file/line number where the error message states the problem is occurring at. The first error you posted indicated that the mysql_query() statement attempted to form a database connection because you didn't supply one in the mysql_query() statement because the $connect variable was part of and inside your query string, not part of the mysql_query() statement. The code you posted in reply #4 is definitely not what was suggested and the code you posted in reply #14 is back to the original nonsense because you are putting the $connect variable inside the string that is defining your query statement. The 'fixed' code that was posted in reply #1 was a fool-proof way of insuring that you cannot mess up the query statement by mixing it up with the connection variable. If you post the actual error message and the corresponding code, I'm sure someone can probably help you. Edit: additionally, the code you did post in reply #4 and your error message concerning the mysql_fetch_array parameter indicates that was the actual code, not the code you just posted in reply #16. If you don't see the difference between the code I gave you, the code you came up with, and the last code you posted, it is not the same, and yes it matters exactly what your code is because computers only do exactly what there code tells them to do.
  6. So, is the voucherid in any way related to the ID value? Your login code should store both the username and the user id in session variables so that your code can operate the most efficiently (using a numeric id in queries to match up information is much faster than using a multiple character username string.)
  7. I have no idea what your last post means. The limited information you have supplied in the thread doesn't indicate what the overall code on the page is doing or what the overall result on the page is, so statements like 'necessary number of records', 'entire thing', or even mentioning scope doesn't mean anything to anyone reading this thread. The code I posted is only a sample showing how the general steps I suggested could be accomplished, relative to the code you did post. You would need to adapt the general concepts to what you are doing or you would need to provide enough information so that someone here could help. However, until you consolidate the tables for each piece of equipment in to one table, nothing you do will have much affect on performance. Putting queries inside of loops is a performance killer due to the 'cost' of forming each query statement, sending that query statement from php to the database server, and executing that query, repeated for every pass through the overall outer loop(s).
  8. Another important reason for fixing the errors is on a live server, where you would be logging any php errors instead of displaying them, you wouldn't want the additional slow down due to the disk writes to the error log file and you wouldn't want a Gigabyte size error log file to sift through to find and fix an actual problem that is occurring in your code.
  9. $connect is inside your query string "..." We recommend that you ALWAYS form your queries in a php variable, then put that variable into the mysql_query() statement. $query = "SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."'"; $result = mysql_query($query,$connect);
  10. You would need to post your actual code. I can guarantee that the code you posted didn't produce that result.
  11. The escape characters - \ are NOT stored in the database table. They only exist in the query statement to indicate which special characters are part of the data instead of being part of the sql syntax.
  12. String data must be enclosed by single-quotes so that it is not treated as a column name or a keyword - $insert = "INSERT INTO table (column1) VALUES ('$string')";
  13. I guess that explains the $row["table_name"] variable? I was hoping that it was 'configuration' data and not a dynamically changing table name. It holds the current table name and the code you first posted is inside of a query/loop itself. The query statement, based on the two queries in the code you did post, would look like this (add other columns to the SELECT term as needed) - $query = "SELECT d.date,d.timestart,u.first_name,u.last_name,u.email FROM {$row["table_name"]} d JOIN {$GLOBALS["userTable"]} u ON d.userid=u.id WHERE d.date BETWEEN '$start_date' AND '$end_date'"; Here is some sample code I came up with - <?php $step_size = 30; // minutes (size of each time slot) $end_time = "17:00"; // HH:MM (make time slots up to, not including, this end time) // build array of date/time slots for the range of dates for( $j=0; $j<$dayPerPage; $j++ ){ $dateArray = getDate( mktime( 0, 0, 0, date("m"), date("d")+$j+$dateOffset, date("Y") ) ); $date = sprintf('%04d-%02d-%02d',$dateArray["year"],$dateArray["mon"],$dateArray["mday"]); $hr = $startHr; $min = $startMin; $time = sprintf('%02d:%02d:00',$hr,$min); while($time < $end_time){ $datetime[] = "$date|$time"; $min += $step_size; if($min >= 60){ $min = 0; $hr++; } $time = sprintf('%02d:%02d:00',$hr,$min); } } // get start and end dates list($start_date) = explode('|',$datetime[0]); list($end_date) = explode('|',end($datetime)); // query for the matching data $query = "SELECT d.date,d.timestart,u.first_name,u.last_name,u.email FROM {$row["table_name"]} d JOIN {$GLOBALS["userTable"]} u ON d.userid=u.id WHERE d.date BETWEEN '$start_date' AND '$end_date'"; if(!$result = mysql_query($query)){ trigger_error("Query failed: $query<br />Error: " . mysql_error()); } else { if(!mysql_num_rows($result)){ echo "Query matched zero rows!"; } else { // one or more rows while($row = mysql_fetch_assoc($result)){ $data["{$row['date']}|{$row['timestart']}"] = $row; } } } // iterate over the date/time slots and display any data foreach($datetime as $dt){ if(isset($data[$dt])){ // data exists for this date/time slot echo "Date: $dt, Data: ",'<pre>',print_r($data[$dt],true),'</pre>'; } else { // no data for this date/time slot echo "Date: $dt - no data<br />"; } }
  14. It would take storing 10's of thousands of large pieces of information in a session to cause a problem (the size is limited by available memory and by the size of file that the operating system can manipulate.) Also, switching to database storage of large pieces of information will run into a problem with the database maximum packet size that can be transfered at one time. It is always best to find and fix the cause of a problem, rather than throw code at a problem and hope that the problem magically gets fixed. Your description of the problem sounds more like a logic error in your code. A memory size issue would produce php errors alerting you to the fact that there was a memory problem.
  15. In general, here is how you should handle this - 1) Determine the overall start and end dates/times of the data you want. 2) Execute ONE query that gets all the data you want and join this with the userTable to get the corresponding user information. This will give you one row per date/time/user. Pre-process this data and store it into a php array with the array index being the date/time value, so that you can easily find and retrieve data as you iterate over the overall date/time range (see step 3.) 3) Iterate over the dates/times (essentially your for() loop and the code that produces the $date, $oldSHr, and $oldSMin) and form a date/time key of the same format that you used for the array index values in step 2. Simply test if there is data (or not) in the php array for the date/time slot and produce the output that you want.
  16. F-n-Domocrazy, it is you who assumes too much. We only see the information you supply in your posts. You are not even clear yourself on what column you wanted to use in your code. From the start of this thread - BTW - Different sizes and colors of a product are different product ids. Your code would be so much simpler. Your current code has no way of testing the correct quantity column value.
  17. Something tells me that $row['sizes'] is probably not the quantity.
  18. You are overwriting the 'template' with the result of the str_replace(). After the first two iterations of the loops, the {CAT} and {SUBCAT} tags in the template don't exist. I recommend storing the output in a different variable than the actual 'template'.
  19. The method you are trying to use requires the latest php version -
  20. I suspect you are trying to find if $today is still part of the previous month range or if it is part of the current month range. If so, your comparisons would need to test for those conditions (if today is greater-than or equal to the start value and less-than or equal to the end value) - <?php if($firstday<=$today && $today<=$lastday) { $month = date('m', strtotime('-10 days', strtotime('next Saturday', strtotime('last Friday', strtotime('first day of this month'))))); $year = date('Y', strtotime('-10 days', strtotime('next Saturday', strtotime('last Friday', strtotime('first day of this month'))))); echo"1<br />$month|$year"; } elseif($thisfirstday<=$today && $today<=$thislastday) { $month = date('m', strtotime('-10 days', strtotime('next Saturday', strtotime('last Friday', strtotime('first day of next month'))))); $year = date('Y', strtotime('-10 days', strtotime('next Saturday', strtotime('last Friday', strtotime('first day of next month'))))); echo"3<br />$month|$year"; }
  21. A slight bit of number/string comparison theory. As long as the strings being compared have the exact same format (requires leading zeros on the month and day and the same separator characters in corresponding positions), so that each corresponding position in each string has the same magnitude in each string and the fields making up the string are ordered left-to-right, most significant digit (year-thousands) to least significant digit (day-ones) you can perform greater-than/less-than and equal comparisons between dates. This is the primary reason why mysql's date/datetime formats are YYYY-MM-DD. If you look at the actual values being used in your comparison statements, you will find that neither comparison is TRUE.
  22. ^^^ Whoever suggested suppressing error messages, gave you some bad advice, especially when trying to learn php, develop php code, and debug php code. Hiding those types of error messages will also hide the type of problems people make when first starting out learning a programming language. Not only will your code not work, but you won't get any error messages from php alerting your to where it found detectable problems in your code. As stated in your other thread for this same code/problem, I found the incorrectly named variable that is preventing your validation error messages from being displayed through trying your code and getting an undefined variable message from the code that was referencing a variable that didn't exist. I guess I repeat it here, since you didn't read, understand, or follow the advice given in your existing thread -
  23. This topic has been moved to PHP Coding Help. http://www.phpfreaks.com/forums/index.php?topic=345481.0
  24. Two things - 1) You need to have php's error_reporting set to E_ALL and display_errors set to ON when you are debugging code so that php will help you by reporting and displaying all the errors it detects (I don't see any place where the program variable $ca_id is being set from the correct $_GET variable.) 2) Moving thread to the php help section... (Unless the problem is isolated to and due to a specific mysql query problem, it's not a problem for the mysql forum section.)
  25. The error is because the file initially doesn't exist and the method the code is using to read the file assumes that the file exists and has a length greater than zero. The simplest solution would be to use file_exists in a conditional statement to skip over the code that is trying to read the nonexistent file until it actually exists.
×
×
  • 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.