DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
batwimp, good catch. session_destroy The session_destroy() here is being executed before the page is ever displayed to the user. The onclick attribute then has nothing assigned to it, so the button will have no effect.
-
or echo 'Current PHP version: ' . phpversion(); Adding 3 hours is a hack. There are two hours during the year when that will produce the wrong results. And if/when you move to a different server, if it is in a different timezone, your code will be wrong.
-
You never answered that question. It sounds like you are running an older version of PHP. If that is the case, and you cannot upgrade (which is recommended), you have to use the old timezone indicators ('EST' and 'EDT'). But that becomes tricky since you have to figure out whether the time is during Daylight Saving Time or not, first. You would have to look at using putenv and getenv to set or get the "TZ" environment variable. As to storing the date/time in the database. This can be problematic. There is no way to tell what timezone is associated with a DATE or DATETIME column in the database. The database server itself has a default timezone setting which is used as the "assumed" timezone of any DATETIME column. If this setting is changed, or you move to another server (in a different timezone), your DATETIME columns take on a different meaning. I always recommend storing dates and date-times as UTC values and applying the timezone on the front-end. If you are thinking about using different timezones for different rows of the same table, STOP NOW! That will just create a massive mess that you will never figure out later. If you just want to get past echoing out the time: echo date('Y-m-d H:m:s', strtotime(date('Y-m-d H:m:s') . ' EST')); // OR echo date('Y-m-d H:m:s', strtotime(date('Y-m-d H:m:s') . ' EDT'));
-
I suspect that the CREATE TABLE statement will fail.
-
In changeword() you are storing the new word in the session array with a key of $word $_SESSION['$word'] = $totalwords[rand(0, count($totalwords)-1)]; echo '<br/>'.$_SESSION['$word']; $_SESSION['scrambled'] = str_shuffle($_SESSION['$word']); But in check_word, you are checking against the value in the session array with a key of word function check_word ($guessword){ return strtolower($guessword) == strtolower($_SESSION['word']); These are not the same array element.
-
What version of PHP are you running? That function became available with PHP 5.1 I don't think you have given us a comprehensive explanation of the problem. You have suddenly injected "database" into the discussion (reply # but all of your other comments are about echoing out the time. Show us your code and tell us what it should be doing and what it is actually doing, and we can provide targeted help. I did not tell you to echo out the result of date_default_timezone_set() and, by the way, it is not a variable (why is there a dollar sign?) and you can not put a function call inside a quoted string (well, not if you expect it to execute); and why is $NOW() hanging out there on the end your statement all naked (without a semi-colon or anything? and what do you think it is going to do there? Nowhere in that code did you tell it to give you the time
-
1) Do you have session_start at the beginning of your scripts? Before any output to the browser 2) FYI: This $_SESSION['$word'] = $totalwords[rand(0, count($totalwords))]; needs to be this $_SESSION['$word'] = $totalwords[rand(0, count($totalwords)-1)]; Since the first word in the list is zero, the last word is one less than the count
-
To set the timezone, the function name is date_default_timezone_set. // Save current timezone setting $oldTZ = date_default_timezone_get(); if (date_default_timezone_set('America/New_York')) { echo 'The current time in New York is ' . date('h:i:s a'); } else { echo ' Nobody ever knows what time it is in New York'; } // Set timezone back to what it was date_default_timezone_set($oldTZ);
-
See http://dev.mysql.com/doc/refman/5.1/en/column-count-limit.html
-
The kind of problems that could be caused by adding or removing columns in a table would (most likely) not produce these symptoms -- they would likely produce errors, but the database would not be updated (or inserted). If your mySql (server software) was upgraded or the PHP engine (software) was upgraded; changes in the configuration could be affecting this. For instance: if register_globals was ON before and is now OFF any PHP code that depends on registered globals will fail. If you post the code that receives the form data we might be able to suggest some areas that may be causing problems.
-
SELECT * FROM articles WHERE tags = 'cars' AND Id != 'the id of the current article'
-
Check the rating on your fire safe before you do that. They keep the fire out, but not all of the heat. If the internal temperature gets too high (and I don't know what value that is), it could damage whatever media you put in it.
-
Error code when inserting a new user to table
DavidAM replied to alan6566's topic in PHP Coding Help
Did you read the error message? order is a reserved word in mySql. You should avoid using reserved words as column names because it creates this kind of problem. A work-around is to put back-ticks around the reserved word so mySql knows you mean it as a column name: INSERT INTO customer(userName, password, privilege, firstName, lastName, address, postCode, `order`, previousOrder) VALUES -
You can avoid the overhead of reading and writing the file by using the touch function. This function just changes the access and modification times on a file. If the file does not exist, it will be created. It is not uncommon on *nix systems to have an empty file around just to have a place to store a date-time stamp. if (file_exists($checkFile)) $lastTime = filemtime($checkfile); else $lastTime = 0; // Never been run before if ((time() - $lastTime) > 30) { // More than 30 seconds ago // Run your process here // The last step of the process should be ... touch($checkFile); } I would put some text inside the file explaining why it is there; you know, like the "This page intentionally left blank" pages in a technical document.
-
$months = date("m", strtotime($row['date'])); $row['date'] does not exist. $query = "SELECT MONTH(date), COUNT(DISTINCT referrer) 'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month."' AND '" .$t_month."' GROUP BY MONTH(date)"; Since you did not give the column an alias, it would be referenced as $row['MONTH(date)'] (I think). Even then, it is not a date-time value. It is an integer between 1 and 12 indicating the month. You could use the MONTHNAME() function instead of MONTH(). But the sort would then be alphabetical instead of chronological. Also note that if your date criteria crosses a year, the order will be confusing, since you don't show the year either. You might try something like this (untested code): $query = "SELECT CONCAT_WS(' ', YEAR(date), MONTHNAME(date)) AS RptDate, COUNT(DISTINCT referrer) 'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month."' AND '" .$t_month."' GROUP BY CONCAT_WS(' ', YEAR(date), MONTHNAME(date)) ORDER BY YEAR(date), MONTH(date)"; // Then refer to the column as $months = $row['RptDate'];
-
You get those errors because $db does not exist inside of the class. A variable ($db, in this case) that is defined outside of a function (or method) is not available inside the function or method. There are a couple of solutions to this, the most commonly recommended, is to add the variable to the function (method) parameter list: class Toplist { public function get_article($db, $id) { // ... } } # Then pass it in the call $ToplistObj->get_article($db, $id); However, there may be a different/better solution depending on a couple of things: 1) Is this your entire class? or are there other methods, particularly ones that will need $db? 2) Does this class extend some other class? Whether or not config.php defines a class is not really material to the first error message. However, once you fix the scope issue (above), the type of the $db variable may come into question.
-
1) In development, comment out the JS that shows the loadmore DIV. See if that solves the double request issue. If it does, we should be able to figure a way to show it without causing it to scroll the page. If it does not solve the issue, we can look elsewhere. 2) maybe the loadmore.php script is outputting some blank spaces or something. Try an alert (before the if (html) statement) with delimiters: alert("|" + html + "|"); if you see anything at all (including blank space) between the two pipes, then the problem may be with the PHP script.
-
I'm not an expert with JS, but could it be that making the "loadmore" DIV visible is causing the page to shift, thereby firing the scroll event? On a side note, that query in your loadmore function is not doing what you think it is. SELECT * FROM Users_Pokes WHERE ToID = '$user_ID' AND PokeMainID < '$mainID' OR FromID = '$user_ID' AND PokeMainID < '$mainID' order by DateSent desc LIMIT 0, 5 AND and OR have the same precedence, so that WHERE clause is evaluated left to right. At the very least, you should add a couple of sets of parenthesis in there: SELECT * FROM Users_Pokes WHERE (ToID = '$user_ID' AND PokeMainID < '$mainID') OR (FromID = '$user_ID' AND PokeMainID < '$mainID') order by DateSent desc LIMIT 0, 5 Although it could be written as: SELECT * FROM Users_Pokes WHERE (ToID = '$user_ID' OR FromID = '$user_ID') AND PokeMainID < '$mainID' order by DateSent desc LIMIT 0, 5 or even: SELECT * FROM Users_Pokes WHERE '$user_ID' IN (ToID, FromID) AND PokeMainID < '$mainID' order by DateSent desc LIMIT 0, 5
-
The echo statement in the MAIN code (outside of the class): echo $m->a . "," . $m->b . "," . $m->c . ","; essentially builds a string COMPLETELY and THEN outputs it. In order to build the string, it has to evaluate each of the expressions. $m->a - Accesses the pubic property "a" and places it's value ("A") in the "string" to be output $m->b - Actually calls the "magic" get method which echo's "b,", the returned value, "B" is placed in the "string" to be output $m->c - Actually calls the "magic" get method which echo's "c,", the returned value, "C" is placed in the "string" to be output After evaluating the expressions, the object has output "b,c," and then the echo in the main code outputs "A,B,C,". Since the object's echo's each completed before the main code's echo did, the output is: "b,c,A,B,C,"
-
Yes, the apostrophe (A.K.A. single-quote mark) is causing the query string to end prematurely. In order to resolve this problem, you have to use the mysql_real_escape_string function when placing your values into the query string. For example: $sql = "SELECT col1, col2 FROM table4 WHERE col3 = '" . mysql_real_escape_string($col3Value) . "'"; You should apply this function to all character fields in the query to protect yourself from SQL injections, and to allow the "special" characters.
-
That error is telling you exactly the same thing that bspace told you in Reply #3. Fix that "typo" if you want to retrieve the data from the query. You stored the query resource in $results, you have to fetch it from that variable: $resuts = mysql_query($query) or die(mysql_error()); $data = mysql_fetch_array($results);
-
Try replacing that last mysql_query() call with something like this: $sql = "INSERT INTO rc_subjects (report_card_id ,student_id, subject_id, report_card_column_1, report_card_column_2 , created_on ) VALUES ('$theRecordPeriod', '$stu_Id', '$stu_subject', '$stud_book', '$studGL','$today' )"; if (! mysql_query($sql)) die('INSERT failed: ' . $sql . ' With error: ' . mysql_error()); Of course, I would not leave the die() message in the production version, but I think this will give an idea of why the INSERT is not working. There is probably a single-quote mark in one of the values, or a duplicate key error or something.
-
Just for the record, $data is an array variable not an object variable.
-
You will have to loop through the categories and products. Something like the code below. foreach ($list as $catID => $products) { print($catID); foreach ($products as $prodID => $data) { print($prodID . ': ' . $data['SKU'] . ': ' . $data['Description']); } } I didn't put any formatting in there, you should be able to handle that.
-
Why is there a GROUP BY in there? You are not using any grouping functions in the query.