Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,354
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. with all the changes that have been made, what is the current end result/symptom when this fails? i would still be concerned about the values not being urlencoded (which the http_build_query does for you) when building the links, since any sort of non-url-permitted character could be treated differently by different browsers and would result in the submitted values being different from what was used to build the link and so wouldn't match in a database query.
  2. text textarea, and password form fields will be set, even if they are empty. your form processing logic should first test if your form was submitted, then specifically test the content from each form field. for fields that are required, at a minimum, you would want to test if their character length is greater than an acceptable minimum.
  3. some more advantages of rearranging the code as ginerjm has suggested are - 1) it will be easier to update the existing mysql code to use the mysqli or POD database functions, since the mysql functions are obsolete. all the database code will be close together, near the start of the code file. 2) since the main logic that determines what to do on the page and what data is being produced will be grouped closer together, it will be easier to avoid problems like the $userid variable problem. 3) it will make testing and debugging the code easier, since once you have determined that the main php code is producing the correct result, you can forget about that part of the code and concentrate on getting the correct output on the web page. 4) you will be able to perform a header() redirect back to the same page once you have successfully processed the form data, thereby making the user experience better since the browser won't attempt to resubmit the form data should you refresh the page or navigate back to any page that was the target of a form submission.
  4. @JTM, is this a second account for you? we have another member joemal, that posted code for this same assignment and from the same location you are at.
  5. there are existing resource availability/resource reservation scripts that probably do this in some fashion (likely for reserving/booking rooms, rather than a trainer, but the logic is the same.) you would need a table to hold the resource (trainer) availability schedule, all resources in stored in the same table, using a resource id to identify which rows are for each resource. for reoccurring schedules, you would need to store the definition of the schedule (Mike is available on Mondays-Friday from 8am-5pm) and evaluate it, storing the resulting dates and times in the availability schedule table, as needed (any query displaying data with a date higher than the latest stored date would evaluate the definition to populate dates up to at least the latest display date.) you would have a second table to hold resource reservations, with the resource id, the id of who is requesting the resource, the date, start time, end time, and a status. the status would indicate if the resource has been requested (someone selected a date/time slot, but it has not been confirmed) or booked (if the trainer has reviewed and confirmed the reservation.) any resource reservation with either of those status values would not be available for selection. if there is a preference for a particular resource or type of resource, you would get and apply a filter in the query that determines which resource id(s) you match in the resource schedule table and for just the date(s) you are trying to display. you would then join the rows from that table with the resource reservation table, using the resource id and date columns, to get the row(s) and therefore the start/end times the resource is (is not) available for selection. that should get you the data you need to display a grid of appointment slots that are (are not) available for selection.
  6. that's the binary data of a png image. either your code isn't outputting a content type header for a png image, or it is but the header isn't working, or you are trying to output the image data on a html web page, which isn't how images are displayed. what's the php code that's doing this and do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would report things like header errors?
  7. you would put the sum logic into the existing query (2nd one in the posted code), so that it would produce a total for each row.
  8. it's likely that the actual data you are getting from your database query isn't what it looks like or you have a variable scope problem. when you printed the $start_point value, where exactly in your code did you do that and what does using var_dump($start_point);, right before the code you have shown us, give for the value?
  9. your online test page stops producing output after the <body> tag. that's a sign you are getting a fatal php runtime error prior to any php echo statements. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? edit: especially since your database table name is not calendar.
  10. in programming, you need to be careful what wording you use. when you mentioned inserting data, that was taken to mean insert data into a database table. what you actually meant is displaying data in the calendar you are outputting on the web page. there's no inserting involved, you are taking data you have at some point in your code and producing html that displays that data the way you want it to be on a web page. using the mysqli code converter to get your code to use the mysqli functions isn't going to get you much sympathy, because it produces messy, lazy, error prone code. learn to actually use the mysqli or PDO statements and rewrite the code yourself. there's a minor problem with the (test) $entries data that's in the code now, in that the data you eventually retrieve from your database table and put into $entries will have leading zero's on the month and day fields and will have - separator characters. by default, unless you do more work to get there, the format will be YYYY-MM-DD. the line of code to build the corresponding $dateKey value will be - $dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d); if you change the format of the test data in $entries and the above line of code, this should get your code to display your test data. the next task would be to retrieve the event data from your database table, that matches the $currYear, $currMonth values, and store it into the $entries array in the necessary format.
  11. besides listing what you want, do you have a specific programming question or a problem you need help with?
  12. some points that hopefully will help - 1) you should be development and testing code on a localhost development system, where you can easily set php's error_reporting to E_ALL and display_errors to ON in the php.ini so that ALL the errors php detects will be reported and displayed. the last problem pointed out, about the syntax of using a php array variable inside a string, in your main file, would have been producing php parse/syntax errors, that will only show up if you have php's error_reporting/display_errors set in the php.ini. 2) the ->get_result() method is specific to a certain type of underlying database client driver being used (mysqlnd) and may be producing a php run-time error (which is why, again, you should be developing and debugging code on a system that has php's error_reporting/display_errors set so that php will help you.) the example code i am posting below uses another mysqlnd specific statement, ->fetch_all(), that may not work either. if these two statements produce undefined method php errors, the code using them will need to be rewritten or more simply, if it is an option available to you, use the PDO database statements as they are much easier to use. 3) in general, the code producing or containing any of your your html/css/javascript (client-side) markup should be separate from the portion of your code that knows how to retrieve data from the database. the code producing the html should have no database specific statements in it. this will allow you to more easily change the type of database statements being used or to delegate and divide the work among others. you would retrieve the data from your database and store it in a php array variable, then simply loop over that variable in place of the while(){} loop you have now that's making use of the msyqli fetch statement. 4) your code producing the table output can and should be written to be general purpose as well, so that it can display any amount of columns and rows that the query retrieves. a rearrangement of your code that demonstrates (untested) these points (and while i was doing this i noticed an ->execute() method statement that wasn't, which would have been producing another php run time error) - <?php $mysqli = new mysqli("localhost", "guestuser", "guestuser", "SMQ"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } $validScott = $_GET['scott']; $query = 'SELECT Scott, Den, Color, Cond, 70, 70J, 75, 75J, 80, 80J, 85, 85J, 90, 90J, 95, 95J, P98, 98J, 100 FROM SMQSQL WHERE Scott = ?'; $stmt = $mysqli->prepare($query); $stmt->bind_param('s',$validScott); $stmt->execute(); $result = $stmt->get_result(); $results = $result->fetch_all(MYSQLI_ASSOC); // if the ->get_result() method is present, the ->fetch_all() method is also available, otherwise you will need to bind the result from the query and fetch it or use the more friendly PDO database library $stmt->close(); // get data for table heading $finfo = $result->fetch_fields(); $fields = array(); foreach ($finfo as $val){ $fields[] = $val->name; } // the above php code is the business logic, that knows what to do on the page and how to get data from the database // the following code, is the presentation logic, that knows how to produce the output on the page $heading = "<tr><td>".implode("</td><td>",$fields)."</td></tr>"; $queryResult = ''; foreach($results as $row){ $queryResult .= "<tr><td>".implode("</td><td>",$row)."</td></tr>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/url] <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml">[/url] <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Online SMQ</title> </head> <body> <form name="searchForm" method="GET" action="#"> <input type="text" name="scott"> <input type="submit" name="submit" value="Search"> </form> <p> <table> <?php echo $heading; ?> <?php echo $queryResult; ?> </table> </body> </html>
  13. @subhomoy, the following paypal link describes the process you will need to use for the IPN information - https://www.paypal.com/in/cgi-bin/webscr?cmd=p/acc/ipn-info-outside as the last step, to finally record the payment as being successful/complete for a user, for a specific order he has made, you need to check the payment_status value, which is something that fastsol included in his post. in fact, since you are not using or storing that value, it's possible that your duplicate data in the payment table has two different statuses. you may want to log each set of data your ipn script receives so that you can detect nefarious activity. next, just because the data your ipn script receives is coming from paypal, doesn't mean it is safe. since you appear to be using the PDO database class, you should be using prepared queries. lastly, your code appears to be making a database connection for each query you are running - $pdo->connect()->query(...). if that is the case, you should only make ONE database connection and use that connection throughout your script.
  14. your page is being requested twice. you would need to do some debugging to find out way. some causes are url rewriting you are doing for your site or even how your web hosting is passing the request to the server where your web site is hosted. however, you cannot prevent duplicate requests in all cases and you need to enforce uniqueness within your application to filter out duplicates. your payment table should be setup with a unique composite key that prevents duplicate transition id/user id combinations. next, when dealing with real money or any sort of data that you need to have the ability to audit the data, you should not simply add the amount to a sum in a column. you should treat this as a deposit/debit account, where you use a query to sum up the transactions to determine the current amount in the account each time you need the current total.
  15. the second thread you started for this in the ajax forum section has been removed. there's no evidence the problem is in any of the client-side ajax code and if debugging this should show that's where the problem is at, this thread can be moved to the appropriate forum section.
  16. this is actually about the same logic as in your last post, but eliminates the extra code at the end to finish the last day of the week - <?php $fd = array(); $fd[0] = array('f'=>"8:00 AM",'t'=>"4:30 PM"); $fd[1] = array('f'=>"8:00 AM",'t'=>"4:30 PM"); $fd[2] = array('f'=>"",'t'=>""); $fd[3] = array('f'=>"9:00 AM",'t'=>"1:00 PM"); $fd[4] = array('f'=>"",'t'=>""); $fd[5] = array('f'=>"9:00 AM",'t'=>"1:00 PM"); $fd[6] = array('f'=>"",'t'=>""); $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",''); // the extra value on the end processes the last day without repeating any logic $last_from = null; $last_to = null; $output = ''; $last = count($WeekDays)-1; foreach($WeekDays as $key=>$day){ if($key == $last || $last_from !== $fd[$key]['f'] || $last_to !== $fd[$key]['t']){ // it's past the end or the from/to is not-equal to last values if($last_from !== null){ // not the first section, build the section that just ended $end_key = $key-1; $op = ($fd[$end_key]['f'] != '') ? "{$fd[$end_key]['f']} to {$fd[$end_key]['t']}" : 'Closed'; $dy = ($start_day == $WeekDays[$end_key]) ? $start_day : "$start_day - {$WeekDays[$end_key]}"; $output .= "$dy $op<br>"; } // start a new section $last_from = isset($fd[$key]) ? $fd[$key]['f'] : ''; $last_to = isset($fd[$key]) ? $fd[$key]['t'] : ''; // remember the new values $start_day = $day; } } echo $output; the data array is organized differently to make the references clearer. you can change the form field names to submit the data as shown or change the references in the code to match your current form field names.
  17. this thread is also the third time the OP posted this. merging with the other thread that has replies. post #5 and down is from the later thread.
  18. another advantage of the method mentioned by Psycho, is you can just create a view to your table that only shows the non-deleted rows, then just use the view name as the table name in any query where you want to exclude the deleted rows.
  19. please see the pinned/sticky post at the top of the forum section you posted this in.
  20. okay, what's your code that attempts to do this? you started the thread with a general fishing question. you got replies mentioning ways you could catch a fish. we are not here to do the fishing for you, especially since the only specific information you have posted is a table name and one column name.
  21. if the tables have a defined relationship (we/i don't visit unknown links) that you are trying to join together to return the correct related data for each row, you need to get the joined query to work correctly first before you try to add any conditions to filter the results. i also recommend putting the join conditions with the join terms, not in the where clause. this a rearrangement only of the first posted query (doesn't attempt to fix anything about the logic) - FROM `activepropertylist` A JOIN `RegionEANHotelIDMapping` RM ON A.EANHotelID = RM.EANHotelID JOIN `ParentRegionList` R ON RM.RegionID = R.RegionID WHERE MATCH(City, RegionName) AGAINST ('hervey bay' IN BOOLEAN MODE) you would only use a UNION query for similar, not related, data in multiple tables (you must select the same number and type of columns in each query and the column names from the first query is what is used for all the data.) showing some sample data from each table, what relationship there is between the tables, what column(s) from each table you want to filter, and what result you expect from that sample data would be the quickest way of solving the puzzle.
  22. afai can determine, to make this work, using both an exact phrase and a wild-card ending, you could use either of the following methods - 1) all but the last word entered, even if there is only one word, are split from the submitted search string and become the exact phrase, then the last/partial word, if there's more than one word, would be added to the search term as +partialwordhere*. for your example, the search $string would be - "Newcastle upon" +ty* edit: if there is only one word/partial word, this should not be used as an exact phrase, only as the +partialwordhere*. this however will match things where the partial word match exists anywhere, not just immediately following the exact phrase. the suggestion found on the web is to add a HAVING clause with a LIKE comparison that matches the complete phrase that was entered - HAVING City LIKE 'Newcastle upon ty%' 2) this is a variation on #1, without using the exact phrase at all. you would split the words and make each one required, with the last one adding the wild card. for your example, the search $string would be - +Newcastle +upon +ty*. you would still also use the HAVING clause as described above to filter the resultant rows to those that only have the complete phrase in them.
  23. the rows per page would apply to how many gameweeks to display on one page. if set to a one, only one gameweek would be displayed per page and the pagination links would become gameweek selectors rather than page selectors. next, do you want to display all information for the games on the selected gameweek or do you want to paginate that information too (assuming there are a large enough number of games in any gameweek to require pagination)?
  24. how do you know which queries are to use the second database connection and if possible can you add some unique table prefix to indicate this? one way would be to write a function/class to abstract the database access, that a simple search/replace can change all the msyql_query() statements to use, that would run the query using the correct connection based on something unique in the query statement. are any of your existing mysql_query() statements inside of your own user functions/classes? edit: answer you probably don't want to hear - is a better way of going about implementing it. yes, if you have a design that has hundreds of files, where database queries exist in a majority of those files, it might be time to rewrite the code to use one common set of code that dynamically produces the pages of the site.
  25. using pagination, with a 'rows per page' value of one, and ordering the rows in the query by gameweek, would give the result you need, especially for the previous/next links, and would end up working for any number of games stored in the table.
×
×
  • 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.