Jump to content

Greywacke

Members
  • Posts

    510
  • Joined

  • Last visited

Everything posted by Greywacke

  1. a short little test actually revealed that the following javascript code is what actually created this issue. was alerted by opening the following javascript protocol as a url in firefox.which other functions can encode a string containing double quotes without replacing them with multiple weird chars?this issue was posted at first under the PHP forum (http://w3schools.invisionzone.com/index.php?showtopic=30419).
  2. this issue was apparently created by trying to pass a string containing the left and right slanted double quotes (“ and ”) from a form. the weird characters (“ and â€) where inserted by mysql_real_escape_string in their place it seems.how can i insert a string containing any special characters such as a double slanted quote left or right into a mysql db without using mysql_real_escape, also escaping the normal double quotes, etc?i need the special characters (“ and ”) inserted into the db without doing it manually via PMA...they insert with the phpMyAdmin but how would i be able to insert a string containing them into a table via a php, mysql query as an ajax result over POST?the current code for inserting and updating a record is: case 3: // add prospecting message $num = $_POST["text_prospectingnumber"]; $msg = mysql_real_escape_string(str_replace("\n","<br />",$_POST["textarea_prospectingmessage"])); $tsql = "INSERT INTO 12_prospectmessages (bigint_ServiceID, smallint_ProspectMessageCount, text_ProspectMessage) VALUES (".$s.", ".$num.", \"".$msg."\");\n"; $sql .= $tsql; $result = mysql_query($tsql); $err = mysql_error(); $sql .= strtoupper($err)."\n"; break; case 4: // modify prospecting message $num = $_POST["text_prospectingnumber"]; $msg = mysql_real_escape_string(str_replace("\n","<br />",$_POST["textarea_prospectingmessage"])); $mid = $_POST["list_msgid"]; $tsql = "UPDATE 12_prospectmessages SET smallint_ProspectMessageCount = ".$num. ", text_ProspectMessage = \"".$msg."\" WHERE bigint_MessageID = ".$mid.";\n"; $sql .= $tsql; $result = mysql_query($tsql); $err = mysql_error(); $sql .= strtoupper($err)."\n"; break; i can retrieve these two characters from mysql (tested this with phpmyadmin), just inserting or updating with them automatically is a biatch to put it mildly... the weird characters break the xml when inserted into the database!this issue has been confirmed to, in reality, be the result of a javascript function - so discussion has been moved to http://w3schools.invisionzone.com/index.php?showtopic=30432
  3. well duh... i needed to use an OR not an AND originally... DELETE FROM 10_serviceprospects, 13_prospectleadsent WHERE 10_serviceprospects.bigint_ProspectID = 780 OR 13_prospectleadsent.bigint_ProspectID = 780; the 780 representing the ProspectID.
  4. hi there,i am trying to delete from two tables, one containing the leads and one containing the record of forwarding.however, this won't work if the second table returns an empty recordset.the left join seems to work, but it won't delete the record from the first table.here is the sql string: DELETE FROM 10_serviceprospects LEFT JOIN 13_prospectleadsent ON 10_serviceprospects.bigint_ProspectID = 13_prospectleadsent.bigint_ProspectID WHERE 10_serviceprospects.bigint_ProspectID = 780; a lead with id 780 does exist however.the query returns with the following error if i enable : how could i modify this query to only attach the second table where that id exists? add a WHERE EXISTS subquery perhaps?how would i do this? i can't seem to find anything on the web...i guess i'm trying to do an optional delete join here.
  5. the issue was not the use of htmlentities, but the creation of those weird chars in the db content - which in turn screwed up the xml...
  6. hi all,the actual cause of this issue was discovered, please read the last post: http://w3schools.invisionzone.com/index.ph...st&p=165476i was wondering if anyone can help me with the following problem.
  7. thanks justsomeguy i'll try this right away :)AWESOME as i said earlier there where many ways to skin a cat this seems the most straight forward however
  8. this is the current script: // ONLY PARSING THE FIRST TWO ATTRIBUTES... WTF?alert(arr[3]);var opt1 = document.createElement('option');arrt = arr[3].split(/<.+\/>/g,-1);//alert(arrt);var attr = new Array();for (var i = 0; i < arrt.length; i++) { attr[i] = arrt[i].split(/.=./g,-1); alert(attr[i].join("\n"));}var produ = ""; // product namevar pstyl = ""; // product stylevar prequ = ""; // product requirementfor (var n = 0; n < attr.length; n++) { alert(attr[n][0].toLowerCase()+"\n"+attr[n][0].toLowerCase().indexOf("req")+ "\n"+attr[n][0].toLowerCase().indexOf("prod")+ "\n"+attr[n][0].toLowerCase().indexOf("make")+ "\n"+attr[n][0].toLowerCase().indexOf("styl")); if (attr[n][0].toLowerCase().indexOf("req") != -1) { prequ = attr[n][1]; } else if (attr[n][0].toLowerCase().indexOf("prod") != -1 || attr[n][0].toLowerCase().indexOf("make") != -1) { produ = attr[n][1]; } else if (attr[n][0].toLowerCase().indexOf("styl") != -1) { pstyl = attr[n][1]; }}opt1.text = "\u00a0\u00a0\u00a0#" + (parseInt(arr[0]) + 9001100) + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" +arr[6] + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" +produ.concat(pstyl) + " ( " + prequ + " )";// ONLY PARSING THE FIRST TWO ATTRIBUTES... WTF? how would i be able to select a possible whitespace, such as a space, nobreak space, tab or carriage return or even a new line or none at all in two positions. these are indicated by the X's in the following regexp:/X<.+X\/>X/g
  9. is the string that is split first.this split value, equals the following two arrays (first and last attributes in the string), elements on a new line. it is looping through the entire split. then it loops through the 'saved arrays", validating them to find if it is a needed attribute. and this is the second element. what happened to the other elements? 0o
  10. in firefox it shows the array elements, joined with a , though. the current site is an admin site for use in firefox. i can make out scalar, because i know what the data type is of the variable alerted. :)i did click the alerts one at a time, stepping through the elements in the array via the script. i've installed firebug now as you suggested, but i don't see how this changes what i already know beyond a doubt...
  11. the problem is with the split(/<.+>/g) though... before that i have all the attributes, it only returns the first two which are not always the attributes wanted.well i did some checking, and /<.+>/g does equal any html tag - the . = any character, the plus means any occurrence count of the preceding character.perhaps the / in the br's (xhtml line break as opposed to <br>) are breaking the regular expression, i don't know... it could even be the >.
  12. the array preperation code has been changed now, i discovered i was only populating the attr array with element 0 from the split (*doh* ).this has almost been completed (kind of been resolved), here is the updated code: alert(arr[3]);var opt1 = document.createElement('option');arrt = arr[3].split(/<.+>/g);//alert(arrt);var attr = new Array();for (var i = 0; i < arrt.length; i++) { attr[i] = arrt[i].split(" = "); alert(attr[i].join("\n"));}var produ = ""; // product namevar pstyl = ""; // product stylevar prequ = ""; // product requirementfor (var n = 0; n < attr.length; n++) { alert(attr[n][0].toLowerCase()+"\n"+attr[n][0].toLowerCase().indexOf("req")+ "\n"+attr[n][0].toLowerCase().indexOf("prod")+ "\n"+attr[n][0].toLowerCase().indexOf("make")+ "\n"+attr[n][0].toLowerCase().indexOf("styl")); if (attr[n][0].toLowerCase().indexOf("req") != -1) { prequ = attr[n][1]; } else if (attr[n][0].toLowerCase().indexOf("prod") != -1 || attr[n][0].toLowerCase().indexOf("make") != -1) { produ = attr[n][1]; } else if (attr[n][0].toLowerCase().indexOf("styl") != -1) { pstyl = attr[n][1]; }}opt1.text = "\u00a0\u00a0\u00a0#" + (parseInt(arr[0]) + 9001100) + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" +arr[6] + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" +produ.concat(pstyl) + " ( " + prequ + " )"; ps justsomeguy, if i alert the data that its processing - that surely shows whats there? (especially when regarding strings) for some reason its not parsing all the attributes though... for some reason, it's only parsing the first two or so elements of the array which theoretically includes two subelements, the attribute key and value.
  13. oh nm, theres a curly closing brace instead of a normal closing brace...the problem now is that this doesn't retrieve the vehicle_make_model & canopy_style, canopy_req or products_description, Requirement attributes... 0o what could possibly be wrong here? 0o
  14. hmmm... seems i have found a temporary solution to my problem, but this arises another error that i can't figure out for the life of me...(oh the woes of working under a galvanised iron roof without aircon!)here is the updated piece of code: //alert(arr[3]);var opt1 = document.createElement('option');arrt = arr[3].split(/<.+>/g);//alert(arrt);var attr = new Array();for (var i = 0; i < arrt.length; i++) { attr[i] = arrt[i].split(" = ")[0];}var prod = "";var cstl = "";var preq = "";for (var i = 0; i < attr.length; i++) { if (attr[i][0].toLowerCase().indexOf("req") != -1} { preq = attr[i][1]; } else if (attr[i][0].toLowerCase().indexOf("prod") != -1 || attr[i][0].toLowerCase().indexOf("make") != -1) { prod = attr[i][1]; } else if (attr[i][0].toLowerCase().indexOf("make") != -1) { cstl = attr[i][1]; }}opt1.text = "\u00a0\u00a0\u00a0#" + (parseInt(arr[0]) + 9001100) + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" + arr[6] + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0" + prod + cstl + " ( " + preq + " )"; unfortunately, this generates the following error in firefox... please help! i am battling to see the forest for the trees...oh please do not click the link, i think it requires a password. the relevant code is above.
  15. thanks jkloth,yes - i was trying to split on any HTML tag, due to the differences in the delimiters... :)gonna try your version now =======================okay, tried and a few changes have occured to the code. var opt1 = document.createElement('option');arrt = arr[3].split(/<.+>/g);alert(arrt.join("\n"));var attr = new Array();for (var i = 0; i < arrt.length; i++) { alert(arrt[i].split(" = ")); attr[i] = arrt[i].split(" = ")[0];} thankyou for helping out with that regular expression
  16. hi,its me again with one of my weakpoints...regular expressions this time, i need to split a string of attributes: as a list of keys = variables, by splitting a string by "<br />".next the script will try to seperate the keys and values by " = ".the problem with this is that i cannot seem to split by html tags, as i have tried to do below. arrt = arr[3].split(/<.*?>/g)[0];alert(arrt.join("\n"));var attr = new Array();for (var i = 0; i < arrt.length; i++) { alert(arrt[i].split(" = ")); attr[i] = arrt[i].split(" = ");} arr[3] is the attributes list retrieved from XML, the variable formatting differs accross sources such as the follows:source A source B this needs to be done in order to parse the attributes for required attributes (the key in this instance will contain "req" of various casing depending on the source of the lead.as i am not that confident with regular expressions, i will need to ask for help.there are a few ways to skin this cat, i could search for the attributes in the string, but then that would be hardcoding and apply only to these two sources. an array with subarrays allows me to check the variables for case-insensitive "req" to find the required attribute.any help would be appreciated - even just a nudge in the right direction
  17. ps: i noticed that there were a few unnessessary instances of date and strtotime... therefore, i made it only with the getdate function now, which expects a numerical timestamp. :)the getdate function was necessary to give an array, so the dates can be set accordingly this way. :)thanks for your help, justsomeguy - much appreciated
  18. well well, looks like the issue has been resolved now both last week and last month work ^^here is the updated code... 0 is the last day of the previous month with mktime here, though... require_once('timezones/class-timezone-conversion.php'); /** Include timezone conversion class */function wdint($weekday) { switch ($weekday) { case "Sunday": return 6; break; case "Saturday": return 5; break; case "Friday": return 4; break; case "Thursday": return 3; break; case "Wednesday": return 2; break; case "Tuesday": return 1; break; case "Monday": return 0; break; }}function convert_tz($timestamp, $timezone) { /** convert local datetime to SAST (South African Standard Time) */ $tz = new TimezoneConversion(); /** Create TimezoneConversion Object */ $tz->setProperty('DateTime', $timestamp); /** Set local 'DateTime' to convert */ $tz->setProperty('Timezone', $timezone); /** Set Timezone Convert To */ return $tz->convertDateTime(); /** Get SAST Timestamp */}function get_timeframe($timeframe, $timezone) { $now = getdate( strtotime( convert_tz( date("Y-m-d H:i:s", time()), $timezone ) ) ); switch ($timeframe) { case "today": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"], $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "yesterday": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"] - 1, $now["year"] ) ); break; case "week to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - wdint($now["weekday"]), $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last week": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - wdint($now["weekday"]) - 7, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"] - wdint($now["weekday"]) - 1, $now["year"] ) ); break; case "month to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last month": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"] - 1, 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], 0, $now["year"] ) ); break; }}
  19. hi again,here is the updated code... i can think alot better during the evening when its cooler in the office <?phprequire_once('timezones/class-timezone-conversion.php'); /** Include class */function wdint($weekday) { switch ($weekday) { case "Sunday": return 6; break; case "Saturday": return 5; break; case "Friday": return 4; break; case "Thursday": return 3; break; case "Wednesday": return 2; break; case "Tuesday": return 1; break; case "Monday": return 0; break; }}function convert_tz($timestamp, $timezone) { /** convert local datetime to SAST (South African Standard Time) */ $tz = new TimezoneConversion(); /** Create TimezoneConversion Object */ $tz->setProperty('DateTime', $timestamp); /** Set local 'DateTime' to convert */ $tz->setProperty('Timezone', $timezone); /** Set Timezone Convert To */ return $tz->convertDateTime(); /** Get SAST Timestamp */}function get_timeframe($timeframe, $timezone) { $now = getdate( strtotime( convert_tz( date("Y-m-d H:i:s", time()), $timezone ) ) ); switch ($timeframe) { case "today": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"], $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "yesterday": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"] - 1, $now["year"] ) ); break; case "week to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - wdint($now["weekday"]), $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last week": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - wdint($now["weekday"]) - 7, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"] - wdint($now["weekday"]), $now["year"] ) ); break; case "month to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last month": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"] - 1, 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], -1, $now["year"] ) ); break; }} the convert_tz function uses the TimeZone Conversion PHP class by Utsav Handa (http://www.phpclasses.org/browse/package/5274.html)just wish to get opinions on this current code, before it will be marked as resolved, but i'll probably get this done in the sandbox version of the site.
  20. yeah last month was kinda,well - duh. especially now that now that u mentioned it :)lol i really need airconditioning in this office 0o
  21. okay, the requirements have changed slightly, and i've started implementing as suggested by justsomeguy - and here is the code: require_once('timezones/class-timezone-conversion.php'); /** Include class */function wdint($weekday) { switch ($weekday) { case "Saturday": return 6; break; case "Friday": return 5; break; case "Thursday": return 4; break; case "Wednesday": return 3; break; case "Tuesday": return 2; break; case "Monday": return 1; break; case "Sunday": return 0; break; }}function convert_tz($timestamp, $timezone) { /** convert local datetime to SAST (South African Standard Time) */ $tz = new TimezoneConversion(); /** Create TimezoneConversion Object */ $tz->setProperty('DateTime', $timestamp); /** Set local 'DateTime' to convert */ $tz->setProperty('Timezone', $timezone); /** Set Timezone Convert To */ return $tz->convertDateTime(); /** Get SAST Timestamp */}function get_timeframe($timeframe, $timezone) { $now = getdate( strtotime( convert_tz( date("Y-m-d H:i:s", time()), $timezone ) ) ); switch ($timeframe) { case "today": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"], $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "yesterday": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"] - 1, $now["year"] ) ); break; case "week to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], $now["mday"] - wdint($now["weekday"]), $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last week": break; case "month to date": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"], 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"], $now["mday"], $now["year"] ) ); break; case "last month": return date("Y-m-d 00:00:00", mktime( 0, 0, 0, $now["mon"] - 1, 1, $now["year"] ) ). " to ". date("Y-m-d 23:59:59", mktime( 23, 59, 59, $now["mon"] - 1, [b]$now["mday"],[/b] $now["year"] ) ); break; }} the get_timeframe function, returns in the format "2010-03-09 00:00:00 to 2010-03-09 23:59:59" with "Today" as the timeframe passed. what's buggering my mind though, is how to implement "Last Week" or finish implementing "Last Month".can anybody please help me here?the result i am to get is the following: <select name="menu_statsel" id="menu_statsel"> <option value="2010-03-09 00:00:00 to 2010-03-09 23:59:59" selected="selected">Today</option> <option value="2010-03-08 00:00:00 to 2010-03-08 23:59:59">Yesterday</option> <option value="2010-03-08 00:00:00 to 2010-03-09 23:59:59">Week to Date</option> <option value="2010-03-01 00:00:00 to 2010-03-07 23:59:59">Last Week</option> <option value="2010-03-01 00:00:00 to 2010-03-09 23:59:59">Month to Date</option> <option value="2010-02-01 00:00:00 to 2010-02-28 23:59:59">Last Month</option></select>
  22. nevermind, sighs... this issue has been resolved :)here is the correct select statement SELECT 10_serviceprospects.bigint_ProspectID, 5_suppliers.text_SupplierName, 5_suppliers.text_ContactFirstName, 5_suppliers.text_ContactSurname, 5_suppliers.text_ContactPosition, 5_suppliers.`text_ContactE-mail`, 5_suppliers.bigint_ContactTel, 13_prospectleadsent.timestamp_Sent, 12_prospectmessages.smallint_ProspectMessageCount FROM 13_prospectleadsent, 5_suppliers, 12_prospectmessages, 10_serviceprospects WHERE 13_prospectleadsent.bigint_SupplierID = 5_suppliers.bigint_SupplierID AND 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_ProspectID = 10_serviceprospects.bigint_ProspectID AND 13_prospectleadsent.bigint_ProspectID = 1 ORDER BY 5_suppliers.text_SupplierName ASC, 12_prospectmessages.smallint_ProspectMessageCount ASC
  23. hi there,i am using MySQL, and trying to process the following select statement: SELECT 10_serviceprospects.bigint_ProspectID, 5_suppliers.text_SupplierName, 5_suppliers.text_ContactFirstName, 5_suppliers.text_ContactSurname, 5_suppliers.text_ContactPosition, 5_suppliers.`text_ContactE-mail`, 5_suppliers.bigint_ContactTel, 13_prospectleadsent.timestamp_Sent, 12_prospectmessages.smallint_ProspectMessageCount FROM 13_prospectleadsent, 5_suppliers, 12_prospectmessages, 10_serviceprospects WHERE 13_prospectleadsent.bigint_SupplierID = 5_suppliers.bigint_SupplierID AND 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_ProspectID = 10_serviceprospects.bigint_ProspectID AND 13_prospectleadsent.bigint_ProspectID = 1 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount ASC, 5_suppliers.text_SupplierName ASC; however, they only seem to order by the 12_prospectmessages.smallint_ProspectMessageCount field. how can i make them order like i attempted to here, with a primary and secondary order? the correct fields are returned, just in the wrong order...someone please help!
  24. thanks to boen_robot, this issue has been resolved
  25. of course... thanks a mill, boen_robot! :)perhaps i need a decent night's rest...
×
×
  • Create New...