ManiacDan
Staff Alumni-
Posts
2,604 -
Joined
-
Last visited
-
Days Won
10
Everything posted by ManiacDan
-
Trying to make my form send info to two different email addresses.
ManiacDan replied to KDM's topic in PHP Coding Help
None of that will work. You can't single-quote PHP variables. $to = array('********@yahoo.com', '********@************.com'); foreach ( $to as $address ) { $mailSent = mail($address, $subject, $message, $headers); } -Dan -
You're still not doing it right. Take the $this-> out of the mysql_connect call, just use $host, $user, and $pass that you're passing in. Research variable scope and OOP -Dan
-
voip, please don't report a post because a mod has moved it. You are not understanding the basics of client-server web programming. Read carefully: PHP - PHP is a server-side language that only executes on the SERVER. It can only run code on your server, and cannot run code on the client. A PHP page will execute entirely and then die before ANY content is shown to the user. JavaScript - JavaScript is an entirely separate language. Read that again. JavaScript is a programming language that has nothing to do with PHP. It is interspersed into HTML code for convenience. It runs on the CLIENT machine. It cannot run on your server. Any javascript on your page executes AFTER the PHP is already dead. JavaScript can trigger FURTHER PHP events, but they do not run in tandem. Your problem is that you want something to happen when the user clicks. This can be accomplished in two ways: 1) Reloading the page entirely by pointing it to a new URL. This is not what you want, but this is the default behavior for clicking a link. 2) Trigger the onClick javascript even, in javascript, on the client's machine ONLY. This has the capacity to call PHP scripts through AJAX, but you must use javascript to perform client-side operations. Now, given this information, continue the discussion. And as a side note, for the love of god use complete sentences and real words. The quality of help you receive is directly proportional to how easy your posts are to read. See how mine is all spelled correctly and the sentences are complete? -Dan
-
Learn to help yourself and this will all be easier. 1) The error message gives you a function that's failing as well as a line. Find it. 2) There is one occurrence of implode() in your code, that must be it. 3) The error also indicates what's wrong: invalid arguments 4) Implode takes two arguments: a string and an array. 5) Of the two arguments you're passing it, one is a bare string and one is a variable. 6) Therefore, the variable is the problem. You (and your code) expect it to be an array, but clearly it is not. 7) Trace upward from there to find out what that variable actually is and either 8a) Fix the code so the variable is an array like it needs to be 8b) Wrap your code in an error-handling condition so that it does not try to call this implode() function or the related code if the variable is not an array. -Dan
-
Restore the theme to its original settings, without your modifications. Does it work? If so, your modifications send data (and therefore headers) prematurely. -Dan
-
Javascript runs on the user's computer. PHP runs on your server. So no, there is no way to modify the contents of the user's computer with PHP, you have to completely reload the page.
-
Don't ever use variable variables unless you're absolutely certain there's no other way to go about doing things. If you ever have variables with sequential numbers at the end, you've done it wrong. The Array construct is perfect for what you're trying to do. -Dan
-
Capitalization matters. -Dan
-
You're looking for arrays -Dan
-
Also, this function you posted creates a new random salt every time it runs if you omit the second argument. That means it cannot be used for passwords without the second argument, because each time you run it it will produce a different password. -Dan
-
Quiz slidehsow with questions and need to capture the answers
ManiacDan replied to venkyzrocks's topic in PHP Coding Help
Look into AJAX. It's much more complicated, but follows the same basic structure I set out above. -
It's not 8601. You can use substr for this, or a regular expression: $string = 'P0DT0H4M14S'; preg_match('/P(\d+)DT(\d+)H(\d+)M(\d+)S/', $string, $foo ); echo "{$foo[2]} Hours, {$foo[3]} Minutes, {$foo[4]} seconds."; -Dan
-
A hash is a one-way function that turns an existing string into another string. It cannot be reversed. It's commonly used for uniqueness checks, passwords, and array keys. Basically what this function does is take a password like "abc123" and turn it into a hash. With the hash, you cannot recover the original password. What you have to do is: - When the user creates a new password, store the hash in the database. - When the user attempts to log in. - Take the password they gave and translate it into a hash. - Compare the hash you just made to the hash in the database. - If they match, log the user in. This way, if someone breaks in and steals your database, they'll never get the passwords themselves, only the (useless, one-way) hashes. If you wish to have a password-reset functionality, have a script that changes the user's password to a NEW password and emails it to them. Better yet, allow them a one-time code to change their password without knowing what the old password was. Also, ALWAYS use this function you posted with a salt (with a second argument) if you're planning on using it for passwords. If you let the function generate its own salt, the hash will be different every time. -Dan
-
Quiz slidehsow with questions and need to capture the answers
ManiacDan replied to venkyzrocks's topic in PHP Coding Help
Look into the PHP session, it is how you maintain state in an applcation. Print question 1, and have the answer "submit" to the same page. Store the "current" question in the session (or in a hidden variable in the form itself). Print the next question when you receive the answer to the previous question. It can all be done in one page: $nextQuestion = 1; if ( isset( $_POST['answer'] ) ) { //record their answer in the db. $nextQuestion = $_POST['questionId'] + 1; } //select and display the question in $nextQuestion, including the questionId in the form. //If there is no next question (you've hit the end of the test), display the score or "thank you" or whatever As you can see, you don't need sessions for this, but you could use the session as a temporary data store for the answers until the quiz is complete (avoiding a round-trip to the database). -Dan -
PFMaBiSmAd's solution gives you the field name, Pikachu's solution gives you the two highest frequencies. The former is probably what you're after. If you want the value AND the frequency, just combine the two: SELECT field, COUNT(field) as frequency FROM table GROUP BY field ORDER BY COUNT(field) DESC LIMIT 2 -Dan
-
You need to get your terminology straight, and be a little more clear. A "row" and "result" are the same thing. Are you saying you want a PHP script that selects a single COLUMN (not row) from a database table and spits out a select box with every value from that column? What have you tried so far? Do you know how to query a database and/or print HTML from PHP? -Dan
-
Or you could pay Meebo for it. Hint: This is really really hard, too hard for you, and very expensive.
-
You're not actually RUNNING these queries. Right now you just have strings and you're trying to see if the password is equal to the full SELECT statement to view the password. That would be a funny coincidence, but is not what you want. Also, don't do passwords like this. Use a one-way hash like sha1 with a salt to encrypt the password so you cannot view them and nobody can steal them. -Dan
-
Warnings are not, strictly speaking, errors. A warning tells you that your code is designed wrong. In this particular instance, PHP is letting you know that you're not checking to see if an array element exists before you try to use it. $form_value will indeed be null, because you've accessed an array element that doesn't exist. More correct code: $form_value = null; if ( isset( $_POST['form_value'] ) ) { $form_value = $_POST['form_value']; } //or more simply: $form_value = isset( $_POST['form_value'] ) ? $_POST['form_value'] : null; Also, this code is wrong: $attendeeName = $form_value = ''; Don't chain assignments like that, it's ambiguous and wastes memory. edit: unless of course you're doing this specifically to empty both variables, then it's fine. If you ever do something like $a = $b = "something"; that's a waste. -Dan
-
This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=332001.0
-
Step 1 then is "learn PHP." Sorry. You'd use a combination of preg_match, strpos, and substr. -Dan
-
1) Yeah, sure. Generally I save a hash of IP, user-agent, username, and unique ID in the cookie. 2) You don't need to, generally, but yes. -Dan
-
\ is a special character that "escapes" the character after it. You're probably familiar with it already, it's now you do strings with quotes in them: 'This is a string with a single quote, isn\'t it nice that we can have one like this?' To get a literal backslash, double-escape it: SELECT REPLACE('google.com\\', '\\', '/'); Note, however, that this doesn't fix the table. -Dan
-
Have you tried looking at the Google APIs for Calendar? I'm sure there's something there. To answer your question: 1) No, you cannot simply demand a specific div from a site, it's all or nothing. 2) Once you get it ALL, you can use a programming language like PHP to pull only the DIV you want. This would unfortunately require your PHP script to log in to google calendar, however. -Dan