-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Treating the data as an array will be much clearer - $arr = json_decode($elements,true); echo "<pre>",print_r($arr,true),"</pre>"; // take a look at the data $key = "c74a0dba-5307-4f90-b04e-fdc88c4dd434"; echo $arr[$key][0]['value'];
-
I Cannot Figure Out Why Database Is Not Updating.
PFMaBiSmAd replied to BrettHartel's topic in PHP Coding Help
^^^ Likewise for the SELECT query. Run one query that selects both columns and since you expect at most one row, there's no need to loop over the results. Just run one fetch statement. -
We can only help with specific programming questions, specific programming problems, or specific programming errors. Do you have one of those? All you have stated is what you want or what you would like, and well... we are not your mom or Santa, and cannot help you with wants and likes.
-
Php Conditionals Not Working As Expected In Jquery Mobile.
PFMaBiSmAd replied to drayarms's topic in PHP Coding Help
What does var_dump($_COOKIE['language']); show? -
The variable you are putting into your query statement is the original $_POST variable, not the filtered/validated/sanitized value, so of course any < > tags will still be present in it. You should also be using mysql_real_escape_string to escape the string data being put into your query. Addslashes does not escape all the sql special characters in the character encoding your database is using and it should not be used to escape string data being put into a query. I think one of the issues with your code is that you have too much of it. You have repeated lines/groups of code that only differ in the name/variable/value it contains. That's a sign you have sets of related data, and sets of data need to use arrays. Here are some general hints - 1) You should only use name/id/value attributes in your html markup when they are needed. You have so much extra markup, reused field names, and unused elements in your form, that I don't know what you are trying to do, or I would have posted an example that used the next two items. 2) You should have an array that defines the form fields so that you can a) dynamically produce the form by looping over the array, and B) you can use this same defining array of fields in your form processing code to determine what you do for each input. 3) You should use a html array for the repetitive form field name, with an index value of 1-9 (name = 'par[1]'), rather than a series of name/numbered fields (name= 'par1'). This will allow you to use php array functions to process/loop over the submitted data, since you are going to process each of those 9 fields identically. It will also allow you to use javascript array functions, assuming that is how you are populating the sum fields in the form.
-
Do you have php's error_reporting set to E_ALL, so that more than just fatal runtime errors will be reported, and you need to test if your database statements are failing or not before using the result from one statement in the next to prevent follow-on errors, and to report/display/log your own application errors when a statement does fail so that you can find and fix the problem. Your ->prepare() statement is failing, but you have no error checking/error reporting/logging logic in your code to get your code to tell you why. The ->prepare() method will return a false value if it fails. You need to test for that and if it is false, the $Con->error property will contain the error that occurred for the ->prepare() statement.
-
@twistedvengeance, Reposting bad generic upload code that doesn't address what the OP asked, is not helpful The upload code you found, is based on the w3schools code and tests for upload errors AFTER it tries to use some of the uploaded file information. Therefore, it reports the wrong reason why the upload was not accepted and never reports actual upload errors. You must test if the upload worked BEFORE you can reference any of the uploaded file information.
-
@twistedvengeance, The two values are integers, not strings, and they don't need to be enclosed by single-quotes in the query. That actually just makes mysql work harder because numbers enclosed by single-quotes are first converted to floating point numbers.
-
I removed the script you posted above for a few reasons - 1) You posted it in a large, bold font, not using the forum's [ code ][ /code ] bbcode tags, that no one was going to attempt to read anyway. 2) It's a 3rd party script and you are posting the original code, a link to the author's site would have been sufficient for anyone who wanted to get or see the original code. 3) The purpose of this php help forum is to help programmers with code they are writing/modifying. If you modified that code, you didn't bother to post just the relevant portion of the code or to identify what you changed in it. 4) All you are stating are the things you want the code to do differently, without actually making the attempt to do the work yourself. That's not how programming help forums work. We are not going to try and get up to speed with a complete application, and hundreds of lines of code, for free. We have a Freelancing forum section that you should post in if you want to hire someone to make these modifications for you. 5) Your 1st post in this thread, and the thread title, indicates you want to add a file upload feature, but your next post states it already has this (which it should given the purpose of the script), but that you want to add a link (I'll assume you mean a download link) in the search results. No one here really knows what it is you want.
-
It would be a total of one UPDATE query, without a WHERE clause, to convert the existing value and set a new column to the corresponding YYYY-MM-DD value, all at once.
-
You shouldn't allow users to directly type dates. Even if you display the correct format next to the input field, you will get all kinds of incorrect input. You need to use a date picker/three separate drop-down select menus. You should also not store unix timestamps since you must perform an ambiguous, timezone dependent, conversion on them to use for anything other than simple comparisons.
-
$mn2 contains some empty entries at the end, probably because some of your $m1, $m2, ,,, variables don't exist. Why not just use an array - $m[1], $m[2], ... and avoid the extra code needed to make the $m1, $m2, ...into an array every time you use the values? By using individual $m1, $m2, ,,, variables, you must now keep track of how many of them there are so that you don't iterate past the end, which is likely what is causing your current error. P.S. mysql_result is the slowest way of retrieving data from a query. And again, creating a series of name/numbered variables in your while(){} loop is taking a bunch more code to set the variables, then more code later to access the values. Just assign the rows from the query to an array. BTW - variable variables are three times slower than using an array.
-
The value of a type="file" form field is read-only. It can only be set by the browse-to-file dialog box in the browser.
-
What have you done to pin down exactly at what point your code and data are doing what you expect and at what point they are not? I can guarantee that the problem lies somewhere between those two points. If all you have done is to run your code and noticed that it didn't work as expected, all you have done is to pin down that there's a problem somewhere in your code. If that answer is somewhat flippant, it's because - A) We cannot run your code to observe the result it produces because we don't have your database tables or data, nor do we want them, B) It's unlikely that anyone is going to read through hundreds of lines of code to figure out both what it should be doing and what might be wrong with it, C) Without any statement of the exact symptom or error you saw in front of you, and at what point you saw it, that leads you to believe that your code doesn't work, we don't even know the most likely place in the code to look at as a starting point. So, you need to debug your own code (you are the only one here who can). You need to narrow down the problem to just one relevant section of code or one data value. Then, if you cannot find the problem after doing those things, you need to post just that relevant section of code or wrong data value along with the symptoms or errors that you saw in front of you that would tell someone what your code and data are doing at that point that is different from the expected result.
-
Here's an alternative method to retrieving all the id's at the start, randomizing them, and storing them for the user. To get the next random question, you would query the question table and get the questions that are not in the set of already answered questions. Then you would randomize those unanswered questions to get the next question.
-
<?php $img = "<img src='../img/beer_mug_finish-green.jpg' alt='beer_m' name='beer_mug' width='34' height='33'>\n"; if($user_rating_show >= 1 && $user_rating_show <= 5){ echo str_repeat($img,$usr_rating_show); }
-
You would end up with a parent/child association (see this thread - http://forums.phpfreaks.com/topic/271801-mysql-hierarchy-structure/ ). I have modified the displayHierarchy() function from that thread so that it allows multiple entries (an additional array dimension) for any id (to allow the same id with different conditions to be added to your cart.) See the following example code for how the cart would/could look and how you can iterate over it - <?php session_start(); // fake cart contents for demo purposes $_SESSION['cart'] = array(); $_SESSION['cart'][0][123][] = array('qty'=>2,'condition'=>3); // main item 123, qty 2, condition 3 $_SESSION['cart'][0][123][] = array('qty'=>2,'condition'=>2); // main item 123, qty 2, condition 2 $_SESSION['cart'][123][555][] = array('qty'=>1,'condition'=>1); // accessory item 555 for item 123, qty 1, condition 1 $_SESSION['cart'][456][555][] = array('qty'=>1,'condition'=>1); // accessory item 555 for item 456, qty 1, condition 1 $_SESSION['cart'][123][555][] = array('qty'=>1,'condition'=>2); // accessory item 555 for item 123, qty 1, condition 2 $_SESSION['cart'][123][555][] = array('qty'=>1,'condition'=>3); // accessory item 555 for item 123, qty 1, condition 3 $_SESSION['cart'][0][456][] = array('qty'=>1,'condition'=>1); // main item 456, qty 1, condition 1 function displayHierarchy(&$arr, $parent, $indent=0){ // define condition value/legend $conditions = array(1=>'poor',2=>'good',3=>'excellent'); $ind = $indent * 30; if (isset($arr[$parent])) foreach($arr[$parent] as $id=>$rec){ // $rec is an array of 1 or more entries for the same id foreach($rec as $item){ echo "<div style='width:400px; margin-top:5px; margin-left: {$ind}px; padding:5px; border:1px solid gray;'> ID: $id - " . (($parent) ? "Accessory for: $parent - " : '') . "Qty: {$item['qty']} - Condition: {$conditions[$item['condition']]} </div>" ; } displayHierarchy($arr, $id, $indent+1); } } // call the recursive display function displayHierarchy($_SESSION['cart'], 0);
- 5 replies
-
- cart
- cart design
-
(and 2 more)
Tagged with:
-
Fetching & Print Multiple Records From A Table
PFMaBiSmAd replied to tahakirmani's topic in PHP Coding Help
Each image you put onto a web page must have its own HTML <img src='url_that_corresponds_to_the_image' alt=''> tag. The url_that_corresponds_to_the_image would be a url to a .php file (image.php for example) that outputs the content-type header, followed by the image data for one image. Since you would want this same .php file to work for each possible image, you would put a GET parameter on the end of the url that specifies the id of the image (image.php?id=123 for example.) Why have you stored images in a database? If you had stored the images as files in the file system and stored the file name in the database, all you would need to do is output the file names as the url_that_corresponds_to_the_image in the <img ...> tags. -
You would use a database table to store the status of the quiz's in progress. When someone starts the quiz, you would retrieve the list of question id's for the quiz, randomize them, and store them, one per row, in the 'active' test table. Each row in that table would contain an auto-increment id (which would determine the order of the questions, since they were randomized before being inserted), the user's id, the question id, the answer the user gave for that question (initially a null value when the rows were inserted, updated when the user enters the answer), and the datetime the question was displayed (so that you can track how long ago the test was worked on so that you can eventually remove abandoned tests.) For any user's id, the highest id in that table that does not have an answer, is the current question the user is working on.
-
Unable To Sign Anything With Openssl_Pkcs7_Sign
PFMaBiSmAd replied to vesko's topic in Miscellaneous
Since this thread isn't about getting help with what was causing your code to not work, moving thread to the appropriate forum section... Programming does not involve trying things and throwing them away until you write, find, or are given 'correct' code. It involves learning the meaning of what you are doing and when there is an error or an unexpected result, to determine what is causing it and fixing the problem. There's at least a half-dozen different things that could cause any particular error and any code someone posts could produce that/those same error messages for a reason wholly different from what was causing them for the code/data you tried. Around 99.2% of the problems using any programming language are due to a lack of understanding. The other .8% are actual bugs. You need to debug why your code didn't work, so that you actually learn, over expecting someone to hand you a working example, that probably won't work on your server, with your certificate, where it is located on your server, with the permissions it has set for it... -
Unable To Sign Anything With Openssl_Pkcs7_Sign
PFMaBiSmAd replied to vesko's topic in Miscellaneous
We cannot possibly help you with something you tried without the exact code you used, sample data that you used, and the specific error you got for that code and data. -
This is slightly off topic, but why are you using a prepared query statement, but putting php variables directly into the query statement. That defeats the purpose of using a prepared query statement.
-
You have to find the cause of the problem before you can fix it. Otherwise you just waste a bunch of time. By trying full opening php tags in that code, it will confirm if that is the cause of the problem. Edit: never mind, you posted while I was writing this and the forum's post notification is a -10 likes.
-
Try full opening php tags <?php
-
What does the opening php tag(s) look like?