DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
That error message seems to indicate there is an error in the configuration file. Are you sure that -x is the correct switch to terminate the daemon? I would expect those type of errors to appear at startup. You did not capture the output from -s so I'm a bit confused. Unless you changed your code between your last two posts. Hint: Paste the print_r results in a [ code ] [ /code ] block to make it easier to read (that's the button with the hash-mark on it)
-
Perhaps the csf daemon is monitoring its configuration directory to prevent a mischievous program from altering it in a way that would allow a program to exploit it. If you stop the daemon and chmod/chown the directory, does it "automatically" change back? If it does not change back and you then start the daemon, does it stay changed or change back? There might be a line in the configuration file that specifies what the directory permissions should be. You may have to write a script that will stop the daemon, replace the config file, and then start the daemon. It should not be down for too long, but you will have to watch out for the possibility that the start fails, leaving you unprotected. I would definitely not leave the directory as world writable (777) since that would leave you open to an attack that does exactly what you are trying to do; i.e. replace the configuration file.
-
There is a big difference between "updates his records" and "new added records". Are you saying you used an INSERT statement and want to return the rows that were inserted? If the records were INSERTed, and the table has an AUTO_INCREMENT column, you need to capture the value of that column after the first INSERT and return all rows >= (greater than or equal to) that column. Note that it is possible other users inserted data at the same time, so you will probably want to limit the rows returned to rows created by the user. To do this, you need to have a column in the table that you put the user's ID into when the record is created.
-
Increment a value based on if variables isset
DavidAM replied to frshjb373's topic in PHP Coding Help
It would help if you would tell us what the error is. Or better yet copy & paste it into your post. The only thing I see wrong with that code is a missing right-curly brace after the last if statement. Note: it is not necessary to close and open the PHP blocks (?> <?php) blank lines are allowed in php code. You could save some typing by using $price += 2; -
Won't make a difference if I don't have the correct permissions... It will make a difference if your current path is not four levels below the root of the server. The absolute path to /etc is not going to change. I would just use an absolute path there.
-
(I (usually) do not follow links; and I (almost) never download attachments. I practice safe browsing.) The error message is pretty clear. You have a class named WhereClause that has a method named testRow that is defined with two parameters. The first is $row and the second is $rowSchema with a default value of NULL. In the file named flatfile.php you have defined a class named LikeWhereClause which is derived from the aforementioned class. In this class, at (about) line 568 you are defining (overloading) the aforementioned method (testRow) but have used a different signature --- meaning the number of parameters or their defaults are different (maybe the names have to be the same, too; I don't really remember). Personally, I don't agree with this strict standard, but I'm sure that a lot of OOP purists do. I have never studied OOP in depth, though I have used it in several different languages. And I have a book on my shelf titled Object Oriented Design and Development, and that alone, qualifies me to say I don't agree To fix this error, you will need to add the parameters to the method in the derived class so that the method signatures are the same.
-
Are you saying that the only thing in the PHP script is the Lock query? If so, then this quote from the page linked by hakimserwa applies: When the script ends, all database connections are closed. So the locks are released. Locks belong to the session/connection that acquires them. If you could lock the tables and go away, then how would they ever get unlocked?
-
I worked for equity once. Well, actually, I worked for pay, but accepted stock when they said, "there's not any money to pay you right now". Then the company reorganized and did a 1 for 20 reverse stock split; which drastically reduced the value of my shares. I now own 101 shares of a stock that might still be on the penny-stock board. I really don't know what happened to the company, I lost track of them. Yeah, I lost money, but it was a moon-lighting job, so it did not impact my living. Would I do it again? Possibly, but only if the deal were clearly defined in writing and did not involve non-preferred stock. However, if I were making my living as a freelance consultant/programmer, the answer would have to be categorically, "No". Not because I'm a mercenary; but for the same reason I wouldn't take a commission only sales job. (Aside from the fact that I can't stand selling) there is just too much uncertainty to gamble the rent money.
-
The $(this).prop('id'); call is retrieving the ID of the object that was clicked. You can inject additional "values" into the tag, but it is non-standard and may not be cross-browser friendly. I'm not sure why you would want to pass a value that you retrieved from the database since the PHP script will have access to the database during the AJAX call. However, if you really want to send multiple values to the click function, you can do something like this: <script> function sendValue(value1, value2) { $.post("include/workhours/lock_month_data.php?send=" + value1 + "&other=" + value2, function(data){ $('#display').html(data.returnFromValue); }, "json"); } </script> <?php $q1="SELECT * FROM user_meta WHERE status=1 ORDER BY display_name limit 3"; $r1=mysql_query($q1); while ($row=mysql_fetch_array($r1)){ $worker_id = $row['user_id']; $value = $row['user_id']; $value2 = $row['display_name']; echo "<a class='lockLink' id='lock_button_$worker_id' onclick=\"sendValue($worker_id, '$value2');\">".$row['display_name']."</a><div id='display'></div>"; I took out the pageInit() function and put the onClick() event directly in the tag so we could pass the values there.
-
As I said, I'm no JS expert, and there might be easier/better ways to do this. But this is how I typically do it: <script> $(document).ready(pageInit); function pageInit() { $('.lockLink').click(sendValue); } function sendValue() { linkID = $(this).prop('id'); $.post("include/workhours/lock_month_data.php?send=" + linkID, function(data){ $('#display').html(data.returnFromValue); }, "json"); } </script> <?php $q1="SELECT * FROM user_meta WHERE status=1 ORDER BY display_name limit 3"; $r1=mysql_query($q1); while ($row=mysql_fetch_array($r1)){ $worker_id = $row['user_id']; $value = $row['user_id']; echo "<a class='lockLink' id='lock_button_$worker_id'>".$row['display_name']."</a><div id='display'></div>"; ?>
-
sprintf is just formatting the string. Saves having to do concatenation (which I can never remember how to spell) or embedding variables in a string (which we can't do with function calls): $sql = 'SELECT UserName FROM users WHERE UserName = "' . mysql_real_escape_string($_POST['username']) . '"' . ' OR email = "' . mysql_real_escape_string($_POST['email']) . '"';
-
PHP form works but I need the Users Name in the Header
DavidAM replied to ajwaldrop's topic in PHP Coding Help
You might want to consider building a VCard from the data you collected and attaching it to the email. He would have to open the email and import the VCard, but it would give him all of the information from the form instead of just the name and email address. That additional data along with the knowledge of the potential pitfalls (from my previous post) might make it worth the effort to him of opening the email (one extra click). I'll admit I have never done this, and I am not sure how involved it would be, but I do know that the Vcard is just a text file and a multi-part MIME message is not that difficult to build. BEGIN:VCARD VERSION:2.1 N:Mxxxxxx;David FN:David Mxxxxxx ORG:My Company Name TITLE:Operations Manager TEL;WORK;VOICE;PREF=1:(832) xxx-xxxx TEL;WORK;VOICE:(936) xxx-xxxx TEL;CELL;VOICE:(281) xxx-xxxx TEL;WORK;FAX:(832) xxx-xxxx ADR;WORK:;;9016 Our Street;SomeTown;TX;773xx;United States of America LABEL;WORK;ENCODING=QUOTED-PRINTABLE:9016 OurStreet=0D=0ASomeTown, TX 773xx=0D=0AUnited States of America URL;WORK:http://www.ourdomain.com EMAIL;PREF;INTERNET:[email protected] REV:20110920T181435Z END:VCARD To get the VCard template, fill out a Contact record the way you want it, then select File->Save As ... (and choose the VCard filetype) or File->Export to vcard file .... You can open the file in any text editor and see the format. I did this when building the QR code for our business cards (well, I did some Googling, too). -
According to the forum Rules & ToS, you are not supposed to bump: I'm not a huge fan of lambda functions, and I'm not really a JavaScript expert; but that function sendValue() looks like it is defined in global scope. Since you are sending that script inside the loop, it looks to me like you are defining that function multiple times. I'm pretty sure JavaScript will choke on that. I think you need to re-think that setup. As it is, you are registering several document.ready() functions, which is unnecessary. I would give all of those links the same class (i.e. class="lockLink"). Then do the document.ready() call once to set them all: $(document).ready(function() { $('.lockLink').click(showValue); } (or something like that). Then in the showValue() function, grab the ID of the link that was clicked (this) and send it through AJAX to the PHP script.
-
If you choose not to remove the location.id, because of other application requirements that we are not privy to, be sure to create an index on the location.jobnumber column so your query performance will not fade as the tables increase in size. In any case, you should define an index on assets.currentjob for query performance as well.
-
PHP form works but I need the Users Name in the Header
DavidAM replied to ajwaldrop's topic in PHP Coding Help
You need to be aware that this is not the correct way to send mail. Your mail server at (say) MyDomain.com does not technically have the authority to send mail from the visitor's address at (say) HisDomain.com. In other words, specifying the visitor's email address in the FROM: header may cause problems. --- The mail is not from the visitor, it is from your website. Some mail servers will see it as an attempt to forge an email and refuse to send it. Some mail servers will see it as a forged email and refuse to deliver it, or put it in the Junk/Spam folder. The "correct" way to send email is to use the website's email address (something at MyDomain.com) in the FROM header and put the visitor's address in the REPLY-TO header. This may break your client's ability to "drop" it on a new contact record, I have never tried to do that. However, you need to keep this in mind since moving to a different web host or upgrading the mail server or changing/upgrading the spam filter software may cause the emails to stop being sent/delivered. -
You do not need to loop through the entire table. You should be able to so something like this: $sql = sprintf('SELECT UserName FROM users WHERE UserName = "%s" OR email = "%s"', mysql_real_escape_string($_POST['username']), mysql_real_escape_string($_POST['email'])); $check = mysql_query($sql); if ( ($check) and (mysql_num_rows($check) > 0) ) { die("That username or email is already in use!"); }
-
Going back to the original code you posted: $flag will be an associative array. $flag['flag'] should get you the flag's value. However, you really should not query the same table twice in a row like that. You could do that with: $sql = "SELECT username, flag FROM users WHERE username = '$username' AND password = '$password'"; $res = mysql_query($sql); if (! $res) { // The query failed, handle it -- in Development you can: trigger_error(sprintf('User Query Failed: %s<BR>%s', $sql, mysql_error()), E_USER_ERROR); exit; } else { if (mysql_num_rows($res) == 1) { $row = mysql_fetch_assoc($res); $_SESSION['loggedin'] = TRUE; $_SESSION['username'] = $username; $_SESSION['auth_lvl'] = $row['flag'];
-
@ChristianF 1) Where does the manual say that strip_tags is "not a good idea"? I see warnings about using it with broken HTML, but nothing else. 2) What is wrong with htmlspecialchars? I find it a minimalistic function suitable for "escaping" user input when it will be displayed. I prefer it over htmlentities since the latter does more work (which means it takes longer) and the extra changes are not necessary (for my purposes). 3) I'm surprised you let him have strlen. After all, isn't the push now toward UTF-8, a multi-byte character set, which requires mb_strlen?
-
It looks to me like the OP's datetime picker is sending DD/MM/YYYY ... in which case, the PHP would be: list($day, $month, $year) = explode('/', $_POST['CheckIn']); (Why was that a backslash?)
-
The second parameter to strtotime is a time() value, if it is omitted, the current time is used. // $item_reg came from the database & is a database formatted DATETIME: YYYY-MM-DD hh:mm:ss if (strtotime($item_reg) >= strtotime('-3 days')) { // Registered 3 or more days ago Note that this method also considers the TIME part of the Date-Time values. I usually just use strtotime() on datetimes from the (mySql) database. It is a well-known, well-structured value and I have never had a problem with it. Note that if the value is a DATE value from the database, it will not have a TIME component, and strtotime() will apply the time component (hh:mm:ss) from the current system time.
-
With the ORDER BY the server has to sort all 400,000+ rows in the table to determine which 10 to send back. Without the ORDER BY it can send back any 10 records it finds. You can add an index on the ResignDate so the server will already have a sorted list of values to consult. You might need to make it a descending index, I'm not sure. Also, do not use LEFT JOIN unless you really need it. A straight JOIN will perform better.
-
TABLE1 has 33 columns, TABLE2 has only 30 columns. I will continue working on this. Don't use SELECT * in the UNION queries. Just select the common columns that you are working with from ((SELECT id, username, timestamp FROM TABLE1 where timestamp >= '$startTime' and timestamp <= '$endTime') UNION (SELECT id, username, timestamp FROM TABLE2 where timestamp >= '$startTime' and timestamp <= '$endTime'))
-
Oops, I kind of forgot about that preg_replace. Here's another stab at it. I've turned the conversion into a function. See if you can follow this: // The original Content we are trying to convert $content = '<BODY> <UL> <LI><A href="example.com/index.php?board=1.0">First Board</A></LI> <LI><A href="example.com/index.php?order=date&board=42.4&search=mike">Another</A></LI> </UL> <P>Try <A href="google.com">Google</A> (not replaced)</P> </BODY>'; $findReplace = array(); // Collect old and new URLs $matches = array(); // Array of what we find with preg_match_all if (preg_match_all('~href=([\'"])(example\.com/[^\1]+?)\1~i', $content, $matches, PREG_PATTERN_ORDER)) { # print_r($matches[2]); // Testing to see what we found foreach ($matches[2] as $oldUrl) { // [2] is an array of the URLs (inside the quotes) found if (!isset($findReplace[$oldUrl])) { // If we have not seen this one already $findReplace[$oldUrl] = changeUrl($oldUrl); // Convert it to the new style } } // Now replace what we found with the new style // str_replace is faster and we don't have any regexp's in there now, anyway $content = str_replace(array_keys($findReplace), $findReplace, $content); print $content; } exit; function changeUrl($oldUrl) { // The list of boards keyed by the Board's ID static $boards = array(1 => 'Board-A', 2 => 'Board-B', 3 => 'Board-J', 42 => 'Grok All'); $urlParts = parse_url($oldUrl); // Breakup the URL $qsParts = array(); // Breakup the Query String (if any) if (isset($urlParts['query'])) parse_str($urlParts['query'], $qsParts); // Convert the BoardID.Page to BoardName-Page if (isset($qsParts['board'])) { $boardParts = explode('.', $qsParts['board']); $boardName = $boards[$boardParts[0]]; if ( (count($boardParts) > 1) and (!empty($boardParts[1])) ) $boardName .= '-' . $boardParts[1]; unset($qsParts['board']); } else { // No Board ID -- use the default $boardName = $boards[1]; } // Build the new URL $newUrl = 'example.com/' . $boardName; if (! empty($qsParts)) $newUrl .= '?' . http_build_query($qsParts); return $newUrl; } By the way, in your original post, you were building up regular expressions for preg_replace. When you do that, you need to remember to escape the regexp special characters. For instance, here is your first line and the correction below it: $url_input[] = "'example.com/index.php?board=" . $id_board . "\.([1-9][0-9]*)[;&]'"; $url_input[] = "'example\.com/index\.php\?board=" . $id_board . "\.([1-9][0-9]*)[;&]'"; Looks like you were using the single-quote as the delimiter. I usually use tilde ("~") because it is highly unlikely that I need to include it in the regexp. The regexp explained: ~href=([\'"])(example\.com/[^\1]+?)\1~i ~ # A delimiter to indicate the beginning of the pattern href= # A literal string "href=" to find since it usually introduces a URL in a link ( # Start a capture group - # 1 [\'"] # A Character class - find either a single-quote or double-quote - the single-quote is escaped because I used single-quotes for the string itself ) # End of capture group - # 1 ( # Start a capture group - # 2 example\.com/ # A literal string "example.com/" - we had to escape the full-stop (".") because it is special to regexp [^\1] # A character class - ^ means NOT when used in the first position - match any character that is NOT the character found in Capture Group # 1 +? # Repeat the preceeding match one or more times but don't be greedy about it ) # End of capture group - # 2 \1 # Match the character found in Capture Group # 1 ~ # The Delimiter marking the end of the pattern i # A modifier to make the matches case-INsensitive
-
Use the force, Luke. Let the system do the work: // The list of boards keyed by the Board's ID $boards = array(1 => 'Board-A', 2 => 'Board-B', 3 => 'Board-J', 42 => 'Grok All'); // The original URL we are trying to convert $content = 'example.com/index.php?order=date&board=42.4&search=mike'; $urlParts = parse_url($content); // Breakup the URL $qsParts = array(); // Breakup the Query String (if any) if (isset($urlParts['query'])) parse_str($urlParts['query'], $qsParts); // Convert the BoardID.Page to BoardName-Page if (isset($qsParts['board'])) { $boardParts = explode('.', $qsParts['board']); $boardName = $boards[$boardParts[0]]; if ( (count($boardParts) > 1) and (!empty($boardParts[1])) ) $boardName .= '-' . $boardParts[1]; unset($qsParts['board']); } else { // No Board ID -- use the default $boardName = $boards[1]; } // Build the new URL $newUrl = 'example.com/' . $boardName; if (! empty($qsParts)) $newUrl .= '?' . http_build_query($qsParts); print($content . ' => ' . $newUrl . PHP_EOL); No repeating code! It handles all boards and all extra parameters in one fell swoop. If any of it is not clear, feel free to ask.
-
I have to admit, the first time I flew to California, I started getting nervous when we were 30 minutes passed what I thought was our arrival time. I finally realized the arrival time on the ticket must be local time at the destination. So, an hour later, I was getting more nervous. I finally asked the stew... uhh, flight-attendant. I'm sure she struggled not to laugh in my face as she explained the "extra" timezone. well, it was my first flight west (and I'm not saying how recent that trip was).