Jump to content

arianhojat

Members
  • Posts

    235
  • Joined

  • Last visited

    Never

Everything posted by arianhojat

  1. I was trying to debug this error and i coulda swore i used childNodes[0] many times be4 without it failing. but the code is rather simple so childNodes is probably the problem... i am looking at this xml in my response var... <info><isDirector>false</isDirector></info> When my js code gets executed and arrives at this line it automatically quits... var isDirector = response.getElementsByTagName('isDirector').childNodes[0].firstChild.nodeValue; Cuts off without any javascript error in FireFox (errrr I really hate DOM errors like that). i noticed however this works... var isDirector = response.getElementsByTagName('isDirector')[0].firstChild.nodeValue; i assumed getElementsByTagName returns an array of the html/xml collection and u probably should use childNodes syntax to drop into the xml node, and get its child node and then its text node value. Why should the array syntax be working better than the more appropriate xml syntax to get the child node? thanks!
  2. Hello All, I have a database of seats and what the seats names are 101, 102 for one venue (or A1, A2 if another venue with different named seats). and those seats are associated in another table to a section, Like section A, B, C, (or arbitrary names like Section 1 for 101, 102 seats). I also have seats associated to rows in case I need to use that so A1-100 might all be considered same row wrapping around venue. Then i also associate those seats to 'chunks' in another table for ticket calculations in php. like A1 to A20 are together in chunk1, then a entrance into stadium breaks up the row, and A20-40 starts (and also a table associating what section that chunk is in). I think a table like this is good so when the user clicks 4 tickets, if the event isnt General Admission, my script tries to find seats together on that section. So for an event I have option for AllGeneralAdmission in that event table. If that value is false then that means the event doesnt have one price across the board, so I look up prices to specialized areas, (but if true, i just set the general price in this table). So in another table I associate areas like GA, Floor, Mezzanine pricing to that event and their respected price. and in another table what sections are associated to those pricing schemes. Best idea I had is let user pick what seating he wants (GA, Floor, Mezzanine) and then find the sections in the area they choose from that last table. then i can find out what chunks are in that section and go chunk by chunk finding seats. then report back the 1st match or give them options on what chunk to choose maybe? Is there anything that you would you change in database table setup and php script? I am not sure if there is a more professional type setup (i saw ticketmaster had section seating, GA seating, and i think also even varying seat prices by section). I made this database setup myself, but if one has something better or a tutorial online, let me know Thanks in advance!
  3. im gonna guess that if you are on a host, you cannot write system wide, so PEAR is installed in your 'local' directory you have access to.
  4. bump : hmmm had this question come up again, what the difference is between a local copy of PEAR and a system install?
  5. I am just curious if anyone experienced with MDB2 has any tips and things to watch out for if you are moving from just php's mysql/mysqli libs. Thanks in advance, Ari
  6. Not sure what you want.... Set everything inside of clientCategoriesForm to 0? document.clientCategoriesForm.options.length=0; or mess with options themselves document.clientCategoriesForm.adultContent.options
  7. http://www.webdeveloper.com/forum/showthread.php?t=27037 seems like u cannot do a scrollTo if url is not on your own web server. PopupWindow("/myownwebsite/index.html", 'popup'); PopupWindow("http://www.externalwebsite.com/index.html", 'popup');
  8. heres example of AJAX in 2 dynamic dropdowns, NOTE: this with Prototype framework which actually makes code easier and 'shorter'. I also dont do any error checking on values returned, like sometimes my xml might return a value i dont like and want to handle differently, so i have the javascript update the page or alert me and say 'The subcategory description for catID=10 is empty' for example. There are other frameworks maybe more specialized to work with php, xajax?, but i prefer doing it this way: //Your main HTML form <?php echo '<script type="text/javascript" src="javascript/prototype.js"></script>';//download this file echo '<script type="text/javascript" src="javascript/func.js"></script>';//your file with custom 'how to handle stuff' fucntions //.......... echo '<select name="category" id="category" size="10" onchange="changedCategory(this);">'; $Query = "SELECT catID, description FROM category ORDER BY description ASC"; $result = mysql_query($Query) or die ("Error in query: $Query. ".mysql_error()); while($row = mysql_fetch_array($result)) { $description = $row['description']; $catID= $row['catID']; echo '<option value="'.$catID.'">'.htmlspecialchars( $description ) .'</option>'; } echo '</select>'; echo '<select name="subcategory" id="subcategory" size="10">'; echo '</select>'; ?> //your func.js file: function changedCategory(selectField) { var catID = selectField.value; clearList( document.getElementById("subcategory") ); //this is a helper function i use to clear the list, be4 i add stuff to it (cause it might be filled from previous AJAX request) makeTempOption();//just a helper function to add an option saying 'Getting info....' be4 gets actual data var rand = Math.floor(Math.random()*1000); //appends a random variable to AJAX call so the url is different each time. Otherwise it might return the xml file cached/stored in browsers 'memory' from previous request var url = "getInfo.php"; //this is a php file u make to return the subcategories based on category value u send it in the AJAX request var params = "catID=" + escape(catID) +"&random="+ rand;//escape() needed if it was text data being sent to escape special characters in the variable var myAjax = new Ajax.Request( url, { method:'post', parameters: params, onSuccess: changeCategorySuccess, onFailure: ajaxFailure } ); //what js fucntions to call if successfully gets response from your script or fails } function changeCategorySuccess(transport) { var responseXML = transport.responseXML; //the XML text your php file gives back to your javascript var subcategories = responseXML.getElementsByTagName('s');//name of xml nodes to loop through clearList( document.getElementById("subcategory") ); //right now it probably has "GETTING INFO..." option in the list to let user know, its getting values, so need to clear it be4 add new stuff for( var i=0; i < subcategories.length; i++ ) { var subcategory = subcategories[i]; var id = subcategory.getElementsByTagName('i')[0].firstChild.nodeValue; //the ID var desc = subcategory.getElementsByTagName('d')[0].firstChild.nodeValue;//the description for current subcategory var optionTemp = document.createElement('option'); optionTemp.setAttribute("value", id); var textNode = document.createTextNode( desc ); optionTemp.appendChild( textNode ); document.getElementById('subcategory').appendChild( optionTemp ); } } function ajaxFailure (transport) { alert('Unsuccessful: ' + '[Error ' + transport.status + ' -- ' + transport.statusText +']'); } function makeTempOption() { var optionTemp = document.createElement('option'); optionTemp.setAttribute("value", '-100'); var textNode = document.createTextNode( 'GETTING INFO...' ); optionTemp.appendChild( textNode ); document.getElementById('requirements').appendChild( optionTemp ); } function clearList(listID) { var optionsList = listID.getElementsByTagName('option'); for (i = optionsList.length - 1; i>=0; i--) { listID.removeChild( optionsList[i] ); } } //your getInfo.php file <?php $catID = $_POST['catID']; $host = "localhost"; $user = "xxx"; $pass = "yyy"; $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect3!"); $db = "yourDBname"; mysql_select_db($db) or die ("Unable to select database!"); $xml = "<info>"; $Query = 'SELECT s.subcatID, s.description FROM category c JOIN subcategory_cat sc ON c.catID=sc.catID JOIN subcategory s ON sc.subcatID=s.subcatID WHERE c.catID='. $catID .' ORDER BY s.description ASC'; $result = mysql_query($Query) or die ("Error in query: $Query. ".mysql_error()); while( $row = mysql_fetch_array($result) ) { $catID_temp = $row['subcatID']; $catID_description = $row['description']; $xml .= '<s>';//i keep the xml names short so xml file is less data to transfer back to you $xml .= '<i>'. $catID_temp .'</i>'; $xml .= '<d>'. htmlspecialchars($catID_description) .'</d>'; $xml .= '</s>'; } $xml .= "</info>"; echo $xml; //response sent back to javascript code ?>
  9. 1. if u want to do it old school: <?php //fill out your db vars please $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect17!"); $db="yourDBname"; mysql_select_db($db) or die ("Unable to select database!"); $submitBtn = isset($_POST['submitBtn']) ? $_POST['submitBtn']: NULL; $catID = isset($_POST['category']) ? $_POST['category']: NULL; $subcatID = isset($_POST['subcategory']) ? $_POST['category']: NULL; //error checking be4 process and display form if( isset($submitBtn) && (!isset($catID)) ) $error['catIDerror1'] = 'Form was submitted but no category chosen'; if( isset($submitBtn) && (!isset($subcatID)) ) $error['subcatIDerror1'] = 'Form was submitted but no subcategory chosen'; //process if( isset($submitBtn) && (!isset($error)) )// if form was submitted and no errors on form (if errors array wasnt set) { //do any processing on the form since he clicked submit button, INSERT values into database etc. if thats what your form does } //display form if( isset($error) )//post errors to user so he can fix { echo 'Errors occured:<br/>'; foreach($error as $err) { echo '*** Error:'. $err . '<br/>'; } } echo '<select name="category" id="category" onchange="this.form.submit();">'; $Query = "SELECT * FROM category"; $result = mysql_query($Query) or die ("Error in query: $Query. ".mysql_error()); while($row = mysql_fetch_array($result)) { $catID_temp = $row['cat']; $categoryDesc_temp= $row['category']; echo '<option value="'.$catID_temp .'" '. (($catID_temp==$catID)? ' selected="selected"':'') .'>'.$categoryDesc_temp.'</option>'; //...populate options from database while loop with a query... if form was submitted it also checked if current value in loop $catID_temp equals the value submitted $catID, and if so selects it } echo '</select>'; echo '<select name="subcategory" id="subcategory">'; if( isset($catID) ) //if not null, aka the form was posted via submit button or select dropdown onchange. either way a category was selected be4 and user submitted form itself now or just selected the category drop down which also posts the page { $Query = "SELECT * FROM subcategory WHERE cat=".$catID; //the posted catID variable $result = mysql_query($Query) or die ("Error in query: $Query. ".mysql_error()); while($row = mysql_fetch_array($result)) { $subcatID_temp = $row['subc']; $subcategoryDesc_temp= $row['subcat']; echo '<option value="'.$subcatID_temp .'" '. (($subcatID_temp==$subcatID)? ' selected="selected"':'') .'>'.$subcategoryDesc_temp.'</option>'; //...populate options from a database while loop etc with a query } } echo '</select>'; echo '<input type="submit" name="submitBtn" value="submit form" />'; ?> 2. new school: USE Prototype JS library (prototype.js google it): And look up how do to AJAX drop downs, the page doesn't need to be refreshed/POSTed if you do this. I have a general AJAX example here: javascript calls another php page, which returns XML to your javascript, javascript then loops through XML values to populate something on your page. my example doesnt talk about drop down specifically, but might be good to look at to understand it. Prototype bascially simplifies 'AJAX', so u can call a simple function to do all the funky stuff the behind scenes
  10. can you post really simple html example u can post? like just the span or form field that has the number in it and an onclick on a button which runs yer code and alerts you? I can check it out with FireFox/Firebug(FF add-on) and see where problem lies better.
  11. hmm not sure.... Some things to try... Don't have # in actual name, maybe you meant as a placeholder like "Article5" (nvm if that the case). Dont use <font>. Use <span style="display: none" id="article5">. font tag is depreciated, maybe not supported as well as span. Might be security restriction for running things on hotmail, try allowing hotmail.com in your IE Options->Trusted Sites and see what happens. Maybe html email is restricted to certain things.
  12. name="cookie[]" the name is cookie[] not the id, getElementById is only for searching elements with id's. and you may be tempted now to try set id's for all your input elements called 'cookie[]', but ids have to be unique (cant have many elements with all their ids called 'cookie[]'); hence why u must use the name attribute like you are doing so php knows its an array when you submit... You need to access the values via getting the elements in the form. document.forms[0]['cookie[]'] or document.forms['nameOfForm']['cookie[]'] or document.forms[0].elements['cookie[]'] or document.forms['nameOfForm'].elements['cookie[]']
  13. parseInt()'s 1st param is "The string to be parsed" My guess is when you do: var MyIssuedValue = document.getElementById("IssuedValue"); ... var IssuedValue = parseInt(MyIssuedValue,10); MyIssuedValue is the element/OBJECT, when you want the string text in it. document.getElementById("IssuedValue").value might work if its a textfield OR if its just text inside a span or div... document.getElementById("IssuedValue").innerHTML (gets the html inside of element) orrrr... document.getElementById("IssuedValue").firstChild.nodeValue (gets the textNode, then the value of it is the text itself) Ari
  14. Here's another one I ran into recently: ######################################### Have to set a dynamically created form input field's name with extra javascript IF you are need that input field be4 u submit form. Its almost like it creates the name value in DOM but its hidden so you can find the node. Yet if you submit the form, the value is available as GET/POST variable under appropriate name. http://www.phpfreaks.com/forums/index.php/topic,147941.msg635224.html#msg635224 ######################################### Not sure why but i have trouble deselecting select values which werent even dynamically set, Like i click and select a value, and now i want to deselect it via javascript. IE doesnt seem to like looping through and deselecting the values. FF unsets the select with all 3 functions i try. IE goofs up on all but the last (but i wasnt sure if the last is the best approach). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST</title> <script type="text/javascript"> function deselectList1(listID) { var optionsList = listID.getElementsByTagName('option'); for (i = optionsList.length - 1; i>=0; i--) //for(var i=0; i < options.length; i++) { optionsList[i].selected = false; } } function deselectList2(listID) { var optionsList = listID.getElementsByTagName('option'); optionsList[listID.selectedIndex].selected = false; } function deselectList3(listID) { var optionsList = listID.getElementsByTagName('option'); try { listID.selectedIndex = -666; }catch (e) { //alert('length'+ optionsList.length) for (i = optionsList.length - 1; i>=0; i--) //for(var i=0; i < options.length; i++) { optionsList[i].selected = false; } } } </script> </head> <body> <select size="5" name="test" id="test"> <option>AAAA</option> <option>BBBB</option> <option>CCCC</option> </select> <input name="btn" type="button" value="unselect list" onclick="deselectList1(document.getElementById('test'));" /> </body> </html> #########################################
  15. i figured out my problem... Creating input fields with a name property dynamically in javascript sucks in IE6. For example: theNode = document.createElement('input'); theNode.setAttribute('name', 'addedReqs[]'); //using array value so when i POST, php knows to parse as an array or theNode = document.createElement('input'); theNode.name = 'addedReqs[]'; dont work in IE6 if you plan to do stuff dynamically be4 posting. You can submit the page, and it posts values correctly. But be4 posting, if u need to do stuff like loop through those dynamically made fields with document.forms[0]['addedReqs[]'], you cant find them cause it never sets name correctly in the DOM. Need to use in IE6 specifically: theNode = document.createElement('<input name="xxx">'); Here is a function i found to help name elements and websites below help explain why problem occurs: function createNamedElement(type, name) { var element = null; //Try the IE way; this fails on standards-compliant browsers try { element = document.createElement('<'+type+' name="'+name+'">'); } catch(e) { } if (!element || element.nodeName != type.toUpperCase()) { // Non-IE browser; use canonical method to create named element element = document.createElement(type); element.name = name; } return element; } theNode =createNamedElement('input', 'xxx') http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/ http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/
  16. Javascript wont know how to parse that... Try this (assuming editlist is name of form?) document.editlist['itmchk[]'] or document.forms[0].elements['itmchk[]'] or document.forms[0]['itmchk[]'] or document.forms['editlist']['itmchk[]'] one of those WILL work.
  17. I make a hidden input field dynamically via: var inputHidden = document.createElement('input'); inputHidden.setAttribute('type', 'hidden'); inputHidden.setAttribute('name', 'addReqs[]'); //has a '[]' so on POST, php can access many of these dynamic elements in one php array inputHidden.setAttribute('value', SomeVal ); Then if i click a button, i have some javascript code that loops through these elements. var toAdd = document.forms[0].elements['addReqs[]'];//code below checks if value already exists in a hidden form field in the page. if( toAdd ) { alert( 'toAdd111' ); for(var i=0; i < toAdd.length; i++) { if(toAdd[i].value == requirementsVal) return true; } } BUT Internet Explorer (6), refuses to confirm those fields exists, it wont even loop. I have a feeling IE has problem with way its created so i tried following below as well to no avail... inputHidden.name = 'addReqs[]'; inputHidden.value = SomeVal; Anyone have any ideas? Thanks in advance, Ari
  18. bump. summary: anyone got an idea why the batch looks via its directory and not the scripts directory?
  19. Hello all, Had some trouble and kinda stumped on why php behaves this way: In Windows I have a Scheduled Task to run emailer.bat... By the way, for future reference... emailer.bat is not in the web root, E:\Intranet\, it is in E:\batches\. In emailer.bat is the command to run php script on command line: php -a E:\Intranet\HelpDesk\techReqEmailer.php In techReqEmailer.php, is the line require("../phpmailer/class.phpmailer.php"); //or require("/phpmailer/class.phpmailer.php"); doesnt make difference both fail Basically it looks for phpmailer class one parent up in the E:\Intranet\phpmailer\ folder. If I goto http://intranetServer/HelpDesk/techReqEmailer.php, it knows how to find the phpmailer class and sends emails since it knows to look up one level to find phpmailer. However when this file is run from a batch file, it doesnt know how and gives a standard php error for not finding the required class. The only way i got passed this was to put the batch file also in the E:\Intranet\HelpDesk\ folder, AND make it look relative for phpmailer... require("phpmailer/class.phpmailer.php"); (so bascially i have 2 copies of phpmailer now, one folder in main web root for other web scripts that send emails, and one in this folder for the batch script, errr, seems annoying to duplicate the folder)... Is there anyway i can have the batch file placed wherever i want, and leave alone the phpmailer class and techReqEmailer.php will know where to look for it whether its called via web or batch script? it should look for include_path 1st, then based on current directory, which is what i was hoping. but batch file thinsk curretn directory is where the batch is, and not where the php file is. I assumed the php file would only 'know' about itself, and didnt matter if batch file called it. But apprently it does? Thanks for any tips and clarification , Arian
  20. hey barand, Still doesnt work for me. Maybe its an IIS/php issue.
  21. Hey barand, when posting, $_POST still has 0 things in it. So it should at least have the submit button like you said, and MAX_FILE_SIZE hidden var.
  22. Hello all, I am not sure why but I have had this problem for a while and havent really been able to solve it. A really simple php upload script works in IE but not in FF. FF just comes back to the page as if there is no POST information. For example code below will output when landing on the page, it outputs: count:0 NOT SUBMITTED, 5-23-2007 16:13:35 and when trying to post the upload via the html submit button, it outputs immediately: count:0 NOT SUBMITTED, 5-23-2007 16:13:54 but it SHOULD have POST data?, count should be > 0, and it should output SUBMITTED if enctype="multipart/form-data" is removed, it will post the data (of course no upload data though): count:3 data=Array ( [filename] => Array ( [0] => blc.gif [1] => ) [MAX_FILE_SIZE] => 100000000 [submitForm] => Submit ) SUBMITTING <?php echo 'count:'. count($_POST) .'<br/>'; if( count($_POST) > 0 ) { echo 'data='; print_r($_POST); } if( isset($_POST['submitForm']) ) { echo "SUBMITTING<br/>" ; foreach ($_FILES["filename"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $path_parts = pathinfo(__file__); $dir = $path_parts['dirname']."\\uploads"; $tmp_name = $_FILES["filename"]["tmp_name"][$key]; $name = $_FILES["filename"]["name"][$key]; move_uploaded_file($tmp_name, "$dir\\$name"); echo "tmp_name=$tmp_name, name=$name, type=$type, size=$size<br/>" ; } else echo 'error:'.$error; } }//submitted else echo "NOT SUBMITTED, ". date('n-j-Y G:i:s') .'<br/>'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST</title> </head> <body> <form name="upload" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>"> File to upload: <br/> <input type="file" name="filename[]" value="Upload1" /> <br/> <input type="file" name="filename[]" value="Upload2" /> <br/> <input type="submit" name="submitForm" value="Submit" /> </form> </body> </html> When i had this problem, I always thought maybe it was the type of data, like images, word docs, pdfs, specifically in FF. but it looks like i cant upload even text files with this simple script. Anyone got ideas?
  23. btherl, yeh i use that method but maybe i try switching it up with prepared queries now for repeated INSERTs/other queries.
  24. Hello all, I asked this question 3 times in PHP Help forum but no one answered, so hoping maybe a MYSQL guru who uses php might know better... Even though this is more php related, i dont want to post same topic over there again when someone over here might be more knowledgable... Had a few questions regarding sprintf versus prepared statements to protect a query from injection etc. Here are my test examples that my questions are based off of... ##### sprintf example <?php function secure_query($var)//returns variable for database insertion { if (!is_numeric($var))//string return "'". mysql_real_escape_string($var) ."'"; //basically adds slashes to strings, (heard this is betetr than addslashes() as its custom to mysql's current char set ) else return $var;//number } $query = sprintf ( "UPDATE theDB.table SET Description=%s, Comments=%s, age=%i WHERE id=%d", , secure_query($description), (($comments!="") ? secure_query($comments) : 'NULL' ), (($age!="") ? secure_query($age) : 'NULL' ), secure_query($id) ); ?> #####prepared example <?php if ($stmt = $mysqli->prepare("UPDATE theDB.table SET Description=?, Comments=?, age=? WHERE id=?")) { $stmt->bind_param("s", $description ); $stmt->bind_param("s", (($comments!="") ? $comments : 'NULL' ) ); $stmt->bind_param("i", (($age!="") ? $age : 'NULL' ) ); $stmt->bind_param("i", $id ); $stmt->execute(); $stmt->close(); } ?> 1. Is a prepared statement in php safer than say a normal query with formatted with sprintf? what are advantages/dis to each if there are any and what do you prefer? (i know prepared statements are faster if doing many of same query and i beleive dont need to addslashes to the variables you pass it since it does that builtin.). 2. my $comments and $age variables can either have string(or int data respectively) but if those textfields pretend were filled blank by the user, i want to put NULL in the database. Since I can pass an string/integer or 'NULL' to sprintf in those variables, it seems like sprintf will definately not like that 'NULL' is not an integer for example. so would this be a reason not to use sprintf? i guess you could always get passed it by doing... sprintf ( "UPDATE theDB.table SET Description=%s, Comments=%s, age=".( ($age==NULL)?'%s':'%d')." WHERE id=%d", secure_query($description), (($comments!="") ? secure_query($comments) : 'NULL' ), (($age!="") ? secure_query($age) : 'NULL' ), secure_query($id) ); What would you do in this situation, use prepared statement instead? Thanks in advance guys!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.