-
Posts
5,536 -
Joined
-
Days Won
192
Everything posted by mac_gyver
-
a unix timestamp would be stored as an integer data type. the functions used to produce the integer value would be those that produce a unix timestamp, such as php's time()/mktime()/strtotime() functions or mysql's UNIX_TIMESTAMP() function. a mysql timetamp would be defined as a mysql timestamp data type, with the values being supplied to it as either a 'YYYY-MM-DD HH:MM:SS' string or a YYYYMMDDHHMMSS number.
-
yes, but what does happen? we are not sitting there with you and don't know what you saw. what did happen, even if nothing happened, and what did you expect to happened?
-
What is the best method to write long if - else conditions?
mac_gyver replied to thara's topic in PHP Coding Help
if you find yourself editing your program logic, just to add, remove, or change values that determine what the logic does, you need to use a data driven design. after your write and test your program logic, you shouldn't be touching the code unless you are adding or changing the features in the code. using the general purpose method 02, in order to change the set-point values, add or remove the quantity of settings, or reuse the program logic (which should be a function/class-method) for a different set/purpose of mapping values, all you have to do is change or supply a different data definition. the data definition(s) can also then be stored in a database where an administrator interface can be provided to easily define/edit the definition(s). -
is your database holding a UNIX Timestamp or a MYSQL Timestamp, they are not the same things (though a MYSQL Timestamp is internally stored as a unix timestamp and has the same range restrictions.) a UNIX Timestamp is an integer that represents the number of seconds since '1970-01-01 00:00:00' UTC. a MYSQL Timestamp is formatted/treated as either a 'YYYY-MM-DD HH:MM:SS' string or a YYYYMMDDHHMMSS number. any mysql or php functions that operate on your data would need to be specific to what your data type actually is. are you using a UNIX Timestamp/integer or you are using a MYSQL Timestamp data type?
-
i looked at your CLASS code closer (i initially misread the $session_uname|$f_uname) and doing that won't do what you think. that's producing the bitwise OR between those two values, in the php code. i suspect you want a logical OR in the sql query statement, which would require sql syntax to do that. you cannot bind sql syntax, only values. you would need to form the correct sql syntax, with place-holders for EACH value, then bind each value. also, using the same place-holder name more than once is not proper usage. it does work with emulated prepared statements, but this is likely a bug that could get fixed at any time and you shouldn't rely on it in your code.
-
your program logic makes no sense. you are looping over the first query result to just get the id values, looping over any results from the second query for each id, then at the end looping over the first query result again. you are also building the output in variables but you are re-assigning the variable, rather than concatenating to it, on each pass through the loops. do what i suggested and run one JOINed query to get the data you want. you will have just one loop and a minimum of code to produce the output.
-
is the query giving you one row, which is what a count(*) will do since there's no GROUP BY in the query, with the COUNT(*) value in the row being a zero, or is the COUNT(*) value in the row a 1?
-
that would indicate that $context doesn't contain what you expect. what does adding var_dump($context);, right before the call to the function show?
-
are you sure the code is running at all? are you getting any output on the page (a blank .php page is usually due to a fatal parse or runtime error.) what is the actual value in $context['user']['mentions'] at the point where you are calling the function?
-
are you calling the function? a function consists of two parts - 1) the definition, which starts with the 'function' keyword, and 2) calling the function at the point in your code where you want to make use of what the function does. next, the input parameter(s) to the function should be the actual value that the function expects, so that the function is general purpose, and can be called with the input coming from any source. this function is testing if the input parameter is a number greater than zero. the input parameter should just be the number, without any context about where it is coming from. it's your calling code that knows the context of where the value is coming from. use the following for the first few lines of your function definition - function growl_notification($num) { if ($num > 0) and use this where you are calling the function - growl_notification($context['user']['mentions']);
-
even if you use a SELECT query to get the initial value, only use this for display purposes. any updating of the value should be done in a single query, so that you don't loose data when there are multiple concurrent instances of your code running, each trying to modify the value. or better yet, don't maintain a count/accumulator in a table column. instead, insert a separate row into a database table for each transaction that modifies a value, then sum up the values from the rows to get the current total. this will give you an audit trail so that you can detect things like double-page requests, programming errors, or if someone manages to find a security hole in your code and submits an arbitrary data value that modifies the count/accumulator by more than you want.
-
your two class methods will return an array. it's an empty array if the query didn't match any rows or it's an array of the all the rows the query did match, assuming that you are still throwing exceptions for any errors. all your for(){} and while(){} loop logic, besides not working, is not necessary. you can test if the returned array is empty or not using, well, empty(). you can loop over the arrays using a foreach(){} loop. next, $status_replies_=$project->reply2StatusView($id[$i]); you are running a select query inside of a loop. this is a performance killer due to the round-trip communication it adds between php and the mysql server. for what you are doing, you should run one JOINed query to get the data that you want, then just loop over that data. edit: public function statusView($session_uname,$f_uname) { you are passing an array and an index into your function/method to supply an account name. this is not how to write general purpose code. the function/method expects an account name as in input, that's all you should supply as an input parameter, so that you can reuse the function/method regardless of where the input comes from. the definition should just be - public function statusView($account_name) {. the code inside the function should just use $account_name, and the calling code would be - $status2view=$project->statusView($session_uname[$f_uname]); // supply the account name input, from wherever it is stored
-
a) are you running the query directly against your database using a query browser of some kind so that you would be seeing any errors from the query? b) what i posted isn't a copy/paste query. you need to adapt it to use your table and column names. you would also need to add in the active=1 logic.
-
see this link - http://dev.mysql.com/doc/refman/5.6/en/example-maximum-column-group-row.html where what you are doing is getting the maximum note id per group. using the last method shown at that link (left join) the following works (cannot vouch for how efficient it is, but it is fairly easy to understand or modify to use any JOINed table query for the two sub-queries) - SELECT t1.* FROM (SELECT p.*, n.note_id, n.comment FROM prospects p LEFT JOIN notes n ON p.id = n.prospect_id) t1 LEFT JOIN (SELECT p.id, n.note_id FROM prospects p LEFT JOIN notes n ON p.id = n.prospect_id) t2 ON t1.id = t2.id AND t1.note_id < t2.note_id WHERE t2.id IS NULL; this is using simplified table naming with - a `prospects` table with at least an `id` column and a `notes` table with at least `note_id`, `prospect_id`, and `comment` columns.
-
one would hope that the recaptcha api would return a unique error for each different thing that could go wrong, but perhaps not. the ip address in the data to the api is optional, so if it's not being put into the data, it doesn't matter, but what if it is present and it's not the same value from the client when the client solved the captcha? if the client being used for testing is on the same local network with the server, the ip address that the server gets in $_SERVER['REMOTE_ADDR'] will be a local ip. the ip address that the recaptcha api saw when the captcha was solved would be the public network ip address. try removing the ip key/value pair from the $captcha_params. next, i wonder what happens if you submit the same curl request twice, which would happen if your .php page is being requested twice? a lot of clients request a page twice. perhaps the output being seen is that due to a second request, and since the recaptcha api has already seen and responded to any specific 'g-recaptcha-response' value, perhaps it returns a null in this case? i would add code in your .php page that logs some information (see file_put_contents() with the FILE_APPEND flag) from the client request and from the curl response each time it runs. this will let you see if there are multiple requests being made for each form submission and if the curl response is always the same. you can also try using an 'official' recaptcha php class (there's a link on the recaptcha/google page.) perhaps it is setting curl options that can have an affect (i saw some code that's setting an ssl verify host parameter to a false value.) however, getting a null from a curl request seems more like a communication problem. the url that's being used would require that the server have open_ssl installed. what does the output from a phpinfo() statement show for the SSL entry under the CURL section?
-
without an ORDER BY term in your sql statement, there is NO guarantee that any particular row of matching data is going to always be the first row. what characteristic does your data have that identifies what order you want the rows from the query to be in and what identifying characteristic or value is there that you can use to not include the one particular row in the result set?
-
just because the mail() function is returning a true value, doesn't mean that the sending mail server has sent or has any intention of sending the email. some mail servers are configured to return a true value/no errors to php regardless of what happens to the email so as to not allow hackers to use the returned errors to find mail box names... next, the yahoo/protonmail email servers may be doing a more thorough check of the DNS records at your web hosting than what gmail is doing (any chance you are using google web hosting so that sending an email to gmail is coming from a google server and the sending mail server is the same as the receiving mail server?). the ONLY information a receiving mail server gets with any email is the ip address of the server/device the email is being sent from (from the tcp/ip data packets) and information in the email, i.e. the from address. the receiving mail server will use these two pieces of information to try and validate that the email is actually coming from where it says it is by checking the DNS records at the sending ip address and at the domain in the from address. perhaps the yahoo/protonmail mail servers are looking for a secondary piece of information that gmail isn't and something is either missing (missing values usually aren't a problem) or is set incorrectly (incorrect values will get an email discarded.) at a minimum, there should be an SPF DNS zone record at the domain being used in the from: mail header that indicates the sending mail server is authorized to send email for that domain. you can check your DNS records and test your sending mail server for configuration problems at a site like dnsstuff.com edit: if this is for a contact form, where you will always be sending to a single email address, you can use SMTP authentication (i.e. provide the access password for the mail box) against a receiving email address and send the emails directly to the mail server where the email address is hosted at. to use SMTP authentication, you will need to exchange smtp commands with the mail server. the phpmailer/swiftmailer classes handle this for you.
-
is your code producing any php errors or any oci errors? is your code producing a completely blank page or does anything on the page get output to the browser and its just the query result that doesn't get output? if you read any of the 'help my page/query doesn't produce any output' posts on any of the php programming help forums, you will notice a common thread, displaying php errors and testing for and displaying database statement errors. you must ALWAYS have php's error_reporting set to E_ALL and for development/debugging display_errors should be set to ON. these two settings should be in the php.ini on your development system, so that they will report php parse/syntax errors and so that you don't need to remember to put them into the code you are developing/debugging. all the database statements that can fail due to an error (connection, prepare/parse, query/execute) must ALWAYS test for errors and handle them in a meaningful way. for development/debugging, you would want to display the database error information. next, queries that run successful can still match zero rows and in most cases you should use your database's num_rows function/method (see oci_num_rows()) to test for and handle this case. if your code was already was doing these things, it (your code) would be telling you if, where, and way it is failing.
-
Generate alert message from database value
mac_gyver replied to finalsman's topic in Application Design
do you have a specific question(s) about doing this? just listing what you want isn't a question and we are not here to do your design for you, just to answer specific questions you have - see the sticky/pinned post http://forums.phpfreaks.com/topic/20513-read-me-welcome-to-application-design/ -
php page working in google chrome but not on firefox in ubuntu
mac_gyver replied to shan's topic in PHP Coding Help
re: post #6. there's nothing obvious in the code that would account for the problem/browser difference. if i have time i will investigate the code further. re: post #7. isset() tests if the variable is set or not. the boolean true from the print_r just means that it is set. when it is set, it can have either a false value or it will contain the fetched row from the query, so, adding an isset() around it is meaningless. any chance that in the browser where this works, the browser has been configured to remember passwords and it's actually the browser that's supplying the password and in the browsers where this doesn't work, you are actually typing the password and you are using the wrong one, either because the one that works was originally entered/registered with some fumble-finger accidental extra/wrong characters in it, or you are typing wrong password where it doesn't work? in any case, you need to determine why the query is not matching any rows. here are two things to do - 1) temporarily modify the sql query statement so that it only tries to match the username. if the code then results in a var_dump of the $user variable with the expected row from your database table, that means that the username comparison is working and it's the password that's the problem. 2) echo the md5() hashed password value and see if it is the same as what is stored in the row in the database table. i suspect it is not. i would do this for both the browser where it works and at least one where it doesn't. the echoed hashed value should be the same for all browsers and it should match exactly what is stored in the database table row that corresponds to the username you are testing with. edit: actually, step #1 in the above may not be so temporary. if you switch to using password_hash()/password_verify(), you will need to match the username in the query, retrieve the hashed password and pass the entered password and the retrieved hash through the password_verify() function to see if they match. -
php page working in google chrome but not on firefox in ubuntu
mac_gyver replied to shan's topic in PHP Coding Help
does the var_dump($user) show a boolean false at the same time as the var_dump of the $_POST data shows what you posted above? given that your html markup shows classes on everything, i'm guessing you are using some framework/code-generator, which could be responsible for the problem (i.e. double submitting the form, once with and once without values.) if you cannot debug and determine what's going on, it's going to take full disclosure of your code that reproduces the problem, both for the entire form PAGE and the entire form processing code in order to help find what is causing the problem. also, this mess - $uname= htmlentities($_POST['unamel']); $unamel= stripslashes($uname); $pass= htmlentities($_POST['passl']); $pass1= stripslashes($pass); htmlentities() is an OUTPUT function it is used when you send output to the browser. it is not an INPUT function and has nothing to do with values being input to your code. stripslashes() is used when you WAN'T/NEED to strip slashes from the input. neither of these functions should be used in your code responsible for logging in a user. while these two functions are not likely the cause (the different browsers could be sending different character-encoded values for your actual username/password), htmlentities could be altering the value(s) making them different from what was used when registering the username/password information. -
1) what does using var_dump($_FILES["file"]); immediately after the first opening <?php tag (in case some of your code/functions are modifying the value) show? 2) are you sure about the actual php code that's running? a statement like $GetName = ServerName($_FILES["file"]["name"]); could very well account for the symptom you are getting.
-
php page working in google chrome but not on firefox in ubuntu
mac_gyver replied to shan's topic in PHP Coding Help
the boolean false value is a symptom of a query that doesn't match any row(s), which is exactly what i stated in your last thread for this problem. if your code behaves differently for different browsers, it's likely that your form is invalid markup and isn't submitting what you think (or the user doesn't exist in your database table.) different browsers handle invalid markup differently, so, some may submit form data for broken markup, while other's don't. what does using var_dump($_POST) show for the submitted form data and what is your form code? -
How to Create a "action.php" page for HTML Form?
mac_gyver replied to rashidpathiyil's topic in PHP Coding Help
rashidpathiyil, your question, How to Create a "action.php" page for HTML Form?, isn't a programming problem. it's a research question based on a lack of knowledge. research questions are things you need to take care of yourself in order to learn enough about a subject so that you can make the attempt at performing a task. a programming problem, which is what programming help forums are for, are what you have after you have written some code and you have a problem or error with it that you cannot solve yourself (though too many people just dump their code on help forums without first making any attempt to learn and fix it themselves.) the www was created for researching information. php was created primarily to process form submissions. there are several 100's of thousands of php form processing examples posted on the www that you can examine to learn the basics of How to Create a "action.php" page for HTML Form. -
Need help posting to mysql and sending email from form
mac_gyver replied to gabbymiles's topic in PHP Coding Help
you may have tried a bunch of things, but if you didn't echo out the sql query statement so that you (and us) will know what it is (which would also confirm that the code where the query is at is running) and check if the query is producing an error or not, you will never narrow down the problem and find what's causing it. it's also possible that your code is inserting a row, but its not where you are looking for it at. that you are specifying the database name in the insert query means that the insert query could be operating on a different database than the one you think it is from the connection code. i tried your last posted code and it did run to send the email, display the success message, and insert the row in the database table. the needed step would be for you to add code that checks if the query is failing or not and if it is failing, what the mysql error is.