Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
That will only work if you specify a width using style properties first. Try this: document.getElementById("mydiv").offsetWidth
-
What are you trying to achieve, exactly? Not recognizing a mouse click when the pointer is moved is standard behavior in a browser. Just try clicking a link on a web page and moving the mouse before releasing the button - the link will not be activated.
-
For debugging purposes, try uploading a working/good file through FTP to the same location. If the file then opens correctly you know that the problem is (almost) definitely with the script upload process. Edit: modified my response slightly. I shouldn't use absolutes, lest I feel like a fool later.
-
Just name your fileds like this: <input name="Address1[]" type="text" value="22 Bishop Crewe" id="Address1_1"> Notice that I added a "_1" to the ID value. You will need to increase those by one or some other method as you can't have two objects on the page with the same ID, but you can add [] to the field names to have the values returned as an array
-
Trying to add "Spaces" to allowed characters on Registration Page
Psycho replied to S L A C K E R's topic in Javascript Help
I forgot to add aline to alert the error. Revised: var uName = document.mainForm.userName; var error = false; if (uName.value.length=='') { error = "Please enter a user name."; } else if (uName.value.match(/[^\w ]/g)) { error = "Only letters, numbers, and underscores are allowed in usernames"; } if (error!==false) { alert(error); uName.focus(); return enable_submit(); } return true; -
Trying to add "Spaces" to allowed characters on Registration Page
Psycho replied to S L A C K E R's topic in Javascript Help
You are using a custom function called inValidCharSet(). I can't tell you if it is even possible for that function to allow spaces without seeing it. But, what you are asking for can be achieved very easily with a simple regex expression var uName = document.mainForm.userName; var error = false; if (uName.value.length=='') { error = "Please enter a user name."; } else if (uName.value.match(/[^\w ]/g)) { error = "Only letters, numbers, and underscores are allowed in usernames"; } if (error!==false) { uName.focus(); return enable_submit(); } return true; However, since you are allowing spaces you will want to trim the value first to remove leading and trailing spaces. -
Text entered in form inputs disappear after page reload
Psycho replied to RoBiNp's topic in PHP Coding Help
It is not a problem with your script. The difference you are seeing is based on accessing a page locally vs. via a web browser. If you take the simple example page you have above and make it a local HTML file and as a PHP page accessed from a web server you will see the same results you stated before. A page refresh will not empty the contents of the form for a local page, btu on a page accessed via a web browser they will be emptied. -
I also find it rediculous that the studios use the argument that when you buy a CD (or other piece of media) that you are buying a license to the music not the music itself (which I agree with). But, if that is the case, they should have a program where you can replace a damaged CD with a new one for a much discounted replacement cost. Or, for that matter, I should be able to purchase a CD for an album I already owned on casette of vinyl for a somewhat reduced cost (since I am getting a higher-quality product). I already bought a license for the music, right? So, why should I have to bug a whole new license to get the music in a different format or to replace damaged media?
-
Well, back in December the RIAA stated it was abandoning its strategy of filing mass lawsuits against individual file sharers (http://www.techdirt.com/articles/20081219/0225073172.shtml), but it seems this was not entirely truthful as it seems they are still ongoing. They will be dragged, kicking and screaming, into the 21st century. There have been some positive changes recently. For example many music subscription sites now offer files that are not encumbered with draconian DRM technology. The "information age" has completely broken the model with which content providers have used for decades. They didn't know how to do anything differently. So, they pushed ahead putting whatever measures in place to prevent (so they thought) people from accessing content for which they didn't pay. But, what they have failed to realize is that the only people that were affected by DRM were the people that paid for the content. People who steal music, or other media, do not steal DRM'd content! In many cases, a provider has gone under and people who paid for the rights to content were now out of luck since the DRM on the content had a "phone home" validation to check that the user had rights to the content. But, once the provider went under, their servers which did the validation were no longer available. Totally, unacceptable in my opinion. I certainly don't have the answer. With electronic content a copy of an MP3 is as good as the original (assuming there was no reencoding). There needs to be an incentive to pay for the music as opposed to "sharing" it. There needs to be some service tied to the music in my opinion. On a related note, it is my understanding that when video cassette tapes were first introduced Disney was initally against it because people could watch one of their movies whenever they wanted and they (Disney) wouldn't be able to control how many people were watching it. Of course, we have come a long way since then and studios make many more millions than they would without video tapes and now DVDs/Blue-Ray. Just shows how short sighted the content providers are.
-
Limiting characters displayed from database help
Psycho replied to ow-design's topic in PHP Coding Help
What ignace posted will work to query a substring of the value, but it will not take into consideration where words begin and end. Typically in these situations you want the content split between words, otherwise what get's displayed can havfe a very different meaning than what it should. For example, this Could become this I would suggest that you instead pull the entire string from the database and use PHP to break the text between words at a length equal to or less than the specified length. Here is a script which will do that (however, I'm sure there is a more efficient way to do this with a regex expression): function part($string, $maxChar) { if (strlen($string) <= $maxChar) { return $string; } $string = substr($string, 0, $maxChar+1); $string = substr($string, ' ', strrpos($string, ' ')); return $string . '...'; } Edit: Also it will be impossible to ensure that you will get exactly enough content to fill exactly three lines unless you change the font being used to a fixed-width font. That is where each character has exactly the same with as every other character. So, ten 'W's will be the same with as 10 'I's. Typically that is not a good font type to use for "copy" on a page, but is good for code. Fixed Width: WWWWWWWWWW IIIIIIIIII Non Fixed-Width: WWWWWWWWWW IIIIIIIIII -
Text entered in form inputs disappear after page reload
Psycho replied to RoBiNp's topic in PHP Coding Help
I dn't think you are going to be able to control this 100% as it is a function of the browser and the user's settings. You need to look into adding headers to your page to instruct the browser to cache the data. But, again it is up to the browser to determine if it will adhere to those settings or not. For example, using a simple for such as you have above, when using the back key in IE or FF the data is redisplayed. However, if I refresh the page with data in the field, the data is wiped out in IE, but not in FF. But, of course, this behavior will be affected by setting in my browsers. I can also influence that behavior with using specific headers. For example this header: header("Cache-Control: no-cache, must-revalidate"); will prevent the data from repopulating the filed when using the back button, but only in IE. To be honest, I don't really understand all the different cache headers and their values, but that is probably where you need to be looking. -
Text entered in form inputs disappear after page reload
Psycho replied to RoBiNp's topic in PHP Coding Help
When a form is submitted, if you want the form to be displayed again with the submitted data - YOU need to populate the data. It is not some magical server setting. Here's a very generic example: <?php $uname = (isset($_POST['uname'])) ? $_POST['uname'] : ''; if (!empty($uname)) { //Do something with the posted value $response = "<div>You submited the name: $uname</div>"; } else { $response = ''; } ?> <html> <body> <?php echo $response; ?> <form method="POST"> Enter your name: <input type="text" name="uname" value="<?php echo $uname; ?>" /> <button type="submit">Submit</button> </form> </body> </html> -
same user login twice on different machine???
Psycho replied to robcrozier's topic in PHP Coding Help
My company is in the middle of a SaaS application with a similar situation, multiple users can log in on different machines with the same credentials. The solution, for use, is to save a file to the user's PC that is used to help track that PCs session. Although I agree with CV that you should only allow one person to log in at a time with a set of credentials, it is not always up to development to decide these things. My suggestion would be to save a different record for each user login/session ID. Then when checking a user's active status, check to see if there is a record for their session ID. If so, then check to see last activity for that particular session. Of course, you will need to clean up records where the last activity is past the alloted time. -
I am not going to write your code for you (unless you want to pay me). As stated in my sig However, I did notice that the code posted above lost the escaping of the quote marks (a bug on this forum). The code I provided was simply an example (hence the use of the word 'example' beofre the code). It is up to you to adapt for your purposes. If you want help, then provide the code that is in error with specific details.
-
Where's the query for the situation when the user selected a letter? No need to create all new functionality for the "#" option, just change the WHERE part of your query. Give this a try, I probably made some typos though. Echo out the query to make sure it is proper. The MySQL substr looks like it starts with 1 as the first character, not 0 as PHP does, but I didn't validate. <?php //Show all restaurants that start with $selectedLetter if ($selectedLetter != "#") { //Letter was selected $where = "name LIKE '%{$selectedLetter}'" } else { //Number was selected $where = "SUBSTRING(name,1,1) IN ('" . implode("','", range(0,9)) . "')"; } $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE $where"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ $name = $row['name']; printf('<a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>', $row['ID'], $row['name'], $row['address'] ); } ?>
-
same user login twice on different machine???
Psycho replied to robcrozier's topic in PHP Coding Help
Save the session ID to the database as well as the last activity timestamp. When user 1 comes back to their computer and tries to do somethign the system will first check if the session ID matches. Since it doesn't user 1 will be told they have been logged out on another PC. Of course you would not be able to have two people logged in using the same account at the same time, but that's probably what you want. -
I think you need to provide a little more information. Are you trying to create multiple instances of the same select field? Or are you trying to create different select lists from the same query? If it is one of the above, then the answer is probably the same. You should start by separating your logic from the actual display/content. I think your problem stems from you trying to create the lists in-line with the HTML. By separating the logic and display it would be easier to implement. Anyway, I would create variables for the option lists and then echo them later in the code as needed. Here's a quick example of what I mean. PHP Logic <?php $stateOptions = ''; $cityOptions = ''; while ($row = mysql_fetch_array($result)) { $stateOptions .= "<option value="{$row['state']}">{$row['state']}</option>"; $cityOptions .= "<option value="{$row['city']}">{$row['city']}</option>"; } ?> Display Code Select State: <select name="state"><?php echo $stateOptions; ?></select><br /> Select Cities: <select name="city1"><?php echo $cityOptions; ?></select> <select name="city2"><?php echo $cityOptions; ?></select>
-
Bug? Escaping lost during post edits.
Psycho replied to Psycho's topic in PHPFreaks.com Website Feedback
OK, this ONLY happens for me when using the "full" modify link - it does not happen when I use the "quick" modify link. -
Bug? Escaping lost during post edits.
Psycho replied to Psycho's topic in PHPFreaks.com Website Feedback
I am experiencing this with the "Modify" link that appears at the top-right of a post after you post an item (right next to the quote link). I agree this sounds like a server-side issue as the client would have nothing to do with the text that get's populated into the text area when the user selects to edit a post. echo "<a href=\"test.php\">Link</a>"; -
Bug? Escaping lost during post edits.
Psycho replied to Psycho's topic in PHPFreaks.com Website Feedback
echo "<div id="foo">bar</div>"; Initial save with IE: OK Edit with IE: Backslashes lost --Correct backslashes Save with FF:OK Edit with FF: Backslashes lost Hmm, not sure what is different between you and I, but I am consistently losing the backslashes when the text is populated into the text area when I use the option to edit. Edit: Getting the same results on a different PC -
Ah,that was me being lazy. You need to define the "default" like you had before with wildteen's update. My code was referencing $_GET['letter'] without verifying it was set. <?php error_reporting(E_ALL); //Create array with letters AND number sign $letters = range('A','Z'); array_push($letters, '#'); $menu = ''; $selectedLetter = isset($_GET['letter']) ? $_GET['letter'] : null; foreach($letters as $letter) { $menu .= ($letter == $selectedLetter) ? sprintf('%s ', $letter) : sprintf('<a href="browse.php?letter=%s">%s</a> ', $letter, $letter); } echo "<div align=\"center\"><b>{$menu}</b><br /></div>"; ?>
-
I think this just started happening recently - at least I didn't notice it before. When editing a post where characters are escaped, the left backslash is removed from the text when the post is opened for editing. The result is that if you make a change to a post and don't put the backslashes back in, the new post will be in error. Example: I create a post such as this (everything dislayes fine) However, if I then go to edit that post, this is what is displayed in the textarea field (note backslashes are gone): Sample Code: [code=php:0]echo "<a href="somepage.php">Go</a>" [/code] If I make changes and don't put the backslashes back in the new post will look like this (incorrect):
-
I suggest separating your logic from the actual display of the content. Makes it much easier in the log run. In any event, this should get you what you want. You can put the logic (the top part) in a separate page or at the top of your code. Then put the last line within the context of your page. <?php //Create array with letters AND number sign $letters = range('A','Z'); array_push($letters, '#'); $menu = ''; foreach($letters as $letter) { $menu .= ($letter == $_GET['letter']) ? sprintf('%s ', $letter) : sprintf('<a href="browse.php?letter=%s">%s</a> ', $letter, $letter); } echo "<div align=\"center\"><b>{$menu}</b><br /></div>"; ?>
-
[SOLVED] Apostrophe Trouble - updating database
Psycho replied to EternalSorrow's topic in PHP Coding Help
That was NOT the problem. The problem was that the variables were out of order as roopurt18 stated previously and your comeback was [qiuote]If it ain't broke, don't fix it. Write clean, organized code to prevent these types of smacktard mistakes if ($_POST["submit"]) { $author = mysql_real_escape_string($_POST["author"]); $title = mysql_real_escape_string($_POST["title"]); $summary = mysql_real_escape_string($_POST["summary"]); $datetime = mysql_real_escape_string($_POST['date("d/m/y H:i:s")']); $sql = sprintf("UPDATE information SET summary='%s', datetime=NOW() WHERE `author`= '%s' AND title = '%s' ", $summary, $author, $title); $result = mysql_query($sql) or die(mysql_error()); echo "The information has been updated. <a href="infoedit.php?cmd=edit&author=$author&title=$title">Care to continuing editing</a> or <a href="info.php?author=$author&title=$title">view the edited content</a>?"; } -
creating a custom variable after a form submission
Psycho replied to egiblock's topic in PHP Coding Help
Well, where are you getting the values to create the select list (I am assuming) for the event? The select list has IDs as the values and names as the text. If you are getting those values from the database you will need to do another query first to get that value. But, I have to ask, why do you want to do this? Just save a record with all the appropriate variables: year, eventID, eventname, etc. No need to concatentate the values and save that too. You can ALWAYS query the data at a later time when you need to display it and concatenate it then. You would not need to do two queries to save tha data and you can get the event name when retrieveing the data later by doign a JOIN. This is completely unnecessary in my opinion. Besides, what if the event name changes at some point. Would you want the 'custom' name to have the current event name?