Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,369
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. It sounds like your code also contains output buffering statements. these will have an affect on the OUTPUT of the content to the browser and could cause one instance of a header() to work and the other to not. if that isn't what is causing the current symptom, you will need to post the code that reproduces the symptom and identify which header() statement in it does and which doesn't trigger the error message. also, for the case where you don't get the error message, does the header() redirect work or does the code stay on the same page? it could be that the error is occurring, but the message is being hidden or suppressed.
  2. i would run one JOIN'ed query, then calculate the $result1 value while looping over the rows from that one query. the following query should (untested) work - $query = "SELECT g.Location, g.Date, g.HomeTeam, g.AwayTeam, t1.Teamdata1, t2.Teamdata2 FROM datagmaes g JOIN gamesdata t1 ON g.HomeTeam = t1.Team JOIN gamesdata t2 ON g.AwayTeam = t2.Team"; you should NOT apply number_format() to the Teamdata1 and Teamdata2 values. number_format() is an output function and should only be applied when you display the number, not when calculating or storing data.
  3. textarea's don't have value='...' attributes. you output the existing content in between the <textarea>content goes here</textarea> tags.
  4. firstly, you are not dealing with web links. include/require statements deal with files, i.e, paths and names. what does echoing $_SERVER['DOCUMENT_ROOT'] give? If the server is set up correctly, it will give - /home/youraccount/etc.., i.e. the path to your account's document root folder, and note the leading / which refers to the root of the current disk. you would just append the folder to where the included files are at to this value, not append the entire path to your document root folder again.
  5. i'll give same advice i gave a little over an year ago when you moved from shared to dedicated hosting - http://forums.phpfreaks.com/topic/294527-transfer-my-website-from-shared-hosting-to-dedicated-server/
  6. yes, just about anything is possible in programming, that's why this is called software. if it doesn't do what you want, it can be changed so that it does. however, this code is badly organized, to the point that it would take rewriting and retesting it just to get it to the point where it could be understood and then be modified to work differently. the code should be organized as follows - 1) initialization 2) post method form processing code 3) get method business logic - code that gets/produces data that's needed for the dynamic content on the page 4) get method presentation logic - code that knows how to produce the dynamic output on the page (for simple processing, this can be handled in the html document/template system.) 5) html document/template - produce the html document, or portion this code is responsible for, based on the result from the above sections
  7. there's no (good) reason that an application wouldn't allow any number of users to concurrently visit any page on a site and produce a result specific to the visitor. the code must therefore be doing something wrong, which we cannot tell you without knowing what exactly the code is. code would typically either use session variables or store data in a database using the user's id and any number of different visitors could be accommodated.
  8. assuming you are doing this as a learning exercise - you don't. users/admins to a site don't need to know or care what the database table structure is, so, you don't need to limit what tables (i'm assuming you mean database tables) they have access to and if you are dynamically making database tables to hold the content for each different user/admin, that's not how you would do this. the database tables you have, are what your APPLICATION needs to accomplish it's goal. it's your application code that has access to the database tables. all the content for a Content Management System would be stored in the same database table. controlling who can Create, Update, or Delete record(s) in that table would be handled by the user permission system, based on the user's assigned permissions or assigned role and ownership of the record(s). you should have a (one) user table that holds the unique user information. the user permission system would store its data in a separate set of tables, using the user id from the user's table to associate the assigned permission to the user it goes with. as to a user permission system, do some research on ACL (Access Control List.) in its simplest form, this defines actions that can be performed (create, read, update, delete) and assigns those actions to specific users. by creating groups of actions, you define roles, that you can assign to a user (in addition to any of the specific, overriding, actions), such as an owner(superadmin), admins, authors, members, guests. to limit Create/Update/Delete access to only those records a specific user created/authored, in addition to storing the author's user id in a column in the row of data, there would be a set of defined actions that limit access to the user with the matching user id. to allow an admin to be able to edit anyone's content, there would be a different set of defined actions that ignore the id of the author of the record. initially, to get the permission system started, you would manually store the user id of the person who is the owner/superadmin into the permission system, with a defined action that allows him/her to perform all possible actions. when that user logs in (and re-authenticates when making changes to user permissions), they would be able to, using an appropriately written user interface to the permission system, assign roles and/or specific actions to other users and also create and manage the actions and roles of the permission system. the code for any 'action' on a page would test if the current user has permission to perform that action and if the specific permission requires it, ownership of data, before performing the action.
  9. and if you make an array of the bedspace values, like they had been retrieved from a db table, you can dynamically produce the bedspace select/option menu by looping over the array, without needing to write out and the test and fix all that code and markup. btw - the <select ... value="..."> tag doesn't use a value="..." attribute and the one you are showing in your code should be removed since it doesn't do anything.
  10. there is no 'regex replace' in mysql. the regex pattern match would only let you find the rows containing the data that you need to update. to do this in a query would require that you use string functions to find the position of the start/end of the number in the string, split the string to get the number part, add the amount to the number, then replace the value in the string. you would be better off retrieving the data using php and use preg_replace to modify the data. if this is a regular occurrence, i.e. you set/update the value regularly, the value should be stored separate from the string it is in.
  11. this is the same basic task as in your previous thread - http://forums.phpfreaks.com/topic/301791-looping-results-from-query-and-limit-amount-per-row/ the sql query would join the table to itself to get the category/sub-category information using one query. then, change the $items_per_row = 5 value to 8, and make any changes you need to the html markup that's being produced.
  12. the code in question is now inside a conditional statement if($num_esb > '0'){ ... }. in the original, it was not. it was outside of and after the end of the conditional statement. you need to update the msyql_ statements to something more current. the msyql_ extension has been removed from php and your code won't run at all on current php versions. the PDO extension is the best choice to switch to. while you are making the changes necessary to keep the database code working, you should clean up all the repetitive code and consider using a template to produce the html document. you currently have a "cannot see the forest for the trees problem", which is one reason you missed putting the pagination links in the right place in the changed logic. the file has 670 lines of code, of which there is probably only about 400 lines that are needed.
  13. you would want to store the data in column defined as a decimal data type - http://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
  14. actually, i'm wondering if the <script>....</script> can be inside the form. you can move it to after the </form> tag to see. in any case, just telling us that something was not successful is not helpful. what did it do and when you debugged the problem in the browser developer tools/console and in the client side code, what did you find it WAS doing or not doing correctly?
  15. setting php's error_reporting to E_ALL and display_errors to ON (which should already both be set this way in the php.ini on your development system), should help with finding the cause of the problem. does the 'view source' of the page show all the repeated sections of content? maybe there's a broken html comment or tag that's preventing the output from being rendered by the browser. also, does the content, that's after the end of the loop, get displayed?
  16. you need to test the value being returned by the mail() function. if it's a true value, it means that php was at least able to successfully hand the email off to a mail server (doesn't mean that mail server is going to do anything with it or that the receiving mail server will accept it.) if you get a false value, there should be a php error providing information as to why either php or the mail server isn't going to do anything with the email. you can get the last php error information using - error_get_last() (returns an array of information.).
  17. do you have php's error handling setup to report and display all the errors that are detected? the pdo specific method of looping over the result from the query won't work with the ancient mysql extension and would be throwing a php error about an invalid argument being supplied to the foreach loop. to fetch data from the result of a query using the mysql extension, you would need to use a while(){} loop, like in your originally posted code.
  18. add GROUP BY products.id right before the ORDER BY .... term, to consolidate the rows having the same id into a single row in the result set.
  19. you will also want to JOIN the image table, whatever its name is, with the products table, so that you can run just ONE query. and did you really name the database column catagory, rather than category? your code should look like this - $items_per_row = 5; // number of items per output row $query = "SELECT p.id, p.catagory as category, p.name, p.make, i.name as imgName FROM products p JOIN $table3 i ON p.id = i.insert_id ORDER BY p.catagory, p.make, p.name"; // execute query using PDO, $pdo contains an instance/connection to the msyql database server $stmt = $pdo->query($query); // pre-process the data and index it by category, creating an array of arrays with the main index being the category $data = array(); foreach($stmt as $row) { $data[$row['category']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>$category</span></td></tr>\n"; // output the rows of data $chunks = array_chunk($arr, $items_per_row); foreach($chunks as $chunk) { echo "<tr>"; // start a new row foreach($chunk as $row) { // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $row['id'] . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $row['imgName'] . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $row["make"]; echo $row["name"]; echo "</div></div></a></td>\n"; } // complete a partial row $count = count($chunk); if($count < $items_per_row) { echo str_repeat("<td> </td>\n", $items_per_row - $count); } echo "</tr>\n"; // end the row } echo "</table>"; // end the table }
  20. in your previous thread, it was pointed out that you should not store a delimited list of values in one column. in this thread you have a sequence of named/numbered columns. this is just as bad for the same reason. you must write a ton of code/complicated queries to find or manipulate any of the data. you need to store each piece of data in its own ROW. you can then write simple code and straightforward queries to find or manipulate any of the data, from one piece of data up to the entire set of data.
  21. right after the line where you are replacing the <select>.....</select> option menu with the hidden form field, add the following - <script> javascript:ahahscript.ahah('[var.base_url]/uploader.php?sub_cat=1', 'sub_change', '', 'GET', '', this); </script>
  22. when you try to print/echo/print_r a false value, you will get nothing. if you want to know what the password_verify() statement is returning, use var_dump() on just that part of the value (if you concatenate it with a string, you will get a string result, and var_dump will show the string result, which will show nothing again from the false value.)
  23. example code - // define the possible choices for each set of filters - $dateorder = array(); $dateorder['asc'] = 'Ascending'; $dateorder['desc'] = 'Descending'; // note: you would query for the unique colors from your data to produce the choices, rather than hard-coding them // you may want an 'All' choice that would leave this WHERE term out of the query to match all colors. the 'All' choice would also be used as the default value if nothing is selected $colors = array(); $colors['red'] = 'Red'; $colors['green'] = 'Green'; $colors['blue'] = 'Blue'; //connect to the database $dbc = mysqli_connect('host', 'user', 'password', 'cars') or die('Error connecting to MySQL Server.'); $dateord = isset($_GET['dateorder']) ? $_GET['dateorder'] : 'asc'; // condition the input and set a default order $dateord = isset($dateorder[$dateord]) ? $dateord : ''; // validate the input as being only and exactly one of the permitted values $orderby_term = "ORDER BY id asc"; // note: asc is the default and doesn't generally need to be specified if($dateord) { $orderby_term = "ORDER BY caradded $dateord"; } $color = isset($_GET['color']) ? $_GET['color'] : ''; // condition the input $color = isset($colors[$color]) ? $color : ''; // validate the input as being only and exactly one of the permitted values $where_term = ""; if($color) { $where_term = "WHERE color = '$color'"; } $query = "SELECT * FROM cardetails $where_term $orderby_term"; $result = mysqli_query($dbc, $query) or die('Error Refreshing the page: ' . mysqli_error($dbc)); // the rest of your code using the data from the query... ?> <div id="leftcolumnwrap"> <div id="leftcolumn"> <h2>Trial Filters</h2> <form method="get"> <p>Order by Date:</p> <?php // note: the $value and $label (any dynamic data) being output, in the following two sections of code, needs to have htmlentities() applied to them, coding left up to you as an exercise foreach($dateorder as $value=>$label) { $checked = isset($dateord) && $dateord == $value ? ' checked' : ''; echo "<input type='radio' name='dateorder' id='dateorder_$value' value='$value'$checked><label for='dateorder_$value'>$label</label><br>\n"; } ?> <br><hr> <p>Filter by Colour:</p> <?php foreach($colors as $value=>$label) { $checked = isset($color) && $color == $value ? ' checked' : ''; echo "<input type='radio' name='color' id='color_$value' value='$value'$checked><label for='color_$value'>$label</label><br>\n"; } ?> <br><br> <input value="Submit" type="submit"> <br><br></form> </div> </div>
  24. your dateorder and color filters are doing two different things that you need to combine into ONE sql query statement. the dateorder is determining what the ORDER BY term should be. the color is determining what the WHERE term should. the logic for each of those should be (safely) building the two parts of the sql query statement, then produce the entire sql query statement by incorporating those terms into it. next, you should be using a method='get' form, since this is determine what the page will display and your form should be 'sticky' and select any existing radio button choice. the easiest way of making the form 'sticky' is to dynamically produce the form fields. if you make an array holding the choices, you can just loop over the array to produce the form fields and cause any currently selected choice to be checked. you can than also use this same defining array to validate that the input data is only and exactly one of the permitted choices. i'll post some example code showing these suggestions, if i have some time.
  25. you MUST test if the form submitted any data, before you can reference the data. there's a condition that occurs, most frequently when uploading files, though it can occur with any post method form submission, when the amount of data to be sent is larger then the post_max_size setting. when this occurs, the server aborts the transmission of the data and both the $_POST and $_FILES arrays will be empty. to handle this, you must first detect that a post method form has been submitted, use if($_SERVER['REQUEST_METHOD'] == 'POST'){, then you can detect this specific size condition and tell the user that the size of the submitted data is too large, then if there is $_FILES and $_POST data, you can reference the data to finish your validation logic. next, when you finally do loop over the $_FILES['file'] array, you must test that the ['error'] element is a zero ( UPLOAD_ERR_OK ), before you can use the file information. something like the example from the php.net documentation - foreach ($_FILES["file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["file"]["tmp_name"][$key]; $name = $_FILES["file"]["name"][$key]; $size = $_FILES["file"]["size"][$key]; // use the uploaded file information here... } }
×
×
  • 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.