Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
$post_fields = array ( 'rm_loc', 'resident', 'patient', 'mrn', 'age', 'race', 'gender', 'pod', 'rcf_date', 'dx', 'meds', 'pmhx', 'problist', 'anticipate', 'antic2', 'antic3', 'antic4', 'todo', 'todo2', 'todo3', 'todo4', 'comments', 'code', 'allergy', 'signoff_status'); //Convert all the 'appropriate' post fields to variables foreach ($post_fields as $field) { $$field = mysql_real_escape_string(trim($_POST[$field])); } //Post processing of some POST vars and creation of others not from POST $rm_loc = ereg_replace("[^A-Za-z0-9]", "", $rm_loc); $rcf_date2 = $newdate; //Create the query $sql = "UPDATE icu SET rm_loc = '$rm_loc', patient = '$patient', mrn = '$mrn', age = '$age', icudays = '$icudays', race='$race', gender='$gender', pod='$pod', resident = '$resident', rcf_date='$rcf_date', dx='$dx', meds='$meds', pmhx='$pmhx', problist='$problist', problist_date= '$problist_date', anticipate='$anticipate', antic2='$antic2', antic3='$antic3', antic4='$antic4', anticipate_date = '$anticipate_date', antic2_date = '$antic2_date', antic3_date = '$antic3_date', antic4_date = '$antic4_date', comments='$comments', comments_date = '$comments_date', code='$code', allergy='$allergy', todo='$todo', todo2='$todo2', todo3='$todo3', todo4='$todo4', todo_date='$todo_date', todo2_date='$todo2_date', todo3_date='$todo3_date', todo4_date='$todo4_date', signoff_status='$signoff_status', rcf_date2='$rcf_date2' WHERE id_incr = '$id_incr'"; //Run the query //*** this check is not useful since $sql is explicitly set //if (isset($sql) && !empty($sql)) { //***If any fields are required, that validation should occure when iterrating through the fields. echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die ("Invalid query: " . mysql_error());
-
Well, I can't see all of your code, but unless you are POSTing the values through AJAX with multiple fields then it will not be received as an array. I suggest you post the values as a delimited string. Then in PHP explode() the values and then iterrate through each one for validation. Then implode the valid values back into the format you need them for the query: var formElements = document.forms['categoryRegister'].elements; var elementsRange = formElements.length; var checkedResults = []; for (i=0; i<elementsRange; i++){ if (formElements[i].type == "checkbox" && formElements[i].checked){ checkedResults = formElements[i].value; } } //Create a string with all values delimited by a | resultsList = checkedResults.join('|'); $categoryList = $_POST['checkedResults']; $categoryListArray = explode('|', $_POST['checkedResults']); foreach ($categoryListArray as $listValue) { //Validate/process each list item //Remove invalid items } $categoryListing = implode(',' , $categoryListArray);
-
Not sure what you're having difficulty with. Would be helpful if you provided some of the code you are having problems with, but you simply create two functions in the page function one() { echo "This is function one."; } function two() { echo "This is function two."; } one(); //Output: //This is function one. //This is function two.
-
Are you doing this through AJAX? If not, there is absolutely no reason for JavaScript here since the checkbox values will be available when the form is posted to the PHP processing page. In fact, I don't know how you would use this if not using AJAX.
-
If you want a list of ALL the checkboxes checked in a form, Nightslyr's method should work fine. However, if you only need the checkboxes for a specific group of checkboxes you could either have the server-side script create a JS array of the field to iterrate through or you could put them all in a div and then iterrate through the div's child elements - similar to Nightslyr's approach (but for a div instead of a form). Since you have two TDs with sets of checkboxes you may want to have results for each TD independantly. In that case follow the same approach Nightslyr presented for the form, but do it for each child elment for the TDs (you would want to give each an ID). But I don't know about your intended goal to know if that's what you want.
-
Well, if we're going to get into validation, there's a lot more than that wihch should be done. In fact that validation, although usefull, doesn't prevent values from beng added to the SQL. The SQL will only include the variables that are defined in the query. That extra step will prevent "other" variables from being defined that may be used in the script elsewhere. But, to validate fully you should ensure that ALL values for the query are present and also run them through mysql_real_escape_string(). Some would also need to be validated that they are an appropriate value for the filed (e.g. number for numeric fields)
-
Based upon what you have I would first convert each POST array item to a variable with the same name as the key: foreach ($_POST as $variable => $value) { $$variable = $value; } //If $_POST['foo'] = "bar" the above will create a variable named $foo with a value of "bar" Then for any post processing you currently have, you will need to incorporate, such as: $rm_loc = ereg_replace("[^A-Za-z0-9]", "", $rm_loc); Ass long as all the variables used in your query are the same as the POST index values, you shoudl be good to go.
-
How are the checkboxes named? 1. Are they named the same? If so then you can access all of them as an array. 2. Do they have same names with a unique id/number (name_1, name_2, etc)? If so, you can iterrate through them programatically. 3. Do they all have unique names? If so, then you want to create a javascript array with the server-side code that generates the checkboxes. Please provide an example of your checkbox code.
-
You are asking a lot of questions in there. I would suggest you take one part at a time and ask specific questions as needed. Getting 3 million records from a flat file into the database is the first problem to overcome. Normally I would use file() to read the file into an array. And then process it for a INPUT statement. If the zip ode and form id were separated on each line by a comma I would do something like this: $file="the_file.csv"; $data = file($file); //Process data foreach ($data as $record) { $record_data = explode(',', $record); $insert_records[] = "('".trim($record_data[0])."', '".trim($record_data[1])."')"; } //Create query string $query = "INSERT INTO table (ssn, form_id) VALUES " . implode(',' , $insert_records); //Run query mysql_query($query) or die (mysql_error()); However, with 3 million records you will most likely run into problems. You may need to find a workaroound to process the file in pieces. But give that a try to see if it will even process that many records. Would be a good idea to track system resources during the process to understand the load on your server.
-
"....there is another script for another part of the page that loads the entire page again" I guess it depends by what he means by "loads the page again."
-
Use a session variable.
-
I think you would be better off in creating an animated gif than trying to do this in JavaScript, but here are some resources: http://www.walterzorn.com/rotate_img/rotate_img.htm http://elouai.com/javascript/javascript-image-rotate.php
-
When you include an external file, the code in that file is already assumed to be script code. Remove the SCRIPT tags inthe external file.
-
$monster[1] = "spirit"; $times[1] = "18"; $monster[2] = "golden spirit"; $times[2] = "18"; $monster[3] = "hank"; $times[3] = "15"; $array = array(); foreach ($monster as $index => $value) { $array = array_merge($array, array_fill(0, $times[$index], $value)); }
-
What you have should work. Here's a working page with the same functionality. Although I changed the process a little bit to make it more flexible. <html> <head> <script type="text/javascript"> function changeText(obj, text) { obj.innerHTML=text; } </script> </head> <body> Mouse over the text below to change it: <br><br> <p id="text_div" onmouseover="changeText(this, 'Quit touching me');" onmouseout="changeText(this, '<?php print $_GET['info']; ?>');"><?php print $_GET['info']; ?></p> </body> </html>
-
As I said I would do all that completely different and I don' thave the time to do a complete rewrite, but here is a quick example of what you could do in the PHP with what you have already. PHP code at the top of page: <?php if(isset($_POST)) { $name_error_vis = (empty($_POST['text']) || !ctype_alpha($_POST['text'])) ? '' : 'hidden'; $name_error_vis = (empty($_POST['text2']) || !valid_email($_POST['text2']) ? '' : 'hidden'; } else { $name_error_vis = 'hidden'; $email_error_vis = 'hidden'; } function valid_email($email) { $formatTest = '/^[-\w+]+(\.[-\w+]+)*@[-a-z\d]{2,}(\.[-a-z\d]{2,})*\.[a-z]{2,6}$/i'; $lengthTest = '/^(.{1,64})@(.{4,255})$/'; return (preg_match($formatTest, $email) && preg_match($lengthTest, $email)); } ?> Change the fields like this: <tr> <td> <span class="style5">NAME ON CARD: </span> <span id="nameOnCard_err" style="color:red;visibility:<?php echo $name_error_vis; ?>;" title="Name is required and must contain only letters">[X]</span> </td> <td><input name="text" type='text' class="violet " id='nameOnCard'></td> </tr> <tr> <td> <span class="style5">EMAIL: </span> <span id="email_err" style="color:red;visibility:<?php echo $name_error_vis; ?>;" title="Email is empty or not valid">[X]</span> </td> <td><input name="text2" type='text' class="violet " id='email' /></td> </tr> Note: I used my php email validator script which is different than your javascript email validator. Here is my javascript script that is consistent with the php one: function validEmail(emailStr) { //Return true/false for valid/invalid email formatTest = /^[-\w+]+(\.[-\w+]+)*@[-a-z\d]{2,}(\.[-a-z\d]{2,})*\.[a-z]{2,6}$/i lengthTest = /^(.{1,64})@(.{4,255})$/ return (formatTest.test(emailStr) && lengthTest.test(emailStr)); }
-
You can also try echoing your query to the page to ensure all the variables are set properly. Are you positive that $forumpostid and $id have valid values?
-
Then you should have left the question and added the answer for others looking for the same solution.
-
Validate how? A checkbox is either checked or it is not. If it is not checked then the field is not included in the POST data. Then just do the same type of validation in the PHP code and set the visibility of the spans based upon the result of the validation? If I was going to do all of that I would probably write it completely different, but I was working with the code you provided.
-
[SOLVED] prevent select from selecting an item during blur event
Psycho replied to shutat's topic in Javascript Help
I've read your post a few times now and am still perplexed by what you arereally doing - I suspect there is probably a better way to accomplish what you are doing by changing the functionality in your "working" functions. Posting the code for a working page would be helpful to see the problem first hand. I tried building a test page to replicate what I think your problem is, but I couldn't create the problem. I have an onchange event for the select lists and I also have an onkeydown event. The onkeydown event changes the value of the select field and then changes focus to the other select list. When that happens the onchange event does not fire - it only fires when the user changes the value, not when the functins hnage the value. Here is the test page which includes code that I could have used to suppress the onchange event if it was fired from changing the vlaue in code (commented out) <html> <head> <script type="text/javascript"> // var runOnChange = true; function s_onchange() { // if (runOnChange) // { alert('Run on change code'); // } // else // { // runOnChange = true; // } } function s_onkeydown(sObj) { sObj.value = (sObj.selectedIndex==1) ? 'one' : 'two'; sObj.blur(); if (sObj.name=='test1') { document.forms[0].test2.focus(); } else { document.forms[0].test1.focus(); } // runOnChange = false; } </script> </head> <body> <form action=""> <select name="test1" onchange="s_onchange();" onkeydown="s_onkeydown(this);"> <option value='one'>one</option> <option value='two'>two</option> </select> <br> <select name="test2" onchange="s_onchange();" onkeydown="s_onkeydown(this);"> <option>one</option> <option>two</option> </select> </form> </body> </html> -
A mysql error does not indicate the line number error in your PHP code -it indicates the error in the mysql query.
-
Well there's a lot I would do differently. I've rewrote the vlaidation for only the name and email fields to include in-place error indicators in addition to a single error message for all the errors. Not the the in-place error indicators include hover text (titles). I would use an image for this purpose in an actual implementaion. <html> <head> <style type=text/css> input.blue {background-color: #0066FF; font-weight: bold; font-size: 12px; color: white;} input.violet {background-color: #ccccff; font-size: 14px;} textarea.violet {background-color: #ccccff; font-size: 14px;} option.red {background-color: #cc0000; font-weight: bold; font-size: 14px; color: white;} option.pink {background-color: #ffcccc;} .style2 { color: #990000; font-weight: bold; font-size: 36px; font-family: Verdana, Arial, Helvetica, sans-serif; } .style5 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; } .style6 {font-family: Arial, Helvetica, sans-serif} body { background-color: #FFFFCC; } </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <title>MOVIE BOOKING</title> <script type='text/javascript'> function report()// TAKEN FROM http://www.tizag.com/javascriptT/javascriptform.php { if (formValidator()) { var thisForm = document.myForm; } } function formValidator() { var errors = new Array(); // Check name field if(empty('nameOnCard') || !isAlphabet('nameOnCard')) { document.getElementById('nameOnCard_err').style.visibility = ''; errors[errors.length] = "Name is required and must contain only alpha characters"; } else { document.getElementById('nameOnCard_err').style.visibility = 'hidden'; } // Check email field if(empty('email') || !validEmail('email')) { document.getElementById('email_err').style.visibility = ''; errors[errors.length] = "Email is not valid"; } else { document.getElementById('email_err').style.visibility = 'hidden'; } if (errors.length==0) { return true; } var error_msg = 'The following errors occured:\n\n'; for (i=0; i<errors.length; i++) { error_msg += ' - ' + errors[i] + '\n'; } alert(error_msg); return falses; } function empty(elem_id) { return (document.getElementById(elem_id).value.length == 0); } function isAlphabet(elem_id) { var alphaExp = /^[a-zA-Z]+$/; return document.getElementById(elem_id).value.match(alphaExp); } function validEmail(elem_id){ var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; return document.getElementById(elem_id).value.match(emailExp); } // CALCULATIONS TAKEN OUT------------------------------------------------------------------------------------------------------------ /* function CheckChoice(whichbox)//TAKEN FROM http://javascript.internet.com/forms/order-form.html { with (whichbox.form) { if (whichbox.type == "radio") { hiddentotal.value = eval(hiddentotal.value) - eval(hiddenpriorradio.value); hiddenpriorradio.value = eval(whichbox.price); hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price); } else { if (whichbox.checked == false) { hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value); } else { hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value); } } if (hiddentotal.value < 0) { InitForm(); } return(formatCurrency(hiddentotal.value)); } } function formatCurrency(num)//TAKEN FROM http://javascript.internet.com/forms/order-form.html { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '£' + num + '.' + cents); } function InitForm()//TAKEN FROM http://javascript.internet.com/forms/order-form.html { //Reset the displayed total on form: document.myform.total.value='£0'; document.myform.hiddentotal.value=0; document.myform.hiddenpriorradio.value=0; document.myform2.total.value='£0'; document.myform2.hiddentotal.value=0; document.myform2.hiddenpriorradio.value=0; document.myform2.hiddenpriorradio.value=0; for (xx=0; xx < document.myform.elements.length; xx++) { if (document.myform.elements[xx].type == 'checkbox' | document.myform.elements[xx].type == 'radio') { document.myform.elements[xx].checked = false; } } for (xx=0; xx < document.myform2.elements.length; xx++) { if (document.myform2.elements[xx].type == 'checkbox' | document.myform2.elements[xx].type == 'radio') { document.myform2.elements[xx].checked = false; } } } ---------------------------------------------------------------------------------------------------------------------------------------*/ </script> <body> <FORM NAME="myForm" action="http://localhost/adw%20php_v3/response%20cinema%20booking_v1.php" METHOD="POST" onSubmit="return formValidator();"> <div align="center"><span class="style2">ONLINE MOVIE BOOKING </span> </div> <div align="center"> <table width="444" border="1"> <tr> <td><span class="style5">NAME ON CARD: </span><span id="nameOnCard_err" style="color:red;visibility:hidden;" title="Name is required and must contain only letters">[X]</span></td> <td><input name="text" type='text' class="violet " id='nameOnCard'></td> </tr> <tr> <td><span class="style5">EMAIL: </span><span id="email_err" style="color:red;visibility:hidden;" title="Email is empty or not valid">[X]</span></td> <td><input name="text2" type='text' class="violet " id='email' /></td> </tr> <tr> <td><span class="style5">CARD NUMBER: </span></td> <td><input name="number" type='number' class="violet " id='cardNumber'></td> </tr> <tr> <td><span class="style5">CARD TYPE: </span></td> <td><span class="style6"> <select name="select" id='cardType'> <option class="red" >Please Choose</option> <option class="pink" >VISA</option> <option class="pink" >Mastercard</option> <option class="pink" >American Express</option> </select> </span></td> </tr> <tr> <td><span class="style5"><br /> MOVIES: </span></td> <td><span class="style6"> <select name="select2" id='movie'> <option class="red" >Please Choose</option> <option class="pink" >Burn After Reading</option> <option class="pink" >Planet Terror</option> <option class="pink" >Tropic Thunder</option> <option class="pink" >Quantum of solace</option> </select> </span></td> </tr> <tr> <td><span class="style5">DATE: </span></td> <td><span class="style6"> <select name="select3" id='date'> <option class="red" >Please Choose</option> <option class="pink" >October 20</option> <option class="pink" >October 21</option> <option class="pink" >October 22</option> <option class="pink" >October 23</option> <option class="pink" >October 24</option> <option class="pink" >October 25</option> <option class="pink" >October 26</option> <option class="pink" >October 27</option> </select> </span></td> </tr> <tr> <td><span class="style5"><br /> TIME: </span></td> <td><span class="style6"> <input type="radio" value="10:40am" name="time" /> 10:40am<br /> <input type="radio" value="1:00pm" name="time" /> 1:00pm<br /> <input type="radio" value="3:50pm" name="time" /> 3:50pm<br /> <input type="radio" value="6:10pm" name="time" /> 6:10pm<br /> <input type="radio" value="8:40pm" name="time" /> 8:40pm<br /> <input type="radio" value="9:10pm" name="time" /> 9:10pm</span></td> </tr> </table> </div> <p align="center"><br> <textarea rows="5" cols="36" name="info" readonly></textarea> </p> <p align="center"> <input class="blue" type="button" name="buttont" value="SUBMIT" onClick= "report()"> </p> <p align="center"> <input class="blue" name="Submit2" type="reset" value="CLEAR ALL FIELDS" /> </p> </form> </body> </html>
-
Why aren't you adding any code to test if the query is even working? $query = "INSERT INTO songcomments (songID, userID, username, comment, date) VALUES ('2', '2', '2', '2', DATE_ADD(NOW())"; mysql_query($query) or die ($query.'<br><br>'.mysql_error());
-
I'm in complete agreement with Crayon (also because looping queries, such as that, is terribly inefficient and will probably slow to a crawl). By just randomly assigning SSN's to users you risk giving them a SSN that a later user might legitimately need. But, let's assume the "worst case" scenario: You cannot change the DB field properties, it is an int type field, and it is set to be unique. Well, SSNs are in the format xxx-xx-xxxx. According to this page: http://www.ssa.gov/employer/stateweb.htm the value 000 is not a legitimate value for the first three numbers. So, you could use anything from 0 to 999,999 (000-00-0000 to 000-99-9999) to identify users that did not have a valid SSN. You could also use that information for later when trying to clean up the data or to display "No SSN" for those records within the system. So, if you use that method then you can always find the next available invalid ID like this: $query = "SELECT ssn FROM table WHERE ssn < 1000000 ORDER BY ssn DESC LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); $last_invalid_ssn = mysql_result($result, 0); $next_invalid_ssn = $last_invalid_ssn + 1; Of course if you go over 1 million invalid records you would have a problem.
-
Change this $font_size = $font_max_size; To this $font_size = $band_font; There was a discrepency between variable names because I'm trying to tie two different scripts together.