Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. you should NEVER create different files of code that only differ in the table column being searched. to specifically search for just a first name or just a last name, all you should have is one file and a little program logic that dynamically picks the table column to be searched. you should also NEVER run loop over the result from one query and run another query inside of the loop. you should run one JOINed query, then just loop over the result from that one query. you should also separate the concerns in your code, which would make it easier to debug your code and to just post the portion of the code where the problem is at. at a minimum you should separate the database dependent code (that knows how to retrieve the data) from the presentation code (that knows how to produce the output from that data.) the result (output) from the database dependent code should just be an array of any rows that the query matched. the database dependent code should contain no html and the presentation code should contain no database statements, just php statements that test and operate on the array of data. for debugging, if the array of data contains the expected result, you know the database dependent code is working and that the problem is in the presentation code. lastly, the code you have attached starts after some main query that's not part of the code. without knowing what those main queries are, we cannot possibly help you with anything your code is or is not doing.
  2. STR_TO_DATE() would be used in a single UPDATE query to take any formatted date and produce a mysql date type.
  3. it depends is what the 'logout' index is intended to be a part of and how it is being used in the code. it could be $_POST, $_GET, or some other array. the context for each program variable that you are fixing needs to be taken into account. two other big problems you are going to have with older code that will require doing a rewrite are - 1) php used to try and escape input data, hoping that if you put it into an sql query statement, that it would prevent sql injection and sql special characters in the data from breaking the sql syntax. this 'feature' has been completely removed, so it's up to your code to either escape string data that's being used in sql query statements or use prepared queries. 2) the php version where the mysql_ database statements have been removed has already been released. if you or your web host upgrades to php version 7, all code that's using mysql_ functions will cease to work. the best choice for a replacement is to use the PDO class. this will also make using prepared queries the cleanest. if you really have 1000's of php variables that are affected by the removal of register_globals, it may be time to refactor your code to dynamically process and produce forms or dynamically produce logical pages using a single main page, using a data driven design, rather than to hard-code each and every variable, multiple times in any script or repeat pages that only differ in the content that's being displayed on them. producing a data driven design, also tends to result in DRY (Don't Repeat Yourself) programming, where repetitive program logic and markup are reduced, which in turn makes it easier to change or fix anything, since the logic or markup for any particular functionality only exists in the code once.
  4. javascript/ajax/jquery is not required to make the client/server functionality for a web page. they are used to add to the presentation of the web page. you should get your client-side and server-side code to work first (even to the point of it working with javascript disabled), because you will need all the same html markup and php code, with or without using javascirpt/ajax/jquery. your two tabs are just two 'views' that are present on the web page. when you pick/enter a date in your form field and submit the form, which should be a get method form since you are determining what the page will display, it should submit any existing get parameters as hidden form fields, along with the date. the server side code should then use the submitted get parameters and retrieve any data for the two views, produce the two sections of output for the page, then produce the complete html document and send it to the browser. once you get all the program logic in place and working, then add things like displaying the output in tabs, adding a date picker to populate the form field, using events to submit forms, using ajax to send data to the server and display the result, ...
  5. browsers have a habit of requesting pages twice, for several different reasons. you could also have have an error in some of your client side code (submitting a form via ajax and not stopping the browser from submitting it as well) or server side code that's causing it. in any case, you should not be modifying a count in a database column to track quantities of things. you should add a record to a database table for each 'transaction' that adds or subtracts a quantity, like what your bank or credit card company does. this record would would have columns for who (a user_id) caused the change in the quantity, the item_id, the quantity - a positive or negative value, a datatime when the records was inserted, and a status/memo column to record the type of transaction or a comment about the transaction. the initial quantity on hand would also be entered by inserting a row in the table. to get the quantity at any point in time, you would just SUM() the quantity column value for any item_id.
  6. UPDATE queries don't return a result. calling the ->free() method after running an UPDATE query makes no sense.
  7. the template system is only concerned with producing and outputting the html document. it has nothing to do with what functionality is present on the page. what template system you use is dependent on your programming skill and knowledge and how much time you want to invest in learning something new.
  8. the example code has information for three users hard-coded into it, i.e. there's three sets of the two related div's in it. if you want to do this for a dynamic number of users that you retrieve from a database query, you will need to dynamically produce each of the two related div's for each user you want to display. you would do this by looping over the data you retrieve from your database query, populate, then output a template version of the two related div's with the correct data for each record from the query. the only issue you should be facing is what sort of template system you want to use. they range from simple php echo variable statements up to full template engines that implement logic, loops, functions, caching...
  9. the only way those two functions would run the php code in the file being tested is if you are using a URL to reference the file, instead of a file system path. if these .php files are on the same server as your php script that is testing if they exist, you should be using a file system path. i've got to ask, if this is your code, why do you need to test if a .php file exists? you should already know if it does.
  10. one = is an assignment operator. two == is a comparison operator. the conditional tests in your code are assigning values to $row, then testing the value that was just assigned. your code is not testing the value in $row. also, $row is an array, from the msyql_fetch_row() statement (the mysql_ functions are obsolete and have been removed from the version of php that was just released, you should be using PDO or msyqli_ statements.) it will never be equal to those string values. you would need to test a specific element in the array in $row. in general, you should use an associative fetch statement, so that your code is more readable, and more maintainable. using $row['race'], instead of $row[1], will make it easier to write and read your code, both for you and for anyone else that must deal with it. lastly, DRY (Don't Repeat Yourself.) your code should not repeat program logic and html markup over and over, when just a small part of it is the dynamic/changing part. ideally your mapping of race values to image base names should be one to one, with the same image base name as the race value. this would eliminate all the if/elseif logic. you would have just one line of code - echo "<img src=\"http://someaddress.me/sieges/img/fortezze/{$row['race']}.png\" border=0>"; if for some reason you cannot make the race value and the image base name the same, you should use a simple mapping array to give the image base name that corresponds to the race name - $map["ELYOS"] = 'elyos'; $map["ASMODIANS"] = 'asmodian'; $map["BALAUR"] = 'balaur'; // add any other race/image base name pairs here... echo "<img src=\"http://someaddress.me/sieges/img/fortezze/{$map[$row['race']]}.png\" border=0>";
  11. you would need to dynamically produce the two div sections - <div class="row user-row"> ... </div> and <div class="row user-infos cyruxx"> ... </div> by turning those sections into a template with replaceable parameters for the values/portions that are dynamic. the only 'magic' to make the javascript work is the data-for=".cyruxx" class selector inside the first div must be a valid class selector and match what is used in the second div definition - <div class="row user-infos cyruxx">
  12. it sounds like you are supposed to create a form for inputting the numbers/selecting the operator -
  13. just checked the mysql documentation and CREATE EVENT queries cannot be prepared. see the list of statements that can be used - http://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html just confirmed this by getting your 'prepared' query to work with PDO's prepared query set to 'emulated' and also by using a normal ->query() method with your hard-coded query. using a real prepared query, it silently fails with nothing in the mysql query or error log, so the lack of any pdo error is likely due to the php driver not doing anything in this case.
  14. you cannot get a result from $stmt->num_rows;, unless you have called $stmt->store_result(); (see the $stmt->num_rows documentation.) this is one more reason to not use mysqli. if you use PDO, all your database code will be simpler.
  15. the database user you are using for the php connection probably doesn't have permission to create events. have you set the error mode to exceptions on your pdo connection so that any errors will throw exceptions, and are you either catching the exceptions/providing your own exception handler and doing something with the error information OR you have php's error_reporting set to E_ALL and display_errors set to ON so that any uncaught exceptions would be reported and displayed?
  16. if would be a little conditional logic - // example data $data[] = array('date'=>'2015-12-10','date_from'=>'','date_to'=>'','name'=>'event1'); $data[] = array('date'=>'2015-12-11','date_from'=>'','date_to'=>'','name'=>'event2'); $data[] = array('date'=>'2015-12-11','date_from'=>'','date_to'=>'','name'=>'event3'); $data[] = array('date'=>'','date_from'=>'2015-12-09','date_to'=>'2015-12-10','name'=>'event4'); $data[] = array('date'=>'','date_from'=>'2015-12-20','date_to'=>'2015-12-29','name'=>'event5'); $last_value = null; // use to detect date change for multiple events on a date $first_pass = true; // used to output a one time label foreach($data as $row){ // loop over the data. you can either fetch all your rows into an array named $data, or replace this line of code with a while() loop that loops over the result set from your query if($row['date']){ // there is a specific date, do the specific date handling // if the date changes or is the first one, output a new heading if($last_value != $row['date']){ // save the new date as the last value $last_value = $row['date']; // format the date for display $date = date_create($row['date']); echo date_format($date, 'F j') . '<br>'; } // output the data under the heading echo $row['name'] . '<br>'; } else { // there is not a specific date, do the general date handling // output a one time label for this section if($first_pass){ echo "Ongoing Events -<br>"; $first_pass = false; } // format the dates for display $date1 = date_create($row['date_from']); $date2 = date_create($row['date_to']); echo date_format($date1, 'F j') . ' to ' . date_format($date2, 'F j') . ' ' . $row['name'] . '<br>'; } } the ORDER BY term you have in your query should produce the correct output. you would want the rows, having a date, first in the result set.
  17. you have got to be kidding - either upgrade your php version to at least V5.5 or use standard array syntax, that works with all php versions.
  18. the syntax you are using on line 13 is only available in php5.5 and above.
  19. because you are using the IGNORE keyword in the INSERT query, you are probably triggering some unique index/key error. you would only use the IGNORE keyword when you want to silently ignore duplicate data and the index/key errors they cause. however, just about everything your code is doing is has a problem. the biggest problem is your food database table should NOT have columns like - eggs_price, bread_price. the data for each item, eggs, bread, ... should be a separate row in the table, with an item_id column that identifies which item the price is for. another BIG problem is the massive amount of logic you have (or are going to write) that only differs in the the values being tested/used. if you use an array to hold the weekday/hour data, all that $weekday/switch($hour) logic can be replaced with a few lines of code. lastly, what is the overall goal of doing this? you are apparently calculating prices for each hour for each day of the week a date falls on. this is derived data and you will end up with a massive amount of stored data as the number of dates increases. in general, you would not do it this way, but store the weekday/hour data in a data structure (database table, array) and calculate the price as needed.
  20. string data that may (in this case does) contain sql special characters (characters that have meaning in the sql syntax), such as NULL (ASCII 0), new-line, carriage-return, \, ', ", and Control-Z, must be escaped (or use prepared queries) so that the sql special characters don't break the sql syntax. for the mysql database, the escape character is a \. if you are manually typing the sql query statement in your code, you can just add the \ before each of the the single-quotes that are inside the sql query statement. if this is not static data that's been typed in your code, you should either use the escape_string function/method for the php database api you are using or use prepared queries, which separate the sql syntax from the data values being used in the query.
  21. the php error on line 8 is because the name='...' attribute for your <textarea> is 'text' the php error on line 12 is/was because of the repeated $name = assignments. i recommend that you first get your form and your form processing code to work correctly, then add any javascript validation and using ajax to submit the form data. edit: the only thing changing the code testing $message is doing is hiding the fact that your form field isn't named 'message.' the $message variable is set, because your code is setting it. !isset() will never cause your 'please provide a message' to ever be output.
  22. you are also getting php error messages being sent back. primarily because there are no $_POST['message'] and $_POST['honeypot'] in the data you are sending to the php code. you can find these if you look at the response sent back to the browser's developer tools -
  23. for ease of use and code readability, you need to end up with the language strings either in defined constants or an array, with the defined constant name or the array index indicating the meaning of the string. you can dynamically produce the defined constants/array from wherever the data is actually stored at. for these two examples, the Italian language was selected. only the building of the defined constant/array is dependent on the language choice. the actual usage in the code is the same regardless of the language choice. if you use the defined constant method - // definition define('LANG_contact', 'Contatto'); // the define() statements can be dynamically called if the data is stored in a database table. // usage echo LANG_contact; if you use the array method - // definition $lang['contact'] = 'Contatto'; // the array can be build dynamically if the data is stored in a database table. // usage echo $lang['contact'];
  24. your alter table query is using the php mysql function to run the query. you are however apparently using either the mysqli or the PDO classes for your connection and the rest of your code. as was stated in one of your previous threads, you cannot mix the different php database functions together for a single connection. if your mysql based statements appear to be running without producing database errors, it's because most of the all-in-one xAMP packages set up default mysql database credentials that allow mysql statements to make a database connection if there isn't already one. also, please do NOT suppress any errors in your code. remove any @ error suppressors and make sure that php's error_reporting is set to E_ALL and display_errors is set to ON in the php.ini on your development system. if you are tyring to learn php or learn anything new in php, developing php code, or trying to debug problems in php code, you want ALL THE HELP YOU CAN GET from php. you don't want to hide any of the php errors.
  25. the part between the (...) is.
×
×
  • 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.