Jump to content
Larry Ullman's Book Forums

Gardacus

Members
  • Posts

    24
  • Joined

  • Last visited

Gardacus's Achievements

Newbie

Newbie (1/14)

2

Reputation

  1. All, I found a nice working way. In the time between posting my question and this answer, I started learning javascripting. Not too far yet, but it gave me some eureka moments. The form now consists of this code, and gets its values from the database: echo '<input type="text" size="11" name="impru_acc" id="impru_acc" value = '.$impru_acc.'>'; echo '<input type="text" size="11" name="impru_rest" id="impru_rest" onchange="calculateAll(this.value)" value = "">'; echo '<input type="text" size="11" name="impru_sold" id="impru_sold" value = '.$impru_sold.'>'; echo '<input type="text" size="11" name="impru_dobanda" id="impru_dobanda" value = '.$impru_dobanda.'>'; I made a separate calculateAll.js file and call it in my header.html file. The code consists of: function calculateAll(){ var form = document.forms["fisa"]; var impruDobandaValue = form.elements["impru_dobanda"]; var impruRestValue = form.elements["impru_rest"]; var impruSoldValue = form.elements["impru_sold"]; var impruDobanda = parseInt(impruDobandaValue.value); var impruRest = parseInt(impruRestValue.value); var impruSold = parseInt(impruSoldValue.value); if (impruDobanda > 0) { var difference = impruDobanda - impruRest; } else { var difference = 0; } if (difference > 0) { impruDobanda = impruDobanda - impruRest; return theForm.elements["impru_dobanda"].value = impruDobanda; } else if (difference < 0) { impruSold = difference + impruSold; impruDobanda = 0; return form.elements["impru_dobanda"].value = impruDobanda, form.elements["impru_sold"].value = impruSold; } else if (difference == 0) { impruDobanda = 0; var impruSold = impruSold - impruRest; return form.elements["impru_dobanda"].value = impruDobanda, form.elements["impru_sold"].value = impruSold; } } But I ran into a small issue. When you make a mistake, the form did not use it's original values, but recalculates from the changed values. Which is logical. To work around this, I created a reset button for the impru_rest field in the form. It resets that field and recovers the original values of the impru_sold and impru_dobanda values in the form. After that correction is possible. I thought it was best to code this in PHP <?php echo "<input type=\"button\" value=\"Reset\" onclick=\"var reset = this.form.elements['impru_rest']; reset.value = reset.defaultValue; this.form.impru_dobanda.value=".$impru_dobanda."; this.form.impru_sold.value=".$impru_sold.";\">" ?> So all in all it took me a bit, but I wanted to share my findings with you. Thanks for your help! Mike
  2. I am using the wonderful onkeyup argument to auto update values in forms. I have a question though. Example: I have five values. Loan, Terms, Saldo, Payment, Interest The form is built up that it gets its data from a database. The Loan, Terms and Interest rate will be entered as a default value to handle the rest of the terms, payment and saldo. example: loan = 1000, terms = 12 Interest = 215 Saldo = Loan = 1000 The form will be filled in as an overview of payments and saldo, to check how much money still needs to be paid. For the next entry, the term will count down 1, and I can enter a payment, example 102. Paying a payment will first influence the interest amount until it is 0. From that moment on the Saldo will go down from it's default value of a 1000. Until it is zero I have managed to auto update my form entries automatically when a payment is entered, so that the Interest goes down accordingly. Everytime the payment in this example should be 102. At a certain moment the interest will drop from 215 to 113 to 11. But then I am stuck. Added below is a part of the code. The calculation and check should be done right after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. I know the code is not correct, because at its current state, it won't touch the value of Loan when interest = 0. Not knowing how to catch this, the interest will just become negative. Is there a way to deduct and thus update the form fields in such a matter that when the interest hits 0 the remainder of the payment will be deducted from the Saldo value and in the process keep my form fields being auto updated? Thanks! Mike <?php // Generate split between Interest bigger or equal to zero if (!empty($loan) and $interest >= 0) { // fill in or echo the size of the loan if (!empty($loan)) { echo '<input type="text" size="11" name="loan" value = '.$loan.'></div></td>'; } else { echo '<input type="text" size="11" name="loan" value="" /></div></td>'; } echo '<td><div align="center">'; } // Fill in the payment and deduct it from interest as long as interest is bigger than 0. if (!empty($interest)) { echo '<input type="text" size="11" name="payment" onkeyup="document.forms[0].interest.value = '.$interest.'*1 - document.forms[0].payment.value*1;"></div></td> <td><div align="center"><input type="text" size="11" name="saldo" value="'.$loan.'" readonly="readonly" />'; } else { echo '<input type="text" size="11" name="payment" value="" /></div></td>'; echo '<td><div align="center"><input type="text" size="11" name="impru_sold" />'; } echo '</div></td><td><div align="center">'; ?> I stopped entering the code here, because it is quite long, and the magic should happen after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. If more code is needed, I will be happy to enter it here.
  3. Hello HartleySan I will add some answers and comments to yours 1. These are the (existing) systems I want to make inquiries in: Sidecode 4 (XX-99-XX) Sidecode 5 (XX-XX-99) Sidecode 6 (99-XX-XX) Sidecode 7 (99-XXX-9) Sidecode 8 (9-XXX-99) Hence the flexibility I am searching for in creating the begin and end point. 2. No, no reason, it is an adjusted array of one of Larry's scripts 3. That's why I want to be the first 4. Yes I have legit access, but these things are all besides the point. I have java scripts available, but first things first. as answers to your ) - numbered remarks; 1) I want to exclude non-existing combinations, by providing a fixed selection (hence the letter array) 2) and 3) Good idea to limit it. So remains... how can I build this array? Any ideas how to start this? Thanks again
  4. Hey HartleySan Thank you so much for looking with me Yes, more or less Except we're limited to these letters: $letter = array (1 => 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'N', 'P', 'R', 'S', 'T', 'X', 'Y', 'Z'); All others are not necessary. All digits are possible. This is just one of the many series of possible combinations Example... currently we are at 1 digit - three letters - 2 digits (9-xxx-99). So I was trying to create a script that I can easily apply to all kinds of possible (and future) ranges Thanks Mike
  5. Hi guys I have a new challenge. Short intro. I am from Holland. In Holland we have a car license plating system that links a license plate to a car. And looking up a license plate, can show the known data of that car (technical info, not personal) There are a bunch of sites where you can get the data for one car at the same time. I am thinking to build a site where I can draw information for a whole range of license plate numbers at once. I don't know if I should create an array or another means to create the range. Example at one time, the numbering on our license plates was: 2 digits - 2 letters - 2 digits (99-xx-99) I wrote a script already that can set the begin and end value... but I have no clue how to create an array with all possible combinations between begin and end value. the code I am using to create the begin and end value for the range is as follows: as part of index.php: $letter = array (1 => 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'N', 'P', 'R', 'S', 'T', 'X', 'Y', 'Z'); $number = range (0, 9); echo '<form action="select.php" method="post">'; // create select for range 1 echo '<p>Set range 1'; echo '<select name="letter11">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter12">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="digit11">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="digit12">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="letter13">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter14">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select></p>'; // create select for range 2 echo '<p>Set range 2'; echo '<select name="letter21">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter22">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="digit21">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="digit22">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="letter23">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter24">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select></p>'; echo '<input type="hidden" name="sc" value="sc4">'; echo '<input name="submit" type="submit" value="Create List"'; } After pressing the submit, it will send all data to select.php for now I simply plot the beginning and end in it as follows: $letterrange11 = ($_POST ['letter11']).($_POST ['letter12']); $digitrange11 = ($_POST ['digit11']).($_POST ['digit12']); $letterrange12 = ($_POST ['letter13']).($_POST ['letter14']); $letterrange21 = ($_POST ['letter21']).($_POST ['letter22']); $digitrange21 = ($_POST ['digit21']).($_POST ['digit22']); $letterrange22 = ($_POST ['letter23']).($_POST ['letter24']); echo '<p>'.$letterrange11.'-'.$digitrange11.'-'.$letterrange12.' until '.$letterrange21.'-'.$digitrange21.'-'.$letterrange22.'</p>'; So the big question is now... The code I used til now, is it a good basis to create the array that I need? If so, How do I build an array that will look like as follows... What I need is if I select DD-00-DD to DZ-99-ZZ, to plot all possible values in an array. This based on the $letter array. e.g. DD-00-DD DD-01-DD DD-02-DD etc, etc, etc, DZ-99-ZV DZ-99-ZX DZ-99-ZZ This data I can then send per license plate to the to-be-built script. I realize it is a huge list, but I am curious how this could work out. Any help is welcome. THANKS GUYS! Regards Mike
  6. Hi all I am not sure if this topic exists or where to place it, so please forgive me if I posted this on the wrong site. I am looking for a smart (PHP preferred) solution to redirect mobile devices to a mobile version of a website. At this moment this is my javascript solution, but it is not fool-proof: <script type="text/javascript"> if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('Blackberry') != -1) || (navigator.userAgent.indexOf('Opera Mini') != -1) || (navigator.userAgent.indexOf('WebKit') != -1)) { document.location ="mobile/index.html"; } </script> It works on the devices mentioned, but Safari on an iMac also is seen as a mobile device, and therefore redirected to the mobile site. Is there any smart solution for this that I can build in PHP? Thanks all! Mike
  7. Hello HartleySan It's a bit of work, but it will safe me a lot of problems later indeed. Thanks again Holland or The Netherlands is kind of used randomly, but I notice that in the "spoken" language, Holland is more used than "The Netherlands" In official writing I would say The Netherlands is mostly used. Though "The Netherlands" is the official English translation. "Holland" is an old term actually, and nowadays in Dutch only used in the name of 2 provencies: North-Holland (Noord-Holland) and South-Holland (Zuid-Holland) This site may explain a bit more: http://www.archimon.nl/general/holland.html or http://www.worldatlas.com/aatlas/infopage/holland.htm Regards Mike
  8. Hello HartleySan Thanks for your response. I did figure out a workaround, which is actually commonly used here in Holland. I just did not realize. What most web builders seem to do is make an extra column for these prepositions and ask the users to put them in there and the last part of the last name to enter as last name. I have to correct about 100 last names, but it makes my life eventually a lot easier. Thank you again. Regards Mike
  9. Hello all I am still working on the login script from this book, and implementation on my own site works very very well At the moment I am strugling with our last-name convention here in Holland We have names like "van der Vaart", "de Wit" and "in 't Groen" and more alike. The current script does not take this into account and puts them in alphabetical order. So all the "van" and "de" names are in one row. Here in Holland it is therefore customary to split the last name like this: "Vaart, van de", "Wit, de" and "Groen, in 't" But of course we also have singular-word last names, like "Groenen", "Smulders" etc, etc. Does anybody know how I can do this, before injecting them into the database? As a person will always enter it in the orignal way. I was thinking to search for a space before the last word in that line or so, but I might be digging in the dark, and I don't know how to write the code for that. This is a line from the script which already checks for a last name: // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Fill in your last name, please!</p>'; } and the line from the form is as follows: <tr><td><b>Last Name:</b></td><td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></td></tr> Thanks! Mike
  10. Larry, you're welcome Glad I can do something in return! You're a great teacher and I love reading and learning from your books! Thanks again Mike
  11. Larry I found this and added it in the header file of the login script: if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1){ $_POST = array_map( 'stripslashes', $_POST ); $_GET = array_map( 'stripslashes', $_GET ); $_COOKIE = array_map( 'stripslashes', $_COOKIE ); } It seems to do the trick... as I need this on more locations (us Dutchies are like the French with our apostrophs hahaha) Mike
  12. Hi Larry Thanks for your answer (and your wisdom!!!) That's going to be a challenge... I will have to find a workaround for this, as I am running the scripts from a hosted site, in which I cannot change anything in the php.ini. I will snoop around Mike
  13. Hi Paul Thanks for your help! Unfortunately the result remains the same. But I have no idea why... So even with your code, it still show in \'t Groen Plus The fact that the apostroph is not accepted by the preg_matching I guess... what else would stop it? I am not even injecting it yet in the database. What I mean is, the rest of the original register.php as written in Larry's book, checks if you enter a first name, last name, email address and twice your password. So forgetting either of those, will fill in the already entered info and warn you about the wrong or forgotten ones. But I have no idea what causes the preg_match to state that the entered last name, containing the ' is not a valid last name. Any ideas? Thanks Mike
  14. Hi everyone. I am running into a problem at the register.php script I am from Holland and in both our city names as in first and last names, apostrophs and other punctuation marks are used. For intance 's-Gravenhage is the official name of The Hague. Or a common last name is In 't Groen The script does not seem to allow this, because it keeps returning that I need to enter a valid last name. the code is: // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; ---------- // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Fill in your last name please!</p>'; } ----------- If I enter a name as in the example In 't Groen... it would re-fill the line with In \'t Groen. To prevent that from happening I rewrote the form for the last name: <tr><td><b>Last Name:</b></td><td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo stripslashes($trimmed['last_name']); ?>" /></td></tr> My question is, how can I allow these characters such as ' and é ï, which we also use a lot, to pass beyond the script and inject it safely into the database? Thanks again! Mike
  15. Hahaha... no problem at all.. I am still just a beginner, and Larry's books are helping a lot. And I love the way this forum works! Great inspiration and great helpers! Thanks again
×
×
  • Create New...