Jump to content

techtheatre

Members
  • Posts

    87
  • Joined

  • Last visited

    Never

Everything posted by techtheatre

  1. I have a script that needs to update a record in a database (standard UPDATE query). Unfortunately, this script is in a general function used by a variety of processes in my scripts, and occasionally there is no record to update, so i would need to use an INSERT query. Is there another type of query besides INSERT and UPDATE that will instead UPDATE if it exists, and if not, INSERT?... Currently i have to run an extra query just to see if it exists before i can run the actual query that i need to run...surely there is a better way...some sort of conditional insert/update... Thanks!
  2. Apparently "fenway" did not get the point of my question as he/she thought that this topic needed to be moved to the freelancing section. I AM NOT however looking to have someone write this script...i am sure that there are countless instances of it out there already open source because I see it in use frequently. I am only looking for guidance as to WHERE TO LOCATE such a script. I believe i said that pretty clearly in my original post when i said: Thanks for the "help" fenway, but next time let me post my question where it best belongs and not worry about you moving it in some completely unrelated category. This was originally posted in JavaScript. If someone reads this who has the ability to move it back, that would certainly be appreciated.
  3. Anyone know a way to autosave the data contained in a form using AJAX? Basically i have a form with LOTS of fields and it takes a long time to get them all filled out. I want to set up javascript to run a function every 5 minutes (for example) that silently submits the form. When the form is submitted all that happens is that the form data is all saved (in MySQL with UPDATE function), so if i could silently submit the form and just let the user continue working without knowing anything even happened, that would be ideal. Seems like this should be easy, but i can't find a way to submit the form content without redirecting the form to the submission page. Can this be done silently? Thanks! :-\
  4. I am looking for a JavaScript that will do something similar to the "top stories" slideshow found at Time.com I have located "Frontpage Slideshow" which is a commercial plugin for Joomla, however the site i am working on is not based in Joomla, so that does me no good. Could anyone point me in the right direction (even an appropriate Google search phrase, as i seem to be completely striking out). Thanks! The Key Points: 1. Needs to NOT use Flash. 2. Should show feedback about which article number/slide we are viewing (never more than 4 or 5) 3. Should link (when clicked) to a page URL not an enlarge image (as most slideshows do) 4. Must be cross-browser compatible and degrade nicely to a single link/image (probably just with "<noscript>" tag) THANKS!
  5. Okay...i have some new info (but still need help)... First of all, here is the line that is called in the popup that triggers the ajax reload in the main window and also closes the popup at the same time: onLoad="window.opener.ajaxFunction();self.close();return false;" Here is why that matters...it all works (still) in Internet Explorer 7. It still does not work in Firefox. I have discovered that the problem is that the popup closes before the ajax call function completes. If I remove the self.close() command from my popup window, the main window refreshes its content with no problem. Unfortunately, I need to have the popup close itself...so this is not a solution. Is there a way to tell the ajaxFunction() to execute and not care if the code that initially told it to execute sticks around? I know i could build in a delay on the self.close() but that is not really the solution i am looking for either. Hopefully someone knows what i can do to solve this for Firefox. THANKS! :-\
  6. well...all you need to do is google "AJAX Tutorial" to uncover hundreds of basic scripts to handle an ajax call...here is one that i have used in teh past: <script language=\"javascript\" type=\"text/javascript\"> <!-- //Browser Support Code function ajaxFunction() { var ajaxRequest; // The variable that makes Ajax possible! try { // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\"); } catch (e) { try { ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\"); } catch (e) { // Something went wrong alert(\"Your browser broke!\"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function() { if(ajaxRequest.readyState == 4) { // the next line inserts retrieved data into a DIV area called <AjaxContentDiv>...change this to whatever the ID of your DIV is document.getElementById('AjaxContentDiv').innerHTML=ajaxRequest.responseText; } } var lookupRequest = 'page/to/call/here.php'; ajaxRequest.open(\"GET\", lookupRequest, true); ajaxRequest.send(null); } //--> </script> There are two parts of this code to modify: 1. the name of your <div> (in this case, change "AjaxContentDiv" to "hits") 2. the URL of the script that returns your value ( var lookupRequest = 'page/to/call/here.php'; ) Other thoughts: I still think that even with 2000 visitors each day (which you may want to check out Google Analytics because you probably have a skewed view of your "real" traffic if you are managing a website with that much traffic but don't know the basics of modern web development), you are going to ruin the good benefits of ajax by requesting updates every 5 seconds...this is not what ajax was developed for and will product tremendous server and client overhead. On top of that, if you do the math... 2000 per day / 24 hours = 83 per hour 83 per hour / 60 minutes = 1.3 hits per minute This would indicate that refreshing the hit count once per minute should be sufficient...or at the most once every 45 seconds. Obviously you can (and will) do whatever you want, and the tools are available to do it...but i think that your plan should be at least somewhat re-considered.
  7. give this a shot...(NOTE: I did not create this code, it was given to me in response to a similar post that i made on another forum at: http://www.webmasterworld.com/css/3337813.htm) <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title>test page</title> <script type="text/javascript" language="JavaScript"> <!-- Copyright 2006 Bontrager Connection, LLC var cX = 0; var cY = 0; function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;} function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;} if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; } else { document.onmousemove = UpdateCursorPosition; } function AssignPosition(d) { d.style.left = (cX+10) + "px"; d.style.top = (cY+10) + "px"; } function HideContent(d) { if(d.length < 1) { return; } document.getElementById(d).style.display = "none"; } function ShowContent(d) { if(d.length < 1) { return; } var dd = document.getElementById(d); AssignPosition(dd); dd.style.display = "block"; } function ReverseContentDisplay(d) { if(d.length < 1) { return; } var dd = document.getElementById(d); AssignPosition(dd); if(dd.style.display == "none") { dd.style.display = "block"; } else { dd.style.display = "none"; } } //--> </script> <style type="text/css"> div.FAQ { color: #336633; font-weight: bold; font-size: 12px; font-family: Arial, sans-serif; background-color: #ffffcc; text-align: center; padding: 10px; border: solid 1px; position: absolute; display: none } #UNIQUEID { background-color: #ffc; position: absolute; display: none } </style> </head> <body bgcolor="#ffffff"> <p> blah blah blah... </p> <p> blah blah blah... </p> <p> blah blah blah... </p> <p> blah blah blah... </p> <a onmouseover="ShowContent('UNIQUEID'); return true;" onmouseout="HideContent('UNIQUEID'); return true;" href="#" target="_self">LINK</a> <div id="UNIQUEID" class="FAQ">IMAGE OR TEXT HERE<br> </div> <p></p> </body> </html> hope this helps.
  8. several thoughts... one is that you should be careful wiht this...refreshing the content every 5 seconds is PROBABLY going to be a bit overkill unless you are really expecting LOTS of traffic on the website. This will simply lead to extra unnecessary overhead on your server and bandwidth. If you really do have hundreds of new hits every minute, maybe you should program a "fake" hit counter that starts wiht your current number and increments it locally on its own based on the average rates of new visitors to your site. It could check in with the server every couple minutes to adjust as needed in case the numbers are not jiving perfectly. two...the </div> tag needs to be closed INSIDE the body section...rather than outside it: ...<body><div>content in here</div></body>... three...your javascript should be placed outside the div, as you will be replacing the entire contents of the div four...you can set a timer in your javascript using: setTimeout(expression, msec); your 5-second example would be 5000 milliseconds (the second parameter) five...you will want to find a basic/generic ajax function (there are thousands of tutorials on implimenting ajax...just Google that) to call as the expression, and then replace this DIV's contents with the returned value from the AJAX request I hope this helps.
  9. Okay...I found line 106 (in firebug's line numbering)...an excerpt follows: (the line numbers are not in the original posting...but are left here for clarity) 102 ajaxRequest.onreadystatechange = function() 103 { 104 if(ajaxRequest.readyState == 4 || ajaxRequest.readystate == 'complete') 105 { 106 if (ajaxRequest.status == 200) 107 { 108 // SUCCESS 109 // the next line inserts retrieved data into a DIV area called <AjaxContentDiv> 110 document.getElementById('AjaxContentDiv').innerHTML=ajaxRequest.responseText; 111 } 112 else 113 { 114 // this might be a 404 if the page is missing (or other error number) 115 document.getElementById('AjaxContentDiv').innerHTML = '<strong><font color="red">ERROR: Unable to access source data.</font></strong>'; 116 // alert("ERROR: Page status is " + ajaxRequest.status); 117 // return false; 118 } 119 } 120 else 121 { 122 // readyState has changed but <> 4 123 document.getElementById('AjaxContentDiv').innerHTML = '<img src="images/ajax_loading.gif"> LOADING...'+ajaxRequest.readyState; 124 } 125 126 } So, now that this bit of info is cleared up...what does it all mean? My best guess (and remember i am a noob at this and really am just shooting in the dark) is that the ajaxRequest.status value is somehow not defined. This seems odd, since in order to get to that line of code at all, the ajaxRequest.readyState is supposed to equal 4 (or "complete"), which my screen output indicates is not happening...it stalls out at 2...but that may just be that it is skipping 3 and has not yet gotten to the line that would display the new output...it breaks too soon. Anyway, it seems that the need for a return value of 200 (which i added in because i read it online somewhere that it is necessary for error checking) is causing the problems. How do i ensure that a valid page response code is returned (or is this not even the problem)? Thanks!
  10. Well...unfortunately i am new to the firebug add-in (i have heard about it for a while, but never installed it). i have it now (and it is very cool)...but i don't know where to look for whatever i am looking for. I did get an error under the "console" tab when i made the request, so i assume that this has to do with the problem at hand...but the message doesn't begin to mean anything to me: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://xxxxx.xxxxx.com/admin/prod_opt_manage.php?ProdId=257 :: anonymous :: line 106" data: no] http://xxxxx.xxxxx.com/admin/prod_opt_manage.php?ProdId=257 Line 106 I looked at line 106 in my script, and in the outputted HTML...and there is nothing even related to this on either of those lines...??? Any idea what the above means or where to look for the problem? Why is it working fine in IE but Firefox is finding this error? THANKS!!
  11. i have re-posted the last part of this in the AJAX section of this forum. Here is the link: http://www.phpfreaks.com/forums/index.php/topic,157804.0.html I am also marking this as "solved"...though the question does continue at the other location. Thanks.
  12. I have a page that calls an ajax function "ajaxFunction();" with an onLoad call when the page first is opened. This populates part of the page with external data. Then the user may click an "edit" link that opens a popup window. Upon completion in that window, they click a link that closes the window and "refreshes" the ajax content (from the same URL as the initial page load): <a href="#" onclick="window.opener.ajaxFunction();self.close();return false;">close this window</a> This works fine in IE7, but Firefox starts the new ajax request but gets stuck at readystate == 2. For troubleshooting, I have a mouseover link on the "main" (window.opener) page that i can use to manually trigger my ajaxFunction() script, and that link successfully refreshes the content in Firefox, so the problem has something to do with calling it remotely and then closing out the window (i think). This is the link (in the main window) that works fine: <a href="#" onmouseover="ajaxFunction();">RELOAD (mouseover)</a> Here is my (very generic) AJAX scripting: <!-- AJAX BEGIN --> <script language=\"javascript\" type=\"text/javascript\"> <!-- //Browser Support Code function ajaxFunction() { var ajaxRequest; // The variable that makes Ajax possible! try { // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\"); } catch (e) { try { ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\"); } catch (e) { // Something went wrong alert(\"Your browser broke!\"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function() { if(ajaxRequest.readyState == 4 || ajaxRequest.readystate == 'complete') { if (ajaxRequest.status == 200) { // SUCCESS // the next line inserts retrieved data into a DIV area called <AjaxContentDiv> document.getElementById('AjaxContentDiv').innerHTML=ajaxRequest.responseText; } else { // this might be a 404 if the page is missing (or other error number) document.getElementById('AjaxContentDiv').innerHTML = '<strong><font color=\"red\">ERROR: Unable to access source data.</font></strong>'; } } else { // readyState has changed but <> 4 document.getElementById('AjaxContentDiv').innerHTML = '<img src=\"images/ajax_loading.gif\"> LOADING...'+ajaxRequest.readyState; } } var lookupRequest = 'ajax_display_options.php?OpdId=$OpdId'; ajaxRequest.open(\"GET\", lookupRequest, true); ajaxRequest.send(null); } //--> </script> <!-- AJAX END --> Any ideas why Firefox (and maybe Safari/Opera...i don't have those) is unhappy and what I can do to resolve this? Thanks! :-\
  13. okay...so i got it (mostly). The following works: onLoad="window.opener.ajaxFunction();self.close();return false;" The only problem is (and this could be completely unrelated) that if i execute the function this way in Firefox, it never seems to complete the Ajax request. It wirks perfectly in IE7. Anyone know what the problem may be (i can post the source in a new thread if nobody has ideas without seeing it). This is a pretty standard ajax request, and it is getting stuck in the "loading" loop (in firefox, not in IE): ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4) { if (ajaxRequest.status == 200) { // SUCCESS // the next line inserts retrieved data into a DIV area called <AjaxContentDiv> document.getElementById('AjaxContentDiv').innerHTML=ajaxRequest.responseText; } else { // this might be a 404 if the page is missing (or other error number) alert(\"ERROR: Page status is \" + ajaxRequest.status); return false; } } else { // readyState has changed but <> 4 document.getElementById('AjaxContentDiv').innerHTML = '<img src=\"images/ajax_loading.gif\"> LOADING...'; } Thanks!
  14. So...i have found out that the "opener" window (originally i was calling this the "parent" since i did not know the correct terminology) can apparently be controlled using the following reference: window.opener.document Unfortunately, even armed with this information, i am still not sure how to run my function "ajaxFunction()" on that window. I know i am making progress, but if anyone has time to point me in the right direction or tell me how to use window.opener.document (or something else) to run my function from the popup window, that would be awesome. THANKS!
  15. i am re-posting the above, because the banner ad seems to have resized the source code snippet i provided, so i think it may be easier to read marked as a quote rather than as code: i have a page (happens to be php) that initializes a javascript popup as follows: i want to run a javascript function in the main (parent) window when the popup is closed. This function will reload the content of the window (actually the content of one section of the page using ajax) to reflect the change made with the popup. Basically, when the popup is closed (which will hopefully happen either by a link click or automatically...both using onLoad="self.close();return false;" ) then the main window should execute a function like: ajaxFunction(); i know pretty much nothing about javascript, but i tried the following with no success: onLoad="parent.ajaxFunction();self.close();return false;" Thank you in advance for any help you can provide!
  16. i have a page (happens to be php) that initializes a javascript popup as follows: <a href="option_edit.php?Action=edit&Id=$Id\" target=\"EditPage\" onclick=\"window.open('option_edit.php?Action=edit&Id=$Id','EditPage','height=255, width=400,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no'); return false;">edit</a> i want to run a javascript function in the main (parent) window when the popup is closed. This function will reload the content of the window (actually the content of one section of the page using ajax) to reflect the change made with the popup. Basically, when the popup is closed (which will hopefully happen either by a link click or automatically...both using onLoad="self.close();return false;" ) then the main window should execute a function like: ajaxFunction(); i know pretty much nothing about javascript, but i tried the following with no success: onLoad="parent.ajaxFunction();self.close();return false;" Thank you in advance for any help you can provide!
  17. Thanks for your help. i did not know i could do JOINs using multiple variables like that (i thought the same element had to be in all tables of the JOIN). The reason that i am limiting everything to 1 result is that this query is really just piecing together the necessary elements to send an email to the customer...including their name, address, and recent transaction summary. I only need the results for this one order, so this is why i put LIMIT 1. Thanks!
  18. i have data located in three tables that i need to pull out to generate a report. Unfortunately, there is no common element between each table, so a normal JOIN will not work. Currently my script WORKS, however it relies on one query executing successfully followed by another and then a third. Is there some way to combine all this into one query or some other way to make it easier to read and manage? Modifying my table structure is not an option at the moment. My eventual values that need to be populated are: $CustomerName $CustomerEmailAddress $CartContentSummary $sql = "SELECT CustomerId, BillToId, CartContentSummary FROM InvoiceData WHERE InvoiceId='$InvoiceId' LIMIT 1"; //echo $sql; $result = mysql_query($sql, $db); while($row = mysql_fetch_array($result)) { $CartContentSummary = $row['CartContentSummary']; $BillToId = $row['BillToId']; $CustomerId = $row['CustomerId']; $sql = "SELECT Email FROM CustomerAccounts WHERE CustomerId='$CustomerId' LIMIT 1"; //echo $sql; $result = mysql_query($sql, $db); while($row = mysql_fetch_array($result)) { $CustomerEmailAddress = $row['Email']; $sql = "SELECT FirstName, LastName FROM Addresses WHERE AddressId='$BillToId' LIMIT 1"; //echo $sql; $result = mysql_query($sql, $db); while($row = mysql_fetch_array($result)) { $CustomerName = $row['FirstName']." ".$row['LastName']; // if we get this far we have been successful ! } } } THANKS!
  19. good point. Thanks! I will switch the order of those... As far as the <condition> ? <true> : <false> it is usually referred to as shorthand (and is a heck of a lot quicker/easier to use)...i don't know if it is really any slower...and certainly would not matter at the low level that I program...but i thought i would mention it just in case since i had read about it. I am trying to start using the long format when i remenber. Anyway, probably only a small matter that really doesn't affect anythign anyway. Thank you for your help!
  20. Right...except i can run the function on specific variables too...and control whether htmlentities is done or not...that is why i have it set up as one of the variables (with false as the defualt) that gets passed to the function. Your methods do look much cleaner to use. A definitely agree that i should use get_magic_quotes_gpc internally since that is the only condition used for stipslashes (at least now). One (or two) question(s): to solve the problem with passing a numeric value to the second function...couldn't the line be changed to: return is_null($value) || ( empty($value) && $value!=0 ) ? "NULL" : "'".mysql_real_escape_string( $htmlentities ? htmlentities($value) : $value )."'"; I have heard that the ternary operator (aka ? degrades performance slightly. For better performance, the longer-winded version is better (even if it requires more code). (reference: Ilya's talk at EZ-Norway). As such...using my example above...would the following work? if( is_null($value) || ( empty($value) && $value!=0 ) ) { return "NULL"; } else { if ( $htmlentities ) { return htmlentities($value); } else { return $value ; } } THANKS!
  21. I do not completely understand what you are asking...please provide more detail... my best guess is that you are starting to create a new table (or set a key in an existing table). If this is the case, i doubt that a primary key can be set on a field of the type "blob"...you will want to use a numeric (int) field for your primary key...any you should probably set it to auto_number so that you don't have to worry about anything. if this is not what you are asking...sorry...please provide more detail. Good luck!
  22. So i have the following function i have been working on...it seems (to me) that it logically SHOULD work and i plan to run it on all $_POST and $_GET arrays upon page load on all my form submittal pages before i insert the data to my databases. The function should take a variable that i pass (either a string or an array) and parse it however is necessary (strip slashes and convert htmlentities...do i need anything else i have left out?), I am trying to set up the function so that i can simply call it on all my pages at the top and immediately secure all my forms. I am using var_dump($_GET) for now at the top and bottom of the "processing" page to see what is happening and if it is working, but it keeps returing bool(false) for each value within the array. Please let me know what i am doing wrong, and also if there are other considerations i should be making (or an easier way to accomplish this). THANKS!! function PrepareArrayOrStringForDB($val,$stripSlashes=false, $htmlEntities=false) { if( is_array($val) ) { //if we need to strip slashes (default is false, but appropriate value (true/false) can be passed by calling get_magic_quotes_gpc() in the function call) if( $stripSlashes ) { foreach( $val as $ky=>$vl) { $val[$ky]=stripslashes( $vl ); } } //if we need to convert characters to HTML equivalents if( $htmlEntities ) { foreach( $val as $ky=>$vl) { $val[$ky]=htmlentities( $vl ); } } //this should always be done before values are inserted into a database foreach( $val as $ky=>$vl) { $val[$ky]=mysql_real_escape_string( $vl ); } } else { //if we need to strip slashes if( $stripSlashes ) { $val = stripslashes( $val ); } //if we need to convert characters to HTML equivalents if( $htmlEntities ) { $val = htmlentities( $val ); } //this should always be done before values are inserted into a database $val= mysql_real_escape_string($val); } return $val; } <?php var_dump($_GET); echo "<br /><br />"; $_GET = PrepareArrayOrStringForDB($_GET, get_magic_quotes_gpc(), true); var_dump($_GET); ?>
  23. Okay. i am happier deleting it anyway...just to keep the clutter away... Thank you VERY much for your help on this. It will make the image filtering process work much better.
  24. okay...the script works...but i have a technical question... I am checking this immediately upon form upload...so the actual file is not really stored yet on teh server in a permanent location. Below is the first part of the code you supplied, bt look at my $img_path...it is working great for determining the dimensions (and filetype)...but i wonder if unlink() is the appropriate way to destroy this uploaded and unwanted file of if there is some other command that i should substitute in this place since the file is not "permanent" yet... //CODE SNIPPET...SEE PREVIOUS POST FOR ENTIRE CODE //check that the size and filetype are ok $img_path = $_FILES['imageone']['tmp_name']; $img = getimagesize($img_path); list($height,$width) = $img; if($height > 1024 || $width > 768) { echo "Your uploaded image is too large. The maximum allowed size is 1024x768 px. Your image was {$height}x{$width}px."; unlink($img_path); } // etc...
  25. It seems that it would work, however isn't the getimagesize() function a part of the GD library...and thus won't that part still choke if the image is too large?...if not, then this is super easy...but i had avoided that function as i thought it would have the smae problem that the rest of GD apparently has over 1024px × 768px. I will give it a try and see what happens with a very large image...i'll post a follow up in a couple minutes. BTW: I love your "most complex hello world implimentation ever" script in your signature!
×
×
  • 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.