-
Posts
5,537 -
Joined
-
Days Won
192
Everything posted by mac_gyver
-
the code you posted in this thread was broken because you made edits to it to remove information from the post and you removed at least one quote/semi-colon, which made it next to impossible to help based on the code, because we don't know what else you may have changed in it when posting it. repost the code, literally just replacing any sensitive information with x's (you should have this type of information defined in a require'ed file using variables or defined constants anyway), but do not modify any syntax, such as quotes, semi-colons, ... next, assuming this is a run-time error, and not a php syntax error, you should have the following three lines at the start of your php code to get all php detected run-time errors reported and displayed - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(-1); have you tried a .php file with just something simple like the following in it - <?php echo 'yes php works'; ?> is there a .htaccess file that came from the old hosting? it may have some statements in it that's producing an error. however, there should be errors in the web server error log. if you do have a .htaccess file, what is the contents of the .htaccess file? also, what was the web server type on the both the old and new hosting?
-
PHP between time's issue - pulling my hair out
mac_gyver replied to jamesmpollard's topic in PHP Coding Help
this should do what you are asking, without all the hard-coded logic (DRY programming), making it easier to modify any portion of the code or markup - <?php // if the current time period is between (inclusive) the start and end, return true function betweenTime($time, $start, $end) { // strcmp - // greater or equal would be >= 0 // less or equal would be <= 0 if((strcmp($time,$start) >= 0 && strcmp($time,$end) <= 0)) { return true; } else { return false; } } // sample data $Appts = array(); $Appts[] = array('start'=>'2015-12-22 08:00:00','end'=>'2015-12-22 08:00:00'); $Appts[] = array('start'=>'2015-12-22 10:00:00','end'=>'2015-12-22 12:00:00'); $Appts[] = array('start'=>'2015-12-22 13:00:00','end'=>'2015-12-22 13:30:00'); // list of times 8:00 am (08:00) to 12am (00:00) for the <td></td> grid and to test against $times = array ( 0 => '08:00', 1 => '08:30', 2 => '09:00', 3 => '09:30', 4 => '10:00', 5 => '10:30', 6 => '11:00', 7 => '11:30', 8 => '12:00', 9 => '12:30', 10 => '13:00', 11 => '13:30', 12 => '14:00', 13 => '14:30', 14 => '15:00', 15 => '15:30', 16 => '16:00', 17 => '16:30', 18 => '17:00', 19 => '17:30', 20 => '18:00', 21 => '18:30', 22 => '19:00', 23 => '19:30', 24 => '20:00', 25 => '20:30', 26 => '21:00', 27 => '21:30', 28 => '22:00', 29 => '22:30', 30 => '23:00', 31=> '00:00'); // loop over data foreach($Appts as $arr){ // get just the HH:MM of the 'YYYY-MM-DD HH:MM:SS' values $start = substr($arr['start'], 11, 5); $end = substr($arr['end'], 11, 5); echo ' <tr class="participant"> <td class="pname"><div class="pname">James</div></td>' . "\n"; // output the time grid foreach($times as $time){ $class = betweenTime($time,$start, $end) ? 'y' : 'n'; echo '<td class="partTableCell ' . $class . ' dsep pok"></td>' . "\n"; } echo '<td class="partTableCell n dsep pok"><img src="assets/images/delete.png" width="20" height="20" /></td> </tr>' . "\n\n"; } -
this is a reply from the end of your last thread - your php code is running the query twice. if you don't see the lines in your code that are doing that, i don't think you are looking at your code.
-
that's not an 'error'. it's the raw php code. if the raw php code is being output to the browser, either - 1) you didn't use a URL when you requested the page and you ended up requesting the file through the file system. 2) the code doesn't start with a full opening php tag - <?php 3) the file extension isn't .php 4) you don't have php installed and working on your web server.
-
the code as posted above doesn't produce that error. it's likely that something about how it was published, with the highlighting, and how you copied it into your file or what you used as an editor got some encoded characters or the edits you did introduced a curly/smart-quote instead of a straight-quote. i would copy/paste the above into a completely new file and try it.
-
we are not here to modify someone else's code to do what you want. if you cannot make this change yourself, ask the Author of the software to do it or find another way. you should also not be using values calculated in the client, on the server, even if you trust the person who is filling in the form on the client. you should only display client-side calculated values, as a convenience for the user, but your server-side code should do any calculation based on the original data that's stored on the server. you should also not store calculated values in a database table. this is derived information and should be calculated when needed.
-
Help with Error Msg: Cannot use string offset as an array
mac_gyver replied to doni49's topic in PHP Coding Help
your code and data doesn't produce that error for me. some of the possibilities would be - your actual code for the join(....) statement contains some characters that php doesn't recognize, but which appear normal after being put into the forum post (are you typing this code or copy/pasting it from somewhere where it could have been 'published' with some non-ascii character encoding?), the data itself or the point where you are displaying the debugging output contains or is in some html markup that's hiding what is really going on (what does the 'view source' in your browser show for that output?) or the code being posted or the line number being mentioned in the error doesn't actually correspond to what the code really is (this usually happens when you have multiple versions of code and the wrong one is being executed or you have multiple statements and the one producing the error is different from the one you are looking at/posting for us to look at.) you are basically asking someone to look at the tail ass end (symptom) of an animal and describe what the head (cause) looks like. this just results in a bunch of guessing and the problem could likely be a more obscure 4th or 5th thing that i didn't even mention. it's not that i/we don't trust you, it's that we have seen every possible combination of output and stated symptoms that don't tell the full story of what the code or result actually is. what is your full code from the point of the sql query statement up through where the current error is being reported at and are you outputting any html prior to this code that could be hiding some of the output? -
Help with Error Msg: Cannot use string offset as an array
mac_gyver replied to doni49's topic in PHP Coding Help
no one asked what it is being used for. -
Help with Error Msg: Cannot use string offset as an array
mac_gyver replied to doni49's topic in PHP Coding Help
what is $values being created as? the error means it is being assigned a string value at some point. -
you would strip the currency symbol from the submitted form data, in the php code. i hope you are only using this as a learning tool for inserting form data into a database table? this example code is not how you would do this work-flow in real life. it is only a demonstration of some css and javascript tricks and mixes editable form design elements and form data elements. if you were doing this for real, the form design elements (logo, company information...) would be created/edited and persistently stored somewhere and could not be changed by the person adding items to the invoice. if you are creating an invoice for a new customer, you would first add the customer information to `customer` db table. to create a new invoice for a customer, you would select the customer from a list of customers from the `customer` db table. this would create a new entry in an `invoice` db table. only the customer_id would be stored in the invoice table and would be used to retrieve the customer information from the `customer` db table to display it on the invoice. adding an entry to the `invoice` db table would assign the invoice number/invoice_id for this invoice. you would then select/enter items for the invoice. these items would be stored in an `invoice_details` table and be related to the invoice they belong to using the invoice_id.
-
if your Inmate class is DEPENDENT on using a database class, you should use dependency injection (a web search will explain what that means) to get the instance of the pdo database class into your Inmate class. usually, you would supply the instance of the pdo database class as a call time parameter when you initiate the Inmate class. you would store the instance of the pdo database class in a property in your Inmate class and reference it within the class wherever it is need. why are you passing an empty array as input into your Inmate class when you initiate it, but are not using that array in the constructor method code? this is not how classes are used. when you create an instance of a class, you reference the class methods and class properties of that class. any input data from the calling code would be passed into a method as a call time parameter and any output data back to the calling code would be returned from a method.
-
here's another issue with the database design and this code. user/customer information, like first and last names, should be stored in a users/customers table. it should not be stored in tables holding purchase_orders and service_orders data. any rows in the purchase_orders and service_orders tables should be related back to the user/customer data using an id.
-
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.
-
STR_TO_DATE() would be used in a single UPDATE query to take any formatted date and produce a mysql date type.
-
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.
-
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, ...
-
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.
-
Populating Bootstrap theme from database
mac_gyver replied to SalientAnimal's topic in Third Party Scripts
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. -
Populating Bootstrap theme from database
mac_gyver replied to SalientAnimal's topic in Third Party Scripts
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... -
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.
-
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>";
-
Populating Bootstrap theme from database
mac_gyver replied to SalientAnimal's topic in Third Party Scripts
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"> -
- 4 replies
-
- query string
- http_build_query
-
(and 1 more)
Tagged with:
-
Problem Creating MySQL Event using PHP
mac_gyver replied to chrisrulez001's topic in PHP Coding Help
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.