Jump to content

DavidAM

Staff Alumni
  • Posts

    1,984
  • Joined

  • Days Won

    10

Everything posted by DavidAM

  1. The table qualifier will not be in the array key. Try this: $sid = $row['SID']; $cid = $row['CID'];
  2. At what level is your question_id unique? You are using it for the HTML field name and then assigning to the session. All of the questions would have to have an ID that is unique across ALL pages of the survey. Try putting a print_r($_SESSION) and print_r($_POST) BEFORE you assign the post variables to the session and then print_r($_SESSION) AFTER the assignment. That might help explain what is happening. Also, take a look at the HTML for each page, specifically the name attribute of each form field. By the way (not related to your question - I think) you may want to re-evaluate this code: echo '<td class="qanswer"><div class="radio" id="box-yes"><input type="radio" value="yes" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio" /></div></td>'; echo '<td class="qanswer"><div class="radio" id="box-no"><input type="radio" value="no" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio"'; $field_name = 'qid_' . $question['question_id']; if (isset($_SESSION[$field_name])) { echo ' checked="checked"'; } echo ' /></div></td>'; It looks like you are assigning the CHECKED attribute to the NO radio if the field is set. Shouldn't that be assigned to the YES field?
  3. [QSA] --> Query String Add RewriteRule ^([A-Za-z0-9-]+)/?$ /steve/index.php?page=$1 [NC,QSA] If I understand the documentation correctly, that means to add the existing query string parameters to the rewritten url
  4. Are you trying to round to one decimal place, and then display it to two decimal places? number_format(round(12.34, 1), 2);
  5. The page is running forever. You are not actually incrementing the loop variable. Try this for the loop: for($grade = 0; $grade < 80; $grade += 10){
  6. To pad with leading zeros, put a zero after the '%' character: echo printf("%08X", $i) ."=". $string ."<br/>"; WHY are you echo-ing printf()? printf() prints a string and returns the length of the string. So the way you have it, it would be printing the hex-string, then the length of that string, then the '=' and the $string. You could do that statement as: printf("%08X=%s<br/>", $i, $string);
  7. Yeah, I usually run with it off. But I did some testing so I would know what is and isn't affected, just in case I find myself in a position where it is on and I can't turn it off. And, for the record, I would never recommend using an HTML field name with any special characters in it (that just seems like ); I only tested it out of curiousity. From the documentation, I gather that the other magic quotes setting (magic_quotes_runtime) would affect the actual data in the file. I haven't tested it (but I guess I should). The documentation indicates it will affect data from most external sources (disk files, database, etc). As to the Windows thing. I hope I never have to run a webserver on Windows. Even so, I don't understand why the filename gets mangled. I've seen posts from people having trouble on a WAMP stack with filenames. But I don't understand why it happens. The name of the user's file is just data, it has no significance in the POST data at any point. Changing it because it is not a valid filename is just wrong (IMHO). As we all learned (I hope) from magic quotes, data should be sacred. It should never be changed by any underlying transport. It is the programmer's responsibility to validate and cleanup or reject all data.
  8. While the documentation does not indicate it; I have run some tests and the magic_quotes_gpc setting does affect the FILES array. And by the way, it affects the field names (the array keys of GET POST COOKIE and FILES) as well as the field values. <?php /* Quick test of file upload with magic quotes */ if (isset($_POST['submit'])) { print('<PRE>'); print('POST: ' . print_r($_POST, true) . PHP_EOL); print('FILES: ' . print_r($_FILES, true) . PHP_EOL); print('</PRE><HR>'); } ?> <FORM method="POST" action="" enctype="multipart/form-data"> Note: <INPUT type="text" name="note'txt"><BR> File: <INPUT type="file" name="upf'ile"><BR> <INPUT type="submit" name="submit"> </FORM> POST: Array ( [note\'txt] => hello \'world [submit] => Submit Query ) FILES: Array ( [upf\'ile] => Array ( [name] => test\'me.sql [type] => text/x-sql [error] => 0 [size] => 0 ) [upf'ile] => Array ( [tmp_name] => /tmp/phpVUpDEP ) ) That last entry is interesting. It didn't affect the field name for that one component. Best bet is to not use any special characters in the field names. PHP version: 5.2.6-1+lenny9
  9. I can write that code in two lines ... foreach (array_keys($GLOBALS) as $k) unset($$k); unset($k); of course, you realize that $GLOBALS is now gone, and you can't really get it back. And so is $_GET, $_POST, $_SERVER, etc., etc., ... Hell, I'm not really sure I'm still here!
  10. You can use a JOIN in a DELETE statement DELETE FROM Table1 USING Table1 JOIN Table2 ON Table1.job1 = Table2.job1 AND Table1.job2 = Table2.job2 Just be careful because this will delete from BOTH tables (at least that's what the manual says): DELETE FROM Table1, Table2 USING Table1 JOIN Table2 ON Table1.job1 = Table2.job1 AND Table1.job2 = Table2.job2 * Always backup your data when testing DELETE statements * This code is untested
  11. You can use an IF in a query. The syntax (for what you want) would be: SELECT * FROM private_messages WHERE ... ORDER BY IF (sender_updated = '1', sender_updated_datetime, receiver_updated_datetime) If it doesn't work in the ORDER BY, or if you want to be able to see the value used, you can add it to your SELECT clause, give it an alias, and ORDER BY the alias: SELECT M.*, IF (sender_updated = '1', sender_updated_datetime, receiver_updated_datetime) AS SortDate FROM private_messages AS M WHERE ... ORDER BY SortDate (Note: mySql seems to require an alias on the "*" when adding other fields to the select list, so I put the "AS M" and "M." in there.)
  12. See the PHP online documentation for break So in your case it would be: for( $i = 0; $i < 10; $i++ ) { switch( $i ) { case 1: break; case 2: // break from loop here break 2; case 3: break; } }
  13. Are you sure the zip file is in the directory with the script? Turn on error reporting. (Add these two lines immediately after your openning PHP tag: error_reporting(E_ALL); ini_set('display_errors', 1); Post any messages you receive along with your current code.
  14. What version of PHP are you using? The reference in a foreach was added in version 5. If you are using version 4, you will have to use PFMaBiSmAd's second suggestion to affect the array: foreach ($S as $key => $cluster) { $S[$key][0] = 'new value'; } Do you have error reporting turned on? Are you getting any errors, warnings or notices? error_reporting(E_ALL); ini_set('display_errors', 1); Also, you do realize you are changing $S not $C1, right? The assignment of $C1 and $C2 to $S makes a copy of those arrays. If you are trying to change $C1 and/or $C2, you need to put references in $S: $C1 = array (174,30); $C2 = array (165,80); $S = array(&$C1, &$C2);
  15. I really think your problem is here (in copy_zip_file()): // THIS $new = '/folders/$folderName/test.zip'; //SHOULD BE THIS $new = "folders/$folderName/test.zip"; That is not the same path where you just created the folder. The slash "/" at the beginning of the path indicates the root of the server's filesystem, I seriously doubt that that is the path to your folders directory. Remove that first slash and use double-quotes and you should be golden. Also, you are using "smart quotes" (which I don't think are really that smart ...) in the extract_zip_file() function. See the ones that are leaning to the right or left? They need to be single quotes or double-quotes like they are in the rest of your code. (The ones with variable names in them, need to be double-quotes): function extract_zip_file(){ $zip = new ZipArchive; $res = $zip->open("folders/$folderName/test.zip"); // This line if ($res === TRUE) { $zip->extractTo("folders/$folderName/"); // This line $zip->close(); echo 'ok'; // This line } else { echo 'failed'; // This line } }
  16. Watch out when you do that. After the loop finishes, $cluster still refers to the last element of the array. If you decide to use that variable again you will be affecting the array. It is a good idea to unset() the loop variable ($cluster) immediately after the loop to prevent unwanted side affects. (This one bit me the other day and it took me a while to track it down). $C1 = array (174,30); $C2 = array (165,80); $S = array($C1, $C2); foreach ($S as &$cluster) { $number = '5000'; $another_number = '4565'; $cluster[0] = $number; } // unset($cluster); # Really need to unset the reference here // more code that does other stuff foreach ($somethingElse as $cluster) { // You have now put the first element of $somethingElse into the $S array above
  17. Follow joel24's advice, let's see what the script is receiving. Also, do you have any other fields defined inside that FORM tag? Like maybe one called "action"? I don't see any in the code you posted, but if you only posted part of the form, check it and make sure you are not using form field names that are the same as the variables in your query-string in the ACTION phrase. If you do need both, you can POST the form to get the fields in $_POST and still get the query-string in $_GET (of course $_REQUEST will be hosed). Edit: I do NOT recommend this except in very special circumstances.
  18. Since any kind of join will likely include multiple occurrences of the same row from one table or the other, I would tackle this as a union. So first, the two queries needed to get the data: SELECT memID, COUNT(RefID) FROM Website WHERE DATE(`Date`) = '2010-12-27' GROUP BY memID -- AND SELECT memID, COUNT(VisitID) FROM Profile WHERE DATE(`Date`) = '2010-12-27' GROUP BY memID Note 1: Just to make the intention clear, I count the primary key instead of '*'. This may improve performance on this type of query in general anyway (depending on your indexes). Note 2: I changed the date selection slightly, if the column 'Date' is a DATETIME type, we need to look at only the date part. I forgot about this in my previous response. Although, if the column is indexed, using BETWEEN (i.e. Date BETWEEN '2010-12-27' AND '2010-12-27 23:59:59') may allow the server to use the index whereas (I think) the above form will force a table scan. Now we can create a union from these and with a little magic, get your desired results: SELECT memID, SUM(RefCnt) AS Referals, SUM(VisCnt) AS Visits, SUM(RefCnt + VisCnt) AS Total FROM ( SELECT memID, COUNT(RefID) AS RefCnt, 0 AS VisCnt FROM Website WHERE DATE(`Date`) = '2010-12-27' GROUP BY memID UNION SELECT memID, 0, COUNT(VisitID) FROM Profile WHERE DATE(`Date`) = '2010-12-27' GROUP BY memID) AS Counter GROUP BY memID Since all SELECTs in a UNION must return the same number of columns, with the same data types in the same order, we added the 'Visits' count into the first SELECT as '0' (zero). Then we added the Referals count in the second SELECT as zero. We don't have to alias the columns in the second SELECT because the column names in a UNION will come from the first SELECT statement. When you tweak this, tweak the inner SELECTs to limit the data you are counting (i.e. WHERE). Tweak the outer statement to limit the data returned (i.e. HAVING, LIMIT) I don't have an environment to test with here at the office, so you may have to work with that a bit (see MySql.com for syntax). Oops, I missed the part about last month. Rather than use DATE() functions on a column in the WHERE clauses, I would determine the Start and End dates in PHP and use BETWEEN in the SQL. As I said, this will allow the server to use an index (if one is defined) on the Date column. For pure SQL, you could determine these values using some of the many DATE functions in SQL. Maybe something like: WHERE `Date` BETWEEN DATE_FORMAT(NOW(), '%Y%m01') AND DATE_FORMAT(LAST_DAY(NOW()), '%Y%m%d235959')
  19. 1) [This is not causing your problem] You don't need to put double-quotes around variable names $dbconnect = mysql_connect($dbhost, $dbuser, $dbpwd); mysql_select_db($dbname); 2) As joel24 said, you need quotes around the literal "Rotating" (unless it is a column name) 3) Never use the @-sign to hide errors. It will leave you thinking everything is fine. if (! mysql_query("UPDATE usersites SET state = 'Rotating' WHERE id = '$id'")) { echo "UPDATE failed, fix it"; // Or some other code to be done when we can't process the request } 4) I have never heard of a FORM METHOD of LINK. Shouldn't that be GET? 5) Try adding a target to the FORM tag - this should cause it to load over the entire document instead of loading in the current frame echo "<FORM METHOD=\"GET\" ACTION=\"SiteManager.php?action=approve&id=$id\" target='_top'>"
  20. -- Basic query SELECT memID, COUNT(*) AS Referals FROM R_Website GROUP BY memID ORDER BY COUNT(*) DESC -- Add this (after FROM clause) to limit to a specific date WHERE `Date` = '2010-12-27' -- Add this (after the GROUP BY phrase) to get only those with more than 1 referral HAVING COUNT(*) > 1 -- Add this (at the very end) For a Top 10 List LIMIT 10 So, a TOP 10 List of multiple referrals for Today would be: SELECT memID, COUNT(*) AS Referals FROM R_Website WHERE `Date` = '2010-12-27' GROUP BY memID HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC LIMIT 10 Note: I assumed your Date field is defined as an DATE (or DATETIME) field in the database.
  21. I think your problem is trying to include the hyphen in a character class. preg_match('/^[a-zA-Z0-9 -\']{3,40}$/i', $business); That dash you have is allowing SPACE through SINGLE-QUOTE. To use a literal dash in a character class, put it first or last or escape it: preg_match('/^[a-zA-Z0-9 \-\']{3,40}$/i', $business);
  22. You might try testing to see if you are in CLI (command line) mode and only do the redirect if you are not: if (php_sapi_name() != 'cli') header('Location: http://www.example.com/index.php'); OR check for one of the $_SERVER array elements that are only present when running from the browser, such as if (isset($_SERVER['DOCUMENT_ROOT'])) header('Location: http://www.example.com/index.php');
  23. The error says that the parameter ($row) to extract is not an array. Since $row is assigned from mysql_fetch_array() we know it will either be an array or it will be a boolean value of false. Since it is not an array, it must be false. mysql_fetch_array() will return false if there is no row to fetch. Since mysql_query() did not error off (which would have caused the "or die()" to execute), we know that the query is syntactically correct but did not return any rows. The most likely reason would be the JOINs or the WHERE clause. Since the WHERE clause is shorter (and I don't know the table structure) we look closely at that. You have: "... WHERE deceasedlist.ID = '$_GET[iD]'"; When you put a variable inside a double-quoted string, PHP should interpret that variable and replace it with the value. One caveat is that when the variable is complex (like an array) you have to put curly braces around the variable so PHP can recognize it and delineate it correctly. However, in this case, curly braces alone may not fix it. You have the array index as ID, unless you have a defined constant named ID somewhere above this code, that line is in error (ok, it's a warning, but those are bad, too). (I'm not sure that PHP will recognize constants in a variable in a double-quoted string, I've never tried it.) You need to put single-quotes around the ID index so PHP can correctly evaluate your variable. So that part of the query should be: "... WHERE deceasedlist.ID = '{$_GET['ID']}'"; Having said that, I highly discourage the use of user supplied data directly in a query. This leaves you open to SQL injection attacks. You need to sanitize that value and make sure it is something you are expecting. If the deceasedlist.ID column is an integer, I would (at the very least) use something like this: $id = intval($_GET['ID']); $query = "... WHERE deceasedlist.ID = '$id'";
  24. It IS possible to call a function as a parameter to another function call. HOWEVER, the function (as a parameter) has to resolve completely BEFORE the outer function is called. So the object will NOT exist when the (parameter) function is called. [by the way, the way you have it written obtainDownloadFileName() is a normal function call NOT a class or object method call] You could pass the method name as a string and have the constructor call it: class clsTryme { function __construct($funcToGetFile, $table) { $this->fileName = $this->$funcToGetFile(); $this->table = $table; } function getGeoFile() { return 'geo_file.zip'; } } $obj = new clsTryme('getGeoFile', 'table1'); or just have the constructor call the method without passing it in: class clsTryme { function __construct($table) { $this->fileName = $this->getGeoFile(); $this->table = $table; } function getGeoFile() { return 'geo_file.zip'; } } $obj = new clsTryme('table1'); IF your getGeoFile() method is a STATIC method, then you can call it in the call to the constructor: class clsTryme { function __construct($filename, $table) { $this->fileName = $filename; $this->table = $table; } static function getGeoFile() { return 'geo_file.zip'; } } $obj = new clsTryme(clsTryme::getGeoFile(), 'table1');
  25. echo "<td><fb:like href=\"$http$ids\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>"; Since you are trying to combine variables INSIDE of a double-quoted string, the dot (".") concatenation is not the answer. You need to separate the variables with curly-braces so PHP will know that they are two separate variables. echo "<td><fb:like href=\"{$http}{$ids}\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>";
×
×
  • 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.