Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
If you want to do that then you will need to use AJAX like drewbee stated. You would not be able to do that even with your plan of having page 2 self submit itself. Let's say it takes 10 seconds to process the data on page 2. Well, when the user submits page 1, page 2 will start processing the data and 10 seconds later the page will be delivered to the user. So, the user would see a white screen that entire time and then see the rotating image for about 1 second before the page self-submitted. I would propose you first get it working without using AJAX. Then implement the AJAX later. -
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
Why do you need to pause at all? Page 2 won't finish unti it's done. By your explanation you are going to read the content provided by the URL and parse the data. You don't need to implement any type of pause. Simply have the page do it's processing and then include page 3. You are really making this more complicated than it should be. Just have your processing done at the beginning of the page and then include page 3 at the end. The inlcude can't occure until the processing is done. Having page 2 as an intermediary page is pointless since it won't be sent to the browser till it's done processing anyway! -
is it possible to hack PHP SESSION information?
Psycho replied to binxalot's topic in PHP Coding Help
OK, from the manual: That is JUST the session ID which is stored client-side! So, the data is stored server-side. But to the point of this post I assume it would be possible to hack a user's session ID to then access data on a secured site, but I suppose there would only be a small window of opportunity. I've never worried about this, but I guess you could protect the session data by matching up the session data with the user's IP? -
Well, the OP didn't statre anything about unique numbers. But, if that's what he needs, this would be more efficient: <?php $value = array(); while(count($value) < 10){ $random = rand(0,9); if (!in_array($random, $value)) { $value[] = $random; } } ?>
-
Yeah, I was going to help. But, it took me many attempts to find a combination that displayed the problem.
-
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
Yes, you need a page 3, but there is no need to pass the variables from page 2 using POST, GET, or SESSION data. Unless page 3 will be used as a stand-alone page to receive data from other pages (not just page 2) then it only needs to be included. -
I'm not really following what you are trying to accomplish, but here goes: <?php function random_num($n=5) { return rand(0, pow(10, $n)); } for ($i=0; $i<10; $i++) { $value[] = random_num(1); } ?>
-
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
haku, Apparently you haven't followed this thread. The OP does not need to pass the values to a 3rd page. He simply needs to include page 3. Problem solved. -
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
Yes, that is what I mean. Technically, you don't even need a page 3, you could simply stick it all on page 2. But, keeping different parts of functionality on different pages is good practice in my opinion. You would use the POST value for the URL the user submitted, but there would be no need to include it in another form. You *can* use javascript to have a form auto-submit. But, that would be very bad practice in my opinion for many reasons. -
How to send the form data from first page to the 3rd page?
Psycho replied to ivytony's topic in PHP Coding Help
OK, you have two different questins in this post - which confuses things. The first issue of getting values from page 1 to page 3 has been taken care of (use either hidden fields or session data). The second issue is how to get page 2 to submit itself. But, after looking at your explanation above I think you are looking at this wrong. According to your explanation page 2 will have a lot of back-end processes, but there is no user interaction. So, why would you need a form to submit? I would suggest this. The user enters the URL on page 1 and submits to page 2. Page 2 goes through all of the backend functionality and gathers the additional data and does validation. If validation fails, then an appropriate error is displayed. If validation passes, then INCLUDE page 3. That way all the values available and created on page 2 are available on the included page 3. Page 3 will complete the operation. -
Well, I still think this makes no sense trying to determine the value before it is created since it can, and will, be wrong in some instances. How about this: Once a user starts the order process (by adding products to the cart) create a record in the orders table so you can generate an order number. But, have an "isOrder" column and set the value initially to "0" (false). One the order is finalized, set the "isOrder" column to "1" (true). You can then query for that order number any time before the order is completed. The only downside would be that any order not completed would take up an order number record, but they could be easily weeded out using the "isOrder" column.
-
Absolutely. Relying upon the Next Auto Increment value for any functional process is a disaster waiting to happen. EDIT: This must be a homework question since there is an EXACT same post by another user today: http://www.phpfreaks.com/forums/index.php/topic,184429.0.html
-
Incrementing the item number is easy: <?php $numberOfItems = 10; for ($i = 1; $i<=$numberOfItems; $i++) { print("<input type=\"hidden\" name=\"item_number\" value=\"{$i}\">\n"); print("<input type=\"hidden\" name=\"item_name\" value=\"$product_name\">\n"); print("<input type=\"hidden\" name=\"amount\" value=\"$product_price\">\n"); print("<input type=\"hidden\" name=\"quantity\" value=\"$quantity\">\n\n"); } However, you need to determine how PayPal expects the other fields to be formatted so the Quantities, Names, and Amounts are all associated with the appropriate items and implement that as well. Without any changes only the last Quantity, Name & Amount would be passed.
-
http://computer-vet.com/weblog/2006/07/05/find-next-autoindex-using-php-and-mysql.html However, as PFMaBiSmAd alluded to you should NOT rely upon this. If two users access the script which pulls this value then both pages will have the same "Next Auto-Increment" value. But if both were to proceed with the record creation, only one would actually get that value and the other would get the subsequent value. I still think this is a proor approach.
-
I don't think there is a fool proof way of doing this unless you were to save the auto-increment value after every record save. The problem is that the next auto-increment value will not be MAX(id) + 1 if the last record created has been deleted. Example, you just inserted a record with the ID of 15. The next auto-increment value will be 16. In that case it WOULD be MAX(ID) +1. But, if the record with the ID of 15 is deleted, the next ID would still be 16 even though MAX(ID) + 1 would now equal 15 (assuming there is a record with the ID of 14). I'm curious why you would need to know the ID before the record is created. Might be a different way of approaching the problem that does not require this.
-
this will get all the email addresses in the input string and remove duplicates: <?php function getEmails($intputStr) { preg_match_all('/[\w\+-]+([\.]?[\w\+-])*@[a-zA-Z0-9]{2,}([\.-][a-zA-Z0-9]{2,})*\.[a-zA-Z]{2,4}/', $intputStr, $matches); $emailListAry = array_unique ($matches[0]); return $emailListAry; } $textInput = '"Bobeee Bob" <Bob@gmail.com>, "Ron@hotmail.com" <Ron@hotmail.com>, "johnee@ruckus.com" <johnee@ruckus.com>'; $emails = getEmails($textInput); print_r($emails); //OUTPUT: //Array //( // [0] => Bob@gmail.com // [1] => Ron@hotmail.com // [3] => johnee@ruckus.com //) ?>
-
I think it would be much easier to store the worked time in decimal format. That way you can use the MySQL SUM function to get total time worked. Just create functions to convert from decimal to time format and vice versa. Unless I am mistaken the SUM() function does not work on time fields in MySQL - at least a quick test I did didn't seem to generate the results I expected.
-
Well, to put it simply you would have to program it. How it would be best programmed depends on several factors. Are you talking about a simple text field for a value such as "color", or is it a text area where the user will enter in full paragraphs? For one-word answers you will most likely have problems because many languages use the same words for some values. And, for full paragraphs you will need to have a fairly complete dictionary for all the different languages. Even then, the process would get rather complext and would never be 100% accurate. In my opinion, you are chasing an unachievable goal.
-
Personally I would changethe function to use something other than seconds, but since you didn't specify what flexibility it needed I didn't change that. <?php function fillEpoc($startDate, $endDate, $frequency) { $dates = array(); $startEpoc = strtotime($startDate); $endEpoc = strtotime($endDate); $newdateEpoc = $startEpoc; $year = date('Y', $startEpoc); $month = date('m', $startEpoc); $day = date('d', $startEpoc); $hours = date('H', $startEpoc); $minutes = date('i', $startEpoc); $seconds = date('s', $startEpoc); while($newdateEpoc <= $endEpoc){ $dates[] = date('Y-m-d H:i:s', $newdateEpoc); $seconds = $seconds + $frequency; $newdateEpoc = mktime($hours, $minutes, $seconds, $month, $day, $year); } return $dates; } ?>
-
Can you post a link to the page?
-
You might also need to change your variables as follows: var check_lname= document.forms['myform'].elements['lname'].value
-
Here's a fully working example script: NOTE: Forum would not allow the file commands in the code, so I replaced them with '[FOPEN]', '[FCLOSE]' & '[FWRITE]' in the script below. Remove the brackets and make them lower case. <?php $file = "names.txt"; $names_list = file($file); foreach ($names_list as $key => $name) { $names_list[$key] = str_replace('\n', '', trim($name)); } if ($_POST['name_sel']!='') { $submit_name = $_POST['name_sel']; } else if ($_POST['name_other']!='') { $submit_name = $_POST['name_other']; $new_name = trim($_POST['name_other']); if (!in_array($new_name, $names_list)) { $names_list[] = $new_name; sort($names_list); //Write the new list to the file $fh = [FOPEN]($file, 'w') or die("can't open file"); foreach($names_list as $name) { [FWRITE]($fh, $name."\n"); } [FCLOSE]($fh); } } ?> <html> <head> <script type="text/javascript"> function other_name() { nameSel = document.getElementById('name_sel'); nameTxt = document.getElementById('name_other'); if (nameSel.value=='') { document.getElementById('name_other').disabled = false; document.getElementById('name_other').style.backgroundColor = '#ffffff'; } else { document.getElementById('name_other').value = ''; document.getElementById('name_other').disabled = true; document.getElementById('name_other').style.backgroundColor = '#cecece'; } } </script> </head> <body onload="other_name();"> <form name="testForm" id="testForm" onload="other_name();" method="POST"> <?php echo "Name: <select name=\"name_sel\" id=\"name_sel\" onchange=\"other_name();\">\n"; echo " <option value=\"\"><--Other--></option>\n"; foreach ($names_list as $name) { $slected = ($name==$submit_name)?' selected="selected"':''; echo " <option value=\"$name\"$slected>$name</option>\n"; } echo "</select><br><br>\n"; ?> Other: <input type="text" name="name_other" id="name_other" /><br><br> <button type="submit">Submit</button> </form> </body> </html>
-
This really isn't a PHP question. There is no HTML control for creating an editable select list. There are some JavaScript hacks out there for doing this, but I can't attest to their cross-browser capability. I would suggest having an "<--Other-->" item in the select list with a text field where the usre can enter the "other" value. Then when the user submits the form you can take the entered value and add it to the list of possible values used to populate the list. You could either do this with a database or a flat file (the database option being more reliable).
-
It's the daylight savings time adjustment! http://webexhibits.org/daylightsaving/b.html you will see the same thing for Nov. 2 of this year.
-
Your first function is working correctly. That "shift" is due to daylight savings time adjustment.