DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
I think the hash needs to come before the query string href="search.php#start?ID=blah blah blah" Also, I think some browsers use the anchor's ID rather than name, so make them both the same <A id="start" name="start"></A> However, I don't see the problem. It has been my experience that pages always display from the top when you click on a link that goes to a new page (unless the page intentionally scrolls itself using javascript or something). Why do you think you need to tell it to go to the top of this page?
-
Close. Try: while($row=0; $row<=10; $row++) { for ($col = 1; $col <= 10; $col++) { $key = 'col_' . $col; $sm_array[$row][$key] = $td->innertext; } }
-
To reference an array element inside of a quoted string, you have to use curly-braces. Also, I don't know if the closing php tag is being interpreted or not. I don't think it should be, but I know PHP will interpret it inside a comment, so you could split it up. $output = "<?php if(isset({$_POST['Bijwerken']})) { header ('Location: http://localhost/Perfect/creategallery.php/creategallery.php'); exit; } ?" . ">";
-
You do realize that add_filter('the_content', 'in_this_instance'); is most likely, not actually executing the function in_this_instance(). I have no experience with wordpress, but from your description, you are providing a callback function for the wordpress process to use. It will call that function when it is ready to - must likely NOT when you add it as a filter. As a result, your global variable is not going to get updated immediately after adding it to the filter list. Whatever it is you want to do when $in_this_instance is true, should probably be done inside your function.
-
If your cron job typically does not produce any output, how do you know it ran? I have a job that runs everyday at a set time. If it finds a problem it sends me an email. If there are never any problems, I would never get an email, and I would not know if everything is fine, or the cron job is just not running. So I have it check what day of the week it is. On Friday, if it does not find any problems, it sends an email telling me it ran and everything is fine. If I don't get that email on Friday, then there is a problem with the cron job. If you have multiple jobs that run at various times (daily, hourly, etc) you might consider having each job log its last completion in a table in the database. Then add one more job that runs weekly and checks the database table. If a job did not post its log, it can send an email to let you know which one to check on. If everything is fine, it should send an email telling you that (so you know it is running).
-
To protect against SQL injection attacks, use the mysql_real_escape() which will escape any characters that might cause problems with the database access. If you are not using mysql, the use some other appropriate function for your database. The htmlspecialchars() function will protect you from HTML and SCRIPT injections since the code will be displayed and not interpreted. There may be other things to do, there are a lot of topics on this site about sanitizing user input.
-
Call htmlspecialchars() just before the bbcode replacements: <?php $text = htmlspecialchars($text); $bb_Code = array( '[ code]' => '<code>', '[ /code]' => '</code>' ); foreach ($bb_Code as $value => $replace) { $text = str_replace($value, $replace, $text); } ?> To me, it seems best to store the data in the database exactly as entered by the user (especially, if you are going to let them edit it later). Then do the (htmlspecialchars() and) bbcode changes just before displaying it on a page - but not before presenting it in a textarea for the user to edit.
-
There MUST be a way to erase a previously saved checkbox array!
DavidAM replied to ThunderVike's topic in PHP Coding Help
Glad to help. You might want to mark the topic as solved. There's a green button at the bottom of the page (a couple of lines below the REPLY line). That way, someone searching for checkbox arrays will know there is a solution to the problem. Good luck with the site. -
There MUST be a way to erase a previously saved checkbox array!
DavidAM replied to ThunderVike's topic in PHP Coding Help
Try using an if(! empty() at the begining of each loop: if($results) { foreach ($results as $result) : // now grab all ad fields and print out the field label and value if (! empty($result->meta_value)) { echo '<h4>' . $result->field_label .'</h4> <br> <ul>' ; $options = explode(',', $result->meta_value); foreach ($options as $option) { ?> <li><?php echo $option; ?></li> <?php } echo '</ul> <br> <div class="clr"></div>'; } endforeach; } Although you may have to check the field_label to make sure you are only skipping the checkboxes. That is, if there are other fields that will appear in the foreach($results ... -
There MUST be a way to erase a previously saved checkbox array!
DavidAM replied to ThunderVike's topic in PHP Coding Help
Well, I'll take a swing at it. I read through your other post the other day, and I figured yall were on the way to solving it. First, I have a question. This code is a little confusing. In the second IF statement, you refer to checkbox_charley AND checkbox_help - is that correct, or should they both be CHARLEY? if($post_id) { // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) if (cp_str_starts_with($meta_key, 'cp_checkbox_charley') && is_array($_POST['cp_checkbox_help'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else if (cp_str_starts_with($meta_key, 'cp_checkbox_charley') && is_null($_POST['cp_checkbox_help']))$meta_value= NULL ; if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) $meta_value = implode(',', $_POST['cp_checkbox_help']); if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) $meta_value= implode(',', $_POST['cp_checkbox_hello']); //echo $meta_key . ' <--metakey <br/>' . $meta_value . ' <--metavalue<br/><br/>'; // for debugging update_post_meta($post_id, $meta_key, $meta_value); } At any rate, I would think you need to assign an empty string to $meta_value if no checkboxes are checked. When no checkboxes (in that array) are checked, the array will NOT be set. So I would think that this would work: ... No, that's not going to work. If the checkbox array does not exist (because nothing is checked) then the "foreach ($_POST ..." is NOT going to come across the checkbox array and it will never clear it. I guess the easiest thing to do would be add a couple of lines before the foreach: if($post_id) { // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } Of course, I have not worked with WordPress so I have no idea what is going on behind the scenes. Also, I am at work and have no way to test this code. You may not even need the IF (ISSET inside the loop. I think implode() will return an empty string if run on an empty array. I think you can add to the $_POST arrray like that, I don't see any reason why you couldn't. But that is the problem, you are not finding the empty array inside the foreach. -
1) If there is a possibility that there are duplicate codes and you don't want the duplicates, you may want to look at array_unique() 2) I'd be careful naming the file 'newfile.txt' -- If you run the script a second time, the glob() call will include this file and you will double your data. Either give it a different extension, or delete it (unlink()) before the call to glob(), or specifically exclude it within the loop.
-
How can I make a proper multi-level thread using parent-child? ...
DavidAM replied to euphora's topic in PHP Coding Help
With a single button to post a reply, how are you going to know which entry they are replying to? If you want to allow replies directly from the list that you have now. You need to add a link at the end of each list entry. It would be something like: <A href="replyPage.php?replyto=idOfTopic&level=levelOfTopicPlus1">Reply</A> replyPage.php would then use $_GET['replyto'] to get the ParentID of the new post; and use $_GET['level'] to get the level of the new post (make sure you have already added 1 to the topic's level when you build the link (or don't and add it in the reply page)). Actually, if you are only using the level for the output indentation, you don't need it in the database. You can pass it to the initial call of showChildrenOf() and then each resursive call would pass the level it got plus 1 to the next call. Something like this: function showChildrenOf($parent_id, $level_in) { $qry = "SELECT * FROM test_db WHERE parent_id = '$parent_id' Order by date DESC"; $res = @mysql_query($qry); while ($levelObj = @mysql_fetch_object($res)) { $level_pid = $levelObj->post_id; // Gets PostID // INSTEAD OF THIS LINE // $level = 1.75 *($levelObj->level); // lvl 2: 3em // USE THIS LINE $level = 1.75 * ($level_in); //echo 'test'; //if ($level_pid === $pid) { echo '<div style="text-indent:' . $level . 'em">' . 'PostID: ' . $levelObj->post_id . ' || ParentID: ' . $levelObj->parent_id . '</div>'; //} showChildrenOf($levelObj->post_id, $level_in + 1); } } //require_once('db_connection'); echo '<hr><hr><br>'; // I just realized that selecting * where parent id is null might limit the amount of rows retrieved. // Query to select threads $q = "SELECT * FROM test_db WHERE (test_db.name_id = '1427') Order By date ASC"; $r = @mysql_query($q); while ($threads = @mysql_fetch_object($r)){ $pid = $threads->post_id; $sid = $threads->subject_id; $parent_id = $threads->parent_id; $title = $threads->title; $body = $threads->body; if ($parent_id === NULL) { echo '<div>PostID: ' . $pid . ' || Parent: ' . $parent_id . ' || SubjectID: ' . $sid . ' || Title: ' . $title . ' || Body: ' . $body . '</div>'; showChildrenOf($pid, 1); // $pid instead of $parent_id } } By the way, this code is not producing anything different than selecting from the table with parent_id IS NULL. You are skipping the ones that are null, so you may as well just not select them. Performance would be better as the database grows. Also, you probably want an INDEX - not unique - on the parent_id column to help with performance down the road. -
How can I make a proper multi-level thread using parent-child? ...
DavidAM replied to euphora's topic in PHP Coding Help
The second code you posted does 3 levels. Period. But the second and third levels are basically the same code, so you could keep copying it to make it how ever many levels you want. If you replace the second and third levels with a call to the function I showed, it will go to an infinite number of levels (theoretically - you will be limited by memory and PHP timeout constraints). function showChildrenOf($parent_id) { $qry = "SELECT * FROM test_db WHERE parent_id = '$parent_id' Order by date DESC"; $res = @mysql_query($qry); while ($levelObj = @mysql_fetch_object($res)) { $level_pid = $levelObj->post_id; $level = 1.5 *($levelObj->level); // lvl 2: 3em echo '<div style="text-indent:' . $level . 'em">' . 'PostID: ' . $levelObj->post_id . ' || ParentID: ' . $levelObj->parent_id . '</div>'; showChildrenOf($levelObj->post_id); } require_once('db_connection'); echo '<hr><hr><br>'; // I just realized that selecting * where parent id is null might limit the amount of rows retrieved. // Query to select threads $n = NULL; $q = "SELECT * FROM test_db WHERE (test_db.parent_id is NULL) Order By date ASC"; $r = @mysql_query($q); while ($threads = @mysql_fetch_object($r)){ $pid = $threads->post_id; $sid = $threads->subject_id; $parent_id = $threads->parent_id; $title = $threads->title; $body = $threads->body; echo '<div>PostID: ' . $pid . ' || Parent: ' . $parent_id . ' || SubjectID: ' . $sid . ' || Title: ' . $title . ' || Body: ' . $body . '</div>'; showChildrenOf($parent_id); } Note: Again, I just copied your code there and I do not have any way of testing it here, but it should get you started down the right road. The '@' operator hides error messages from you. When applied to a statement, if the statement generates any errors, those errors will not be caught or reported. In my opinion, it is better to leave it out, correct any errors during development as they occur, and test the inputs before a function call and the outputs after a function call and handle any exceptions in a user-friendly manner. -
How can I make a proper multi-level thread using parent-child? ...
DavidAM replied to euphora's topic in PHP Coding Help
If you notice, your "q3" (level 3) code is exactly the same as your "q2" (level 2) code, except you had to use different variable names. This is a great opportunity for a function! You are going to have to write a recursive function here. That's just a normal function that calls itself. So, after you output your top level posts (parent_id IS NULL) you would call a function to show its children. The function would output each child and call the function to output its children. Eventually, you should reach a point where there are no more children and it will unwind. Something along these lines: function showChildrenOf($parent_id) { $qry = "SELECT * FROM test_db WHERE parent_id = '$parent_id' Order by date DESC"; $res = @mysql_query($qry); while ($levelObj = @mysql_fetch_object($res)) { $level_pid = $levelObj->post_id; $level = 1.5 *($levelObj->level); // lvl 2: 3em echo '<div style="text-indent:' . $level . 'em">' . 'PostID: ' . $levelObj->post_id . ' || ParentID: ' . $levelObj->parent_id . '</div>'; showChildrenOf($levelObj->post_id); } Note: I just copied your code and made minor changes. I do not recommend or endorse the user of the '@' operator. You need to check $res before the while loop to make sure it has a value. -
PFMaBiSmAd is correct BUT you should also fix the error ( in my book a notice is an error ) if ( (isset($_SERVER["HTTPS"])) and ($_SERVER["HTTPS"] == "on")) {$pageURL .= "s";}
-
You shouldn't be getting a count for each video AND the # of keywords ... you only return 1 column. Using your sample data, I think you are getting 6 (3 with 'word1' and 3 with 'word2'). If you changed it to IN ('word1', 'word3'), I think you would get 5. That is still more videos than you have in your table. If what you want is the number of unique videos that have any of those keywords, I think you need to use: SELECT COUNT(DISTINCT video_id) as Total FROM keywords_videos ON videos.id = keywords_videos.video_id JOIN keywords ON keywords_videos.keyword_id = keywords.id WHERE keywords.word IN('word 1','word 2') You don't really need the videos table in the query, you just want a count of the IDs. Using COUNT(DISTINCT) will only count each video_id once regardless of how many of the keywords it has.
-
The date() function: http://us3.php.net/manual/en/function.date.php
-
#1 - The "Cannot modify header ..." errors are most likely a result of the other error messages. You can ignore them until you get the other errors cleaned up. #2 - The "Deprecated ... " messages indicate that the script is using a function which has been depricated. This means that some future release of PHP will NOT contain that function and your code will quit working (again). You have two choices: 1) turn off deprecated messages or 2) change these function calls to use the recommended replacements for the deprecated functions. See the php manual at http://www.php.net/manual/en/index.php for help on these functions. Note: turning off the Deprecated messages is a short-term work-around. #3 - The "strlen function expects ..." indicates that one of the parameters passed to that function are not the expected type (it tells you which one). This indicates that $string is not a string (might be an array, or object, or null, or something). Since this variable is passed in to the smarty_modifier_myescape() function, you will have to look at where that function is called to see what is wrong with the "string". It is possible that this variable is not getting assigned because of one of the other errors, and fixing those errors will make this one go away. #4 - You cannot login to the admin panel - this is likely a cause of one of these errors. One of the script files you added is probably getting included and it is throwing errors. I highly recommend you reconsider using this script. It is using OLD functions and ignoring NEWer functions. For instance, the four calls to str_replace() could be replaced with one call to str_ireplace() which is a PHP5 function (so this code was written for PHP 4 or earlier). It could be the code is still there to allow support for PHP4 users, or it could be that the script is not being maintained. The continued use of the deprecated functions indicates (to me at least) that it is not being maintained. See if the provider has a PHP5 version of the script since you are obviously using PHP5. Otherwise, read the line numbers presented in the error messages, find that line of code, fix the error, and try again. If you run into problems or questions fixing specific lines of code, you can post the code and what is happening and we may be able to offer solutions. Be aware, if this script IS being maintained, and you start making changes to it, it will be next to impossible to "upgrade" if the provider issues a newer version of the script. If at all possible check with the script provider to see if they have a PHP5 version of the script. If they say to just turn off Deprecated messages, ask if they PLAN to issue a PHP5 script. If you turn off deprecated messages, and your host upgrades to PHP6 (whenever it is released) your script will break again on any deprecated functions that have been removed from PHP6.
-
Create a new database named "restoreData" or something. Change the database name in the .SQL file (to this new database name) Load the .SQL file so it goes into the new database. Run queries to update the data from one database to the other. For instance: INSERT INTO newDatabase.tableName SELECT * FROM oldDatabase.tableName WHERE ID = missingIDvalue; will let you copy data from one to the other. HOWEVER -- I do NOT know the database structure and table structures and cannot advise as to which rows/tables need to be moved. If you are not careful, you will clobber the current database. I would highly -- VERY HIGHLY -- recommend, creating a COPY of the current database on a development platform, then test your update process against it. Then test the application against the updated database, thouroughly. When you are satisfied that it works, and ALL vBulletin checks come up clean, then BACK UP THE FUNCTIONING DATABASE and run your entire process against it. You will want to lock out the users while you are updating the database if possible (at least I would want to). Edit: NEVER - EVER even THINK of running a database cleanup/fixup without FIRST TESTING THOUROUGHLY and BACKING UP the working database.
-
You are not checking to see if a box is checked. If any boxes are left unchecked, you will still get the ranking text box. Which will probably be empty. So you have duplicate values (empty). You might try something like this: // check for duplicate rating values $ranks = array(); if (isset($_POST['cvess'])) { // Is the cvess box checked? $ranks['cevss'] = $_POST['cevssrank']; } if ( (isset($_POST['occs'])) { // Is the occs box checked? $ranks['occs'] = $_POST['occsrank']; } if ( (isset($_POST['trtw'])) { // Is the trtwbox checked? $ranks['trtw'] = $_POST['trtwrank']; } if ( (isset($_POST['ppcmr'])) { // Is the ppcmrbox checked? $ranks['ppcmr'] = $_POST['ppcmrrank']; } $uniq = array_unique($ranks); if ( count($uniq) != count($ranks)) { // There are duplicate rankings ... } This may not be the "best" way to do it. But it should work. The $uniq array will only have unique entries from the $ranks array. So if all of the ranks are unique, then both arrays should have the same number of elements. You could simplify this by changing the input fields to something like this: <input value="" name="rank[cevss]" type="text" id="cevssrank" size="5" maxlength="1"> Then they will show up as $_POST['rank']['cevss'] (I'm not sure if you need quotes in the INPUT tag or not, try it out: <input value="" name="rank['cevss']" type="text" id="cevssrank" size="5" maxlength="1">
-
I have found that when working with compound conditions in an if statement it is always safer to add parenthesis around each individual condition. It does not cost much (parenthesis are really cheap these days) and it never hurts (unless you put them in the wrong place). if ( ($cevss == $occs) || ($cevss == $trtw) || ($cevss == $ppcmr) || ($occs == $trtw) || ($occs == $ppcmr) || ($trtw == $ppcmr) ) { Personally, I always use 'and' and 'or' instead of '&&' and '||'. That's just a personal thing though. The order of precedence is different between them, so you don't want to mix them in the same statement unless you know exactly what is happening.
-
If you are echoing to a webpage, the browser is seeing '<' as the start of an HTML tag. It does not know what '?php' is (it is not a known tag) so it does not display it. This is standard (required) browser behavior so that new HTML tags do not break pages in older browsers (they just get ignored). To display this text, use the htmlentities() function. It will convert any, well, HTML entities, into special codes so the browser will display them instead of interpreting them: echo htmlentities($string);
-
echo '<li>'. dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'). '<a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>'. '</li>'; if dp_attachment_image() or get_permalink() or get_the_title() are echoing, or printing or otherwise outputting text, it will appear before the output from the echo that is outputting the LI. The way this code is written, you are expecting these three functions to return a string not output a string. If these functions do in fact echo the code, you should use something like this: echo '<li>'; dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'); echo '<a href="'; get_permalink($id); echo '">'; get_the_title($id); echo'</a></li>'; which is kind of ugly; and probably whey some PHP native functions (like print_r) have a paramter called $return which can be set to true to return the string; and defaults to false to output the string.
-
Well, just for grins, try reversing the two updates, run updatequery2 first then updatequery. See which one works. Also, check all the server logs, Apache, MySql, and OS if you have access to them. At this point, I would normally delete several lines of code and retype from memory, assuming there's something there I just can't see. Sorry, I can't be more help.
-
The header() function does NOT end the script. It will continue to run. If you want to redirect immediately, you need to exit the script immediately. if (1 == 1) { header("location:1.php"); exit(); } else { header("location:2.php"); exit(); } // other code down here