Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. There are literally thousands of links and pages and info out there on this, especially since mysql functions are deprecated and a lot of people are moving away from it. There are even tutorials out there that more or less put it all in one place as a "migration guide" (no, I'm not going to be your personal google service). This is not a language barrier. This is a "level of effort you are willing to make" barrier. But if you really have been trying your hardest and still no joy..no offense, but if it has taken you one month and you still have not figured out how to convert mysql to pdo, perhaps you should consider hiring someone to do it for you?
  2. I'd also point out that m-d-y is a terrible way to store dates. That's a "carry-over" from the "business" world that has caused no end to havoc and headache in the computer world.
  3. I understand you are new to PDO. But you need to make an effort to figure it out. We're here to help you when you are making an effort, not spoon feed you. Especially for a "convert to new syntax" type of problem, where the answers are easy to find. google "php pdo version of [insert mysql function here]". The message tells you what the problem is. You are making a call to a method that doesn't exist. google "php pdo version of mysql_affected_rows" and literally the first result is your friend.
  4. The most immediate issue you have is that you are creating a new validation object, and you have your form validation code inside the constructor. If you name a method the same name as the class, that becomes the constructor that gets executed when you create an object of that class. This is the old php4 style of making a constructor; you shouldn't really be doing it that way unless you are using php4 (in which case, update your php version 5+ and use the new style syntax). But regardless, you shouldn't be putting your form validation in the constructor, because when you make that new object $form_validation it's going to run the code. And you are making it before you even fill out and submit the form, so nothing is getting passed to it, which is making $form_fields default to an empty string, which is making your foreach loop attempt to iterate over a string instead of an array. So, basically you need to change your code to call your validation when the form is submitted. Which you already do, except for the fact that your method is your constructor. So if you absolutely want to stick with the php4 syntax, rename your validation method to something like validate() or something else other than the class name, and leave the rest of the code as-is (except for below, read on). Also, as far as your actual validation is concerned.. there is one outright error, and another issue that's not so much an issue as a matter of better coding. Firstly, you pass the form values to your validation function, and yet do this: $_POST[$form_field]. This is going to make the condition look for an index of the form value, not the form element name. E.g. if I put "Crayon" as my name and "Violent" as my last_name, it's going to look for $_POST['Crayon'] and $_POST['Violent']. Which brings me to my 2nd point: You shouldn't be looking at $_POST in your function in the first place. You passed the form values to the function, so why are you looking at $_POST? You should just be doing if (empty($form_field)) {..}.
  5. Please explain what is not working. One thing I do see is that you aren't using try..catch properly. At a minimum, catch expects an Exception arg passed to it. Example: private function connect(){ try{ $this->_conndb = new PDO($this->_pdo_host_dbname,$this->_user,$this->_password); } catch (Exception $e) { echo 'Connection failed: '.$e->getMessage(); } } But beyond that, I see some issues that aren't so much issues as code that could be written better, but regardless, I am not going to make wild guesses at what you mean by "not working". You need to provide more details.
  6. You know.. you said you wanted to output the zip, and all of your coding efforts have reflected that. Now you are saying you want to put it in a database. Not being clear about what you want is a good way to get people to stop giving you help even when you throw money at them, and you're not even throwing money. I suggest moving forward you try your very hardest to explain what it is you are actually trying to do so that you don't waste anybody's time. Here is how you can download the file directly to your server instead of output it to the browser. This will put the file in the same directory that the script is run. <?php $url ='http://www.partner.viator.com/partner/admin/tools/links_feeds/downloadFeed.jspa?feed=Products&PUID=13594'; $ch = curl_init(); $fp = fopen (dirname(__FILE__) . '/file-name-here.zip', 'w+'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_exec ($ch); curl_close ($ch); fclose($fp); ?> That is a whole other can of worms to deal with, and again, my ability to help is hampered by the fact that you aren't providing necessary information. Are you just wanting to put the name of the zip file in some column so you can reference by name? Are you wanting to put the actual zip file into a column? Are you wanting to parse the file and put data from the file into separate columns and/or tables? If it's the last, then you need to unzip the file, and you will need to provide details about file structure and values and mappings to your database.
  7. Your issue is with headers. Both in the curl request and also with what you are trying to output. A side issue is that you are putting the response in a variable and then attempting to output it. While it is possible to do this (if you output the proper headers first), it's not really advisable. Problem is that who knows how big the file is. So if you attempt to put a 1gb file into a string then there's a good chance php is going to run out of memory. It would be better to just let the file pass through directly to the the client. So, having said that, this is what your code should look like: <?php // callback function to set the appropriate // headers for the zip file to be pushed to the client function curlHeaderCallback($ch, $header) { if (preg_match('/^HTTP/i', $header)) { header($header); header('Content-Disposition: attachment; filename="file-name-here.zip"'); } return strlen($header); } $url ='http://www.partner.viator.com/partner/admin/tools/links_feeds/downloadFeed.jspa?feed=Products&PUID=13594'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); // this is to set the headers to be output to the client curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback'); curl_exec ($ch); // output a message if the curl failed $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($intReturnCode != 200) { echo 'was error: ' . $intReturnCode; } curl_close ($ch); ?>
  8. You might wanna be more specific about what you're trying to actually do. Generally you shouldn't really use document.write for anything. If you are just playing around with stuff, you should use console.log() instead. Chrome has a built-in set of developer tools. Go to the menu and Tools > Developer Tools, (shortcut Ctrl+Shift+I). You can go to the "Console" tab to type in javascript code or see the results of calls to console.log(). If you are attempting to print (output) the code somewhere else, like visibly on your page, then you should be using methods to change an html element's value or text, or create one, etc.. There are numerous ways to do this, so more specific advice can come with more specific description of what you are actually trying to do. But as for a "dump" of what a javascript object contains, you can reference individual properties with dot notation or index notation var object1 = {value: 10}; console.log(object1.value); // dot notation console.log(object1['value']); // index notation You can also loop through the properties with the in loop: var object1 = {value: 10, foo:'bar'}; for (x in object1) { // x will have the name of the property, so we can get the value of each property // by using index notation console.log(object1[x]); } But as far as (recursively) outputting a "tree" of everything in the object (e.g. the equivalent of php's var_dump or print_r), javascript has no native method for this (for some odd reason). I have not tested to see if the code phpzer works as advertised, but you will basically need to something like that. If you google for "javascript equivalent of var_dump" you will find plenty of example functions people have made to replicate it. Though honestly, there isn't much use case for something like this, other than for qa/debug purposes, and if that's what you are looking to do, then the javascript/dev console already offers a really nicely formatted way to visualize an object. For example, if you go to the Chrome dev console and type in var object1 = {value: 10, foo:'bar'}; And then type on "object1" It will output the following: Object {value: 10, foo: "bar"} If the object is more complex, it will output it in a way that has little arrows you can click on to expand it to a tree view. For example, you can type "document" into the console and get an expandable tree-view of what the rendered document looks like. It's basically like right-click > viewsource but with the fully rendered content (fyi if you want to utilize that, go to the "Elements" tab of the dev console instead, since that's what it's all about). Or, type in "window" to see the window object. From there you can drill down and find any variable set (since window is the highest scope for js)
  9. that's how you do it, yes. function probability($p) { return $p >= rand(1,100); } if ( probability(31) ) echo 'true'; else echo 'false';
  10. okay, well if you are absolutely 150% certain the dynamic output matches the hardcoded output, then maybe you need to provide a little more context. As far as php is concerned, it's all text. Even if your database were taking a while to return stuff.. it's still all text, and things being buggy and hanging is a client-side issue.. unless you are using this alongside with ajax... is your clientside code calling this script onclick or hover or something? Things don't seem to be adding up here..please provide more context.
  11. use ZipArchive to unzip it. Or, if you're looking to make the browser prompt a download of the zip file instead of output gibberish, use header to set the content type (read the user notes, there are entries for what to set for zip files).
  12. dumb question: did you view your source and compare it to what it looks like when you hardcode it? if they are exactly the same, then it sounds like you may have some database issues and/or optimization to figure out. How many rows are in your table?
  13. first off, where are you actually defining $qotw? I don' tsee anywhere in your code where you are actually defining it... except in your condition, which that's not how it works. = is the assignment operator. == is the equality operator. edit: on a side note, when you change it to e.g. if ($qotw=='1') .. note that php is a loosely typed language, which means '1' will also stand for true, so anything that evaluates as true will make the condition true. IOW you may instead want to use a strict comparison with === instead of ==
  14. umm.. no? using a while statement like that will cause the query to be executed every time. Come on people.. understanding how loops work is php 101...
  15. well that's not how foreach loops work. They aren't like other loops. See my edit.
  16. Why is this not intuitive? If your mate handed you a grocery list and asked you to recite each item on the list, are you going to read the first line, hand the list back to him, then have him hand it back to you, then you read the 2nd line, then you hand it back to them, wash rinse and repeat for every line of the list, or are you just going to take the list once and keep it until you're done reading through the list? a foreach loop is not like other loops, where a condition is evaluated each iteration. Well, there is, but it's internal. Internally, php checks to see if there's another element for the pointer to move to, and stops when there isn't. But that's not the same as evaluating a condition written into the code to be evaluated on each iteration, like with other loops.
  17. my bad requinix.. for some reason i don't get notification when someone else posts.. I moved the solve to yours
  18. You need to change your binding to be a delegated event. Basically the idea is to attach the event handler to an element that will always exist, e.g. the body: $('body').on("dblclick",".newimageContainer label",function(e){ // Get the src of the img below the label that was clicked imgSrc = $(this).children("img").attr('src') // Set the src of the prior selected page image to the new src $('.changing').attr("src", imgSrc); // close modal modal.close(); });
  19. There are a number of issues wrong with your regex. Some things are just wrong for what you are individually trying to match (e.g. spacing, allowing for bad matches like align=100), and some things are wrong because what you are trying to match for in regex101 more than likely doesn't really match your real-world context (e.g. I somehow doubt you're really parsing a list of bbcodes. More likely is you are ultimately trying to find them within a bunch of arbitrary text like a forum post and replace them with html markup). So, here is an example of how to find and replace them: $content = preg_replace_callback( '~\[img((?:\s+(??:width|height)=\d+|align=(?:left|right|middle|top|bottom)))+)\s*\](.*?)\[\/img\]~i', function ($m) { $m[1] = array_filter(preg_split('~\s+~',$m[1])); array_walk( $m[1], function (&$a) { $a = explode('=',$a); // this is where you would do something with attribute. // $a[0] is name and $a[1] is value. The code below just // translates it to e.g. height='100' but you may want to do // something else. For example, align isn't supported by html5 // so in reality you'll prolly want to instead check if $a[0]=='align' // and then build a style='..' attrib instead $a = "{$a[0]}='{$a[1]}'"; } ); return "<img src='{$m[2]}' ".implode(' ',$m[1])."/>"; }, $content );
  20. Why aren't you building your form within the wp-admin interface? That's like, the whole point of using a CMS..
  21. You can use You can have multiple WHERE..LIKE clauses, e.g.: SELECT * FROM records WHERE title LIKE '%value1%' OR title LIKE '%value2%' OR title LIKE '%value3%' or you can use regex: SELECT * FROM records WHERE title REGEXP 'value1|value2|value3'
  22. We aren't here to fix some random 3rd party script you found and don't know anything about. We're here to help people learn and fix code that they try to make. You've got 2 choices, as far as this forum is concerned: 1) make an effort to understand and debug the code, and feel free to ask any specific questions about something you get stuck on, or 2) hire a freelancer to fix it for you.
  23. explain where and how the data is stored and what you are currently using to interact with the data.
  24. Otherwise known as Dr Seuss Day. So in honor of this "holiday" and of Dr. Seuss: You did not like green eggs and ham, Sam, you did not give a damn But then a bloke just wouldn't scram, and now you like them plenty, Sam! Now it's time to read a book - don't you give that dirty look. You'll like reading Mr. Sam, You will like it more than ham. One book, two book, red book, blue book: just pick and sit down in a nook. You should read one in a house, about a cookie and a mouse. You will like it near and far, even Where the Wild Things Are. If evening is more opportune, read in bed with Goodnight Moon. Oh, the Places You Will Go, imagine things that books can show. If you don't believe it's so, Ask the Doctor, Who should know. "Doctor Who? Doctor Who?" Just ask Horton, he hears too. So read a book for that old cat; to Doctor Suess: I tip my hat.
  25. Be The Ball? Ah okay, a euphemism for focusing on the problem at hand. CONCENTRATE. Buy Ten Burritos? Nope, not working.. maybe you're just hungry and can't focus on an empty stomach. Good call. Bang The Blonde? Still not gettin' it. Okay, just walk way for a bit and come back to the problem later. What an excellent distraction! Beat The Beast? Okay fair enough; reality and all that... an excellent alternative if you don't have a blonde handy (or a handy blonde) Bork The Bjork? I don't even know what the...maybe the fetish sites are too much of a distraction. You've still got a problem to deal with here.. Bring The Beer? Still can't figure it out.. time to drown your sorrows. Blaze The Blunt? In case you think booze tastes like carbonated piss.. Bob The Builder? Okay fuck it.. time to hire a freelancer. But can he fix it? Yes, yes he can.
×
×
  • 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.