Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. some comments about your code (some of which actually have something to do with why it is not working) - 1) Please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum. this will increase the chance of people even looking at your code. i edited your post above to add code tags. 2) you need to separate your business logic (the php code that determines what to do on the page and gets the data that the page needs) from the presentation logic (the html/css/javascipt and minimal php code that outputs the content on the page.) this alone will reduce the amount of code because the majority of the php logic will be in one place and you will be able to see things like the duplicated lines of code, values that are defined but never used, values that are used that are not defined... it will also let you see the main program logic in one consolidated place so that you and us can figure out what it is doing (some of your code makes no sense, such as only displaying the output if the current date and the order_transaction_date are the same - what happens if someone placed an order before midnight and tries to view the order after midnight?) 3) don't run database queries inside of loops. this results in a noticeable performance loss. for related queries, you should use one joined query. for getting the information about a list of input data, you should run one query that gets all the information at once. 4) don't store comma separated lists of values in a column in a database table. you should have one more table that holds the values, one per row, that is related back to the parent table using the id's. 5) the error listed in post #2 likely refers to this line - $checkout_couponid = $coup_id['order_coupon_id']; $coup_id isn't an array, it's a value from the foreach(){} loop that is itself looping over an exploded list of values. if you follow my recommendations about your code, this foreach loop and the query you are running inside of it will be eliminated anyway.
  2. the part of the code you changed is the else statement for if ( $_SESSION['locked'] != 1 ). which, if the session is locked, you wouldn't care if you went back to step 1. the header() redirect right after the block with the update queries is what you need to modify. your update code needs to enforce access security. it currently allows anyone to modify the quantity of any item in the cartitems table, not just their own items.
  3. after you have detected that a post method form has been submitted ($_SERVER['REQUEST_METHOD'] will be equal to 'POST'), the $_FILES array will be empty if the size of the uploaded file exceeds the post max size setting. also, if the $_FILES array is not empty, i.e. your expected $_FILES['uploaded'] element is set, you must test if the upload worked correctly (the $_FILES['uploaded']['error'] element is a zero), before you can use any of the uploaded file information. to detect and report back to the user which of these conditions has caused the upload to fail, you would need to write program logic to do so.
  4. i did a global search through that extension's code, and there's no instance of using getList() with a parameter. there is however a getItem() method in ...\components\com_j2store\models\orders.php file that looks like it is retrieving the item attribute information you are trying to access. if your purpose in this thread is to just change how information that's already being retrieved is being displayed, you would modify the 'view' code for that data, not write your own data retrieval code.
  5. ^^^ firstly, your page controller SHOULDN'T use the actual filename for the file to be included as this will let a hacker include any of your .php files and bypass security you may have in place. your page controller should just accept the 'module' name, mC=stampsforexchange, validate the value in the current user's context (should the current user be able to access that module/page), then include the appropriate .php file based on the module name. then, to do what you are asking, you would have a second parameter in the url to specify what you want the stampsforexchange module to do - index.php?mC=stampsforexchange&country=malta. your control logic in the tampsforexchange.php code would take the $_GET['country'] value, validate it, and call the getCountryStamps($country) function with the $_GET['country'] value as the parameter to the function.
  6. that does help since it shows what getList() is doing (though i would expect that setState() would clear previous data.) give this a try for the getList() method call - $attributes = $model->getList(true); // force refresh - i.e. get new data edit: actually, that may not produce the expected result since the $refresh value is used by getQuery() to get the $query value. the form of getList() with a parameter would imply you tell it which list you want. that would take knowing the name(s) of the available lists. this is the problem of code that's not documented. how did you come up with the two lines of code in question? perhaps if there is an example showing using the getList('with some list name here...') method, that we can determine how to relate it to your code.
  7. for debugging purposes, you would want your code to tell you (log) why it is failing. you can use mysql_error() to get the reason why the connection failed.
  8. $obj isn't an array of arrays. it's an array, i.e. written as code it would be $obj = Array('id' => 2,'name' => 'Jhon'); the code in question in this thread would need to be - $stmt = $mysqli->prepare('INSERT INTO prueba (id,nombre) VALUES (?, ?)'); $stmt->bind_param('is',$obj['id'],$obj['name']); $stmt->execute(); // execute the query
  9. that error would mean that the input data you have shown in this thread isn't what the actual data is. what does the following show for the contents of $obj - echo '<pre>',print_r($obj,true),'</pre>';
  10. the empty get data means that the browser isn't placing any query string parameters on the end of the url, but it is making a get request to the same url that was used by the ajax call. is the url of the main page and the url used in the ajax call the same page/url? you didn't exactly clarify if it is. the reason i asked if this url is the same as for the main page, is that when browsers re-request pages due to debuggers/character set encoding differences (two of the reasons i know they do this) they request the page they are on, which would be the main page's url. if the url that your ajax is requesting is different from the main page, this problem likely won't occur. actually, your die() statement when the post data is empty and what i am suggesting of testing for a post request will result in the same symptom, as both will cause an empty http 200 ok response to be sent back to the browser. beyond the url being the same or different for the main page and the ajax page, at this point we would probably need your client side code in order to fully see what it is doing and to try and reproduce the problem.
  11. and once you have the program logic/data, producing the output using an xml library would look like this - // starting with the above code, replace everything from the header() down with this - header ("Content-Type:text/xml"); $sxe = new SimpleXMLElement('<Applications></Applications>'); foreach($application as $app){ $e_appl = $sxe->addChild('App'); $e_appl->addAttribute('AppName', $app['appname']); $e_env = $e_appl->addChild('Env'); foreach($data[$app['id']] as $env_name=>$servers){ $e_env->addAttribute($env_name,implode(',',$servers)); } } echo $sxe->asXML();
  12. i reverse engineered your data from the posted information. here's one way of producing the output, using the php only approach - $application[] = array('id'=>1,'appname'=>'NotePad++'); $application[] = array('id'=>2,'appname'=>'7Zip'); // these could potentially be in any order. allow for arbitrary environments $serverlist[] = array('appid'=>1,'Environment'=>'Prod', 'servername'=>'server1'); $serverlist[] = array('appid'=>1,'Environment'=>'Prod', 'servername'=>'server2'); $serverlist[] = array('appid'=>1,'Environment'=>'DEV', 'servername'=>'devserver1'); $serverlist[] = array('appid'=>1,'Environment'=>'DEV', 'servername'=>'devserver2'); $serverlist[] = array('appid'=>2,'Environment'=>'Prod', 'servername'=>'server3'); $serverlist[] = array('appid'=>2,'Environment'=>'Prod', 'servername'=>'server4'); $serverlist[] = array('appid'=>2,'Environment'=>'DEV', 'servername'=>'devserver3'); $serverlist[] = array('appid'=>2,'Environment'=>'DEV', 'servername'=>'devserver4'); // pre-process server list into appid/environments $data = array(); foreach($serverlist as $s){ if(!isset($data[$s['appid']])){ $data[$s['appid']] = array(); } if(!isset($data[$s['appid']][$s['Environment']])){ $data[$s['appid']][$s['Environment']] = array(); } $data[$s['appid']][$s['Environment']][] = $s['servername']; } //echo '<pre>',print_r($data,true); // examine resulting data header ("Content-Type:text/xml"); echo '<?xml version="1.0" ?>'; echo '<Applications>'; foreach($application as $app){ echo "<App AppName='{$app['appname']}'>"; echo "<Env "; foreach($data[$app['id']] as $env_name=>$servers){ echo "$env_name='".implode(',',$servers)."' "; } echo "/>"; echo "</App>"; } echo '</Applications>';
  13. 1) when creating an xml document, i find it easier (and clearer) to just use php to create the elements you want. using an xml library isn't necessary unless you are modifying an existing xml document. 2) your loops and logic don't make sense. each pass through the loop is creating/appending new elements. you would either need to detect changes in the related data and/or run loops to reference the related data. 3) providing us with a sample of your input data that you expect to produce the shown output, in a format that we can copy/paste (see var_export()) and use in php code, would help as it would both show the structure and relationship between your arrays of data and allow someone to experiment.
  14. the following two lines would be responsible for getting the correct data - $model->setState( 'filter_orderitemid', $item->orderitem_id); $attributes = $model->getList(); since no one here likely has experience with the extension you are using, about the only way we could help is if you posted a link to the documentation that defines those two methods.
  15. topic abandoned by the op - locked...
  16. programming help forums are not here to find or to give you code that you need. see this sticky/pinned topic - http://forums.phpfreaks.com/topic/195880-this-board-is-not-a-script-repository/
  17. because bind_parm() uses references to variables, i was only able to get this to work as follows - $stmt = $mysqli->prepare('INSERT INTO prueba (id,nombre) VALUES (?, ?)'); $stmt->bind_param('is',$id,$name); foreach($obj as $assocArray) { $id = $assocArray[0]['id']; $name = $assocArray[1]['name']; $stmt->execute(); // execute the query }
  18. this is at least the third thread you have started for this problem, which i have now merged together. please stick to one thread for the same problem.
  19. let me correct something i wrote above, the second request is occurring 2-3 minutes after the first one. but the fact remains you are receiving a get request that's fairly consistently timed after your original post request. have you done what Psycho suggested so that you know what is in the get request - because the request contains the user agent, this is probably actually coming from the browser. is this test page you are showing us the same url as the main (or only) page that was requested by the browser? it seems to be some sort of keep-alive ping. in any case, after you have determined what the get request contains, you may not have any control over it. if the overall all problem is that this get request is interfering with your ongoing processing of the post request (what exactly are you doing that requires that?) the solution is for your php code that's responsible for servicing the post request to actually test for and only respond to post requests (i mentioned two ways of doing this in post #6.)
  20. the best solution depends on what the system is being used for.
  21. if you have a class definition that contains too much code to post, you are doing something wrong. the only code that's relevant is the class definition, the code making an instance of that class, and the code where you are calling the method/getting the error.
  22. your symptom is (most likely) due to the browser making a get request to the code. in each case that you have posted, it is about 2-3 seconds after the first request. your post data processing code isn't testing either if a method = 'post' request was made to it or if the post variable is set before referencing the value in it. i'm betting if php error_reporting was on and log_errors was on that $_POST['q'] is throwing undefined index errors when the second request is made and that $_SERVER['REQUEST_METHOD'] is GET for those second requests. if so, this is either something your browser is doing (browser debuggers have a habit of doing this), something your client code is doing, or something your server is doing.
  23. i edited your post(s) in this thread to make the thread readable. you are aware that you can edit your own posts for a time? you don't need to keep making multiple replies to fix how the code is posted.
  24. your posted code, with the last line change to echo $disp->displayTomorrow();, runs correctly. we will need to see the actual code that produces the error in order to help you with what is wrong with it. you either have a spelling or scope or conditional definition problem.
  25. also log the user agent to get the browser/search engine info being put into the request
×
×
  • 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.