-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
no one here is going to try and figure out your code the way it is written or posted. if you fix the following things in your code, so that you or anyone else can see just what your code actually is, and repost it using the forum's bbcode tags (the edit form's <> button), someone might take the time to look at it - 1) remove all the html comments associated with the template you are using or where you got this page from. html comments are rather pointless when dealing with a dynamically produced page. 2) remove all the commented out php code. if the code's not in use, it doesn't do you or us any good to have it clutter up what the actual code is. 3) remove all the excessive empty lines. you don't need more than one blank line between different sections of code to set them apart. 4) every place where you have a closing php tag, immediately followed by an opening php tag, remove those. there's no point to it. 5) indent your code so that statements at the same block level are indented the same amount. lastly, some comments about your actual code - 1) Don't Repeat Yourself (DRY). you have code repeated three times, that only differs in a value. you need to factor out the things that are different, then use one set of common code. 2) you need to use method='get' for your search form. what you are doing is specifying what is to be retrieved (gotten, i.e. GET) on a page. this will eliminate all your $_POST logic. 3) you need to move your count(*) query logic to be near the start of the php code so that you can use the total page count to limit the $_GET['page'] value. 4) your count(*) query needs to have the same WHERE clause as your main data retrieval query. i.e. you should be building the WHERE clause once, in a php variable, then use that in all the queries. 5) you need to learn how to use the ternary operator - (expr1) ? (expr2) : (expr3) to simplify code. 6) to retrieve ALL matching values for a column, just leave that column out of the WHERE clause in the query. 7) you need to validate and/or escape all external values being put into your query statements. that should be enough to get you started. i think that by completing item #4 in this second list, that you will be able to see what is wrong with your code that is causing it to not use the search terms the way you want.
-
since the form is completely dependent upon the javascript for its submission, do you have the js folder and the two files in it, on your system? did/does the original unmodified script work?
-
change url, session stops working in oscommerce
mac_gyver replied to jasmeet's topic in PHP Coding Help
unless you configured your web server to invoke the php language engine for .html files, none of the php code is even being recognized in the files. -
Proper method for form & function with variable validation
mac_gyver replied to airborne305's topic in PHP Coding Help
in general, when you want to request a page with specific existing information displayed on it, you would request that page with the id of the information in the url and the page would retrieve and display the corresponding data. i would get the last inserted id after the insert query is ran and redirect to the form page with that id on the end of the url. -
if you post your code that is producing the output, someone could help you with what it is doing.
-
Help with - Notice: Trying to get property of non-object in....
mac_gyver replied to 28mikes's topic in PHP Coding Help
there's a Mark Solved button at the lower-right-hand side of any post. i hit it for you in this thread. -
help with php/mysql inserting with binds
mac_gyver replied to afallingpanda's topic in PHP Coding Help
that's the other help forum site where you have been posting these same questions. you need to keep your threads and replies straight between all the different places you have posted them. i'm pretty sure no one that has replied in this thread is the same as the member you are referring to on that other site and someone misreading code and stating there's not a function/method is hardly anything to whine about, especially since he was questioning your code because it contains an obvious problem that would have prevented it from producing any output. -
help with php/mysql inserting with binds
mac_gyver replied to afallingpanda's topic in PHP Coding Help
the 'jargon' used in programming (or any activity) is not to exclude people, but to insure that the people partaking in the activity share a common base of information, so that a book doesn't have to be written each time information is exchanged, because there have been books written to teach the basics. you were not asked which database columns were the offending ones, you were asked for the definition of your database table, and then more specifically what the field types are of those columns. edit: i'm kind of curious how you know there are ones in these columns? what is the method or code that produced the output showing those? -
edit and update button on the same form in php
mac_gyver replied to jackgoddy123's topic in Applications
since you didn't state what sort of problem you are having or where you are stuck at in doing this, we cannot help since we don't have a clue what you need help on, i.e we are not standing right next to you and you must communicate effectively to get help. -
help with php/mysql inserting with binds
mac_gyver replied to afallingpanda's topic in PHP Coding Help
a) what is your database table definition? b) any chance the data is left over from some previous testing that inserted those values or some update code that updated those values? -
i recommend that you echo your $file variable so that you can see what it actually contains (the $_date variable isn't being replaced by its value.) you would need to concatenate the variable, the same as the $_REQUEST variable - $file = '/var/www/html/public_html/svsshc/'.$_date.'/'.$_REQUEST['id'].'.png'; or more simply, since it tends to reduce syntax problems, just use an over-all double-quoted string - $file = "/var/www/html/public_html/svsshc/$_date/{$_REQUEST['id']}.png";
-
you need to normalize your data so that you can find and manipulate the data easily. basically, there would be one row in a table for each piece of data that table is designed to hold. you would have two tables - users, and picks the users table - user_id name 2 jack 13 bob the picks table - user_id pick 2 3 2 6 2 10 2 56 2 63 13 10 13 36 13 69 13 70 13 99 the query to get the answer to the question of how many have selected the number 10 - select count(*) from your table where pick = 10
-
something i always recommend when validating user supplied input, is to have the failure message display the submitted value that failed the test along with the permitted values (as long as it doesn't expose any security information.) this will make your code self-troubleshooting and help the user by telling him exactly why something he did failed. btw - your form is missing the enctype that would allow the upload to work at all. your code must test if the upload worked before you can use ANY of the uploaded file information.
-
Delete multiple rows with PDO and checkboxes
mac_gyver replied to davidolson's topic in PHP Coding Help
when binding the input data: if using named place-holders, each one would need to be a unique name in the query so that each different id value will be assigned to its own place-holder. if using ? place-holders, you would need to increment the parameter number, starting with 1, for each iteration of the loop. -
or you could just use $_GET parameter(s), a separate one for each different filter/sort input.
-
Arduino: SQLite3, PHP, Very basic script
mac_gyver replied to RensD's topic in Other RDBMS and SQL dialects
i looked (more) at your device code. the form you are producing is repeating the same set of name='...' attributes for each device. only the last value for any name='...' is what is being submitted, which is empty due to the 'add device' set of form fields at the end of the form. because your intent is to only modify/delete one value at a time, you should produce a separate form for each row on the display. currently, with one form, pressing ANY of the submit buttons will submit all the values in the form. if you intended to modify/delete all the fields at once, you would have just one form and use array names for the form fields, with the device id as the array key, then just have one submit button. -
How do I optimise proddetail.php in ecommerce shop?
mac_gyver replied to oavs's topic in Applications
your first step ought to be to look at your web server access log for the time period in question to see how many and how frequently your site was being requested. if all the requests being made look legitimate (i.e. no hackers probing or exploiting some security hole or a DOS attack) then the issue is likely just normal/expected usage, combined with a cheep low cost web host that doesn't want your site using too much of the spread-too-thin resources on the server. aside from the included .php files, the page isn't doing anything out of the ordinary. you would need to profile all the code on the page to determine which if any of it is using an excessive amount of processing time. perhaps the menus are running queries inside of loops... there's one include statement with an @ error suppressor in front of it. do you know why that is there? trying to include a file that doesn't exist will take some extra time for php to determine that it cannot find and read the file. if the @ is because that file isn't present and you don't need the functionality in it, entirely comment out the statement. -
Arduino: SQLite3, PHP, Very basic script
mac_gyver replied to RensD's topic in Other RDBMS and SQL dialects
for the email, some of your logic is foo-bar - $results = $db->query("SELECT * FROM email"); $email_array = $results->fetchArray(); $email = $email_array['email']; ?> <!-- For debugging only --> <?php echo "In body after fetchArray: email_array "; print_r($email_array); echo "<br>"; ?> <?php if ($email == ""){ if ($_POST['new_email'] > ""){ $email = $_POST['new_email']; } } ?> the code above queries for ALL the rows from the email table, retrieves the first row (assuming at least one row exists) and sets the $email variable from the first row. it only uses the $_POST['new_email'] if there are no rows in the email table or the email address in the first row is empty. which brings us to your code trying to insert the email - if (isset($_POST['new_email'])){ // Update or Insert the emailaddres. $query = "INSERT OR REPLACE INTO email (email) VALUES ('{$email}');"; echo $query; @$db->exec($query); // Remove the old email address (if any) //$query = "DELETE FROM email ; "; //echo $query; //echo "<BR>"; //@$db->exec($query); // Put in the new email address //$query = "INSERT INTO email VALUES ('{$email}');"; //echo $query; //echo "<BR>"; //@$db->exec($query); this code uses whatever is in the $email variable, which will only be from $_POST['new_email'] if the email table is empty or if the first row in the email table has an empty email column. ALL the logic related to handling the form submission for $_POST['new_email'] needs to be within the - if (isset($_POST['new_email'])){ ...... } block of code. also, you should enforce uniqueness of things like email addresses in your database table by assigning a unique key to the column (not sure if sqlite supports this) or in your code by querying for the value before trying to insert/update it. lastly, most of your symptoms 'sound' like the browser is requesting the page twice. when you are observing empty submitted data, it's because the last of the two requests doesn't have any submitted data. in general. you need to validate that there is data before using it, i.e, required/expected data is at least not empty. -
a) the hidden MAX_FILE_SIZE form field goes before any type='file' fields if you want php to use it to test the size of the uploaded files. b) the size of your test file is greater than the 30000 specified in the MAX_FILE_SIZE hidden field, resulting in a upload error value of 2. you must always test for errors at any step that can fail before you can use the data you expected from that step. in this case your upload is failing with a non-zero error number. test if the ['error'] element isset and is equal to a zero before trying to use any of the ['size'], ['type'], ['name'], or ['tmp_name'] values.
-
$QchoiceResult is an array. if you are not referencing $QchoiceResult[0], you won't get the selected count(*) value from the query. edit: you also have a spelling/capitalization error between the :rid placeholder in the query and the bind statement that is either throwing a php warning or an exception, depending on what pdo error mode you are using. you always need to test for errors before you can use the result from any step in your code.
-
@Ritual29, the nonspecific answer you have provided has already been given, with much greater detail, with the name of the function, a link to its documentation, and an example, in a previous reply in this thread. please don't parrot answers already in the thread unless you are adding helpful information to the thread.
-
it would sure help if you posted that error. if it concerns using an undefined constant, that's because you left off the $ in front of the share_postcode variable in the query statement. all the logic you have after your mysql_fetch_assoc() statements is invalid. the $rstDBEdit variable contains the fetched array and you would reference individual elements of that array like - $rstDBEdit["pcode_city"]. also, php assignment statements assign the value on the right-hand side of the = to the variable on the left-hand side. you can use an INSERT ... SELECT query to select data from one table and insert it into another table using one query - http://dev.mysql.com/doc/refman/5.6/en/insert-select.html
-
@Ritual29,the SET syntax is perfectly valid for an INSERT query -
-
PHP form not transferring data from a field
mac_gyver replied to mktimpact's topic in PHP Coding Help
answers - 1. by determining where your code and data are doing what you expect and where they are not, to narrow down the point where the problem is at. 2. the id="..." attribute is only used in the client-side code and unless that form element is being referenced in the client/browser by its id, the lack of an id won't have any affect. the name="..." attribute determines what data is submitted. there's nothing obviously wrong with the form. in fact, most of the form fields don't have id's. on the page where that form submits to, add the following line of debugging code to display what post data is being submitted (i'm betting that the comment data is submitted, but the form processing logic isn't doing anything with it or is overwriting it) - echo '<pre>',print_r($_POST,true),'</pre>'; -
PHP form pull MySQL data for field when another field is selected
mac_gyver replied to tycoonbob's topic in PHP Coding Help
only part of your data is being submitted because of the reason given in post #16 and #19. if you look at the 'view source' of your form page, you will see that all the value is present, but only the part up to the ' is being submitted.