Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,519
  • Joined

  • Days Won

    187

Everything posted by mac_gyver

  1. then, i know of a third help forum, with two shorter threads for this problem, filled with replies listing what's wrong with the current randomly thrown together code, and what the code needs to be doing, with a working pdo example that matches the form data, that could have been followed, but wasn't. nor was the advice that was given that the OP needed to actually learn the meaning of what he is doing in order to successfully write any code. resulting in no one continuing to post replies. if the OP revisits this thread, you cannot program by mimicking things you have seen posted on the web. randomly putting pieces of code together will take an infinite amount of time to come up with code that does something. repeatedly asking someone else to look at your randomly changing 'moving target' of code will quickly loose the free help, because no one likes to see their volunteered time go to waste. you need to first go and learn the basics of the php language, so that you will know what an if(){} conditional statement, that encloses multiple statements, even looks like.
  2. one single query would look more like this - SELECT Count(l.lot_id) AS slab_count, WEEK (l.slab_date) AS week_number FROM lot l LEFT JOIN block AS b ON l.block_id = b.block_id LEFT JOIN community AS c ON b.community_id = c.community_id WHERE YEAR(l.slab_date) = 2015 AND (c.contract_type_id = 1 OR c.contract_type_id= 3) GROUP BY week_number however, i/we don't know what your rules are concerning how the dried_in_date should factor into the result. the query you showed doesn't produce the result you want, therefore it doesn't show us the correct rules for the value. the following is the same basic query as above without the GROUP BY - SELECT l.slab_date, WEEK (l.slab_date) AS week_number, l.dried_in_date, WEEK (l.dried_in_date) AS dry_week_number FROM lot l LEFT JOIN block AS b ON l.block_id = b.block_id LEFT JOIN community AS c ON b.community_id = c.community_id WHERE YEAR(l.slab_date) = 2015 AND (c.contract_type_id = 1 OR c.contract_type_id= 3) ORDER BY week_number it produces this result from your data - so, from that, how do you get your desired slab count of 2,1,2 for week 1,2,3?
  3. implode the array into a list, with a comma as the separator character, then use that comma separated list in an IN() comparison in a WHERE clause in your query. ref: http://php.net/implode http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#function_in are these values coming from external data and would need to be properly validated, cast, or put into a prepared query to prevent sql injection?
  4. neither the {} around the exit or () on the end of exit are required, nor does the lack of them throw a syntax error. since the error gives line 1 as where the problem is being detected at and there's no statement on line 1, either this isn't the actual code the error is referring to or there's something going on with the file's character encoding or a broken php installation that's causing the problem.
  5. your code contains two logic problems. 1) if(!$query) - this condition means that the query failed with an error of some kind (sql syntax error, wrong table or column name.) it does not mean that the username/password was invalid. your code should actually be using exceptions to handle database errors so that the main program logic only has to deal with the non-error conditions. 2) your code creates an instance of the user class in $_SESSION['user'] any time the User::sign_in() method gets called, regardless of the username/password matching anything. any request to the page after that will result in $_SESSION['user'] being set. your user class needs a property or method you can use in your code to determine the logged in state.
  6. is your code echoing the $output variable?
  7. each page request must actively enforce access security for the page. the "classroom sourcecode" would only be output, using php code, to a visitor if that visitor is logged in and has permission to access one instance of that content. you would only have one 'classroom' .php page. you would need a database table that holds the students that have been assigned to an instance of a classroom. for historical data reasons, you should keep any past records in the table and have a 'status' column that you can use to mark records with an 'active' status. if the limit is 5 students, you would need to insure that there are only 5 students listed as being active at one time. if it is the teacher(s) that assign a student to a classroom, a logged in teacher would need a way of picking from all the unassigned students and if there is an available instance of a classroom, can add a record to the database table with an active status, with the selected student's id. the table would also have a column with the teacher's id, used both to list the teacher and to limit who 'owns' the record and can alter the status column. one would assume that the same teacher (or an administrator) would have permission to remove a student from a classroom, by changing the status from active to some other value. this would free up one of the available classrooms. if a student is logged in and has a record in the database table with his id and an active status, when he visits the one single .php 'classroom' page, he will be able to view the content. any one who isn't logged in or doesn't have a record with an active status, would not be able to view the content. you would either just output a message or redirect them somewhere else.
  8. rather than just asking someone else which keys to push to fix a problem, how about debugging the problem yourself? between the forums that i know you post on, you have several hundred posts. at this point, you should be able to isolate a problem with your code and queries to at least the pin down where the problem is at and by looking at where the problem is at, you may be able to solve it yourself. is your query running or is it producing an error? do you have error checking and error handling logic in your code for the query? is your query running, but not matching any rows? do you have any logic in your code to test for this condition and output an appropriate result for the case of no matching rows?
  9. the problem is the above comparison in your for(){} loop. $max is the count of the items in the array. if there are 10 items in the array, $max will be 10, but the array indexes would be 0-9. you would want to use $x < $max; next, don't run queries inside of loops. this a performance killer. edit: run one JOINed query that gets the related data all at once. i would get a unique list of all the departure and arrival airports. then implode these into a comma separated list of quoted-string values, then use WHERE IATA IN(the list would go here) in ONE query to get all the lat/long values in one query. edit: also, if i read what you are doing correctly, you would need to get the lat/long for the final arrival airport. your current code is only getting the lat/long for the departure airports. see the related edit i also made in the above paragraph.
  10. this is a problem with the foreach($arr as $txn) loop and references. the $txn variable that the foreach loop creates is a new variable and any reference(s) when you ran the bind_param() statement no longer exists. your example is only looping over a single set of data. if you don't need to do this in a loop, don't. if you do need to do this in a loop, either 1) bind individually named variables, $payee, $date, , ..., then, inside the foreach(){} loop, assign each named element of $txn to the correct named variable, $payee = $txn['payee'];, ...or 2) bind elements of a differently named array, $temp['payee'], $temp['date'], ..., then, inside the foreach loop, assign each named element of $txn to the correct named element in $temp (you can actually use a second foreach loop to do this). if you use the $temp array method, you must assign each element individually inside the loop. you cannot simply do $temp = $txn; because this will end up referencing the last element in the $arr every time through the loop, if i remember correctly.
  11. you should have one set of users and one login. each user would have a role/type stored for him/her that would determine what they can do or see on any particular web page.
  12. any page must have code to enforce who may access it. the payment status data in a database table would need to be tied to the user who made the purchase through a user id. is your current code and query doing that? if your protected page requires a logged in user, who has purchased an item allowing access to that page, and the payment status for that user and item is 'Completed', your user access code on that page must test for all of these conditions.
  13. is there a chance that the date value contains some non-printing/white-space characters? what does using var_dump($txn['date']); show?
  14. must have been some other site, because i have reviewed the most recent page of threads you have started here and the results don't support your claim. i particularly reviewed a recent thread that i helped solve, where it turned out you were including files incorrectly. i also thoroughly read another thread where you were trying to roll your own base64 encryption/decryption and were insistent that someone not try to tell you to use a different offset with a string function, then a top forum member demonstrated that it was that string offset that was wrong. that you would get bent out of shape over someone advising you that there is a better, shorter, faster, correct way of doing something, indicates you need to show some flexibility in your approach to asking others to help you with programming that you cannot do yourself. you basically didn't get someone to jump and convert your pseudo code into real code for you and you think the problem is somewhere than where it is really at. the reason you may be only getting advice on what you should be doing, is because i/we/people in general would like to help you completely and correctly FIX a problem, not just patch it up so that it 'works', so that i/we/people in general don't have to see what you are doing keep showing up in forum threads when the next problem with it, just because of a bad design, needs solving.
  15. i/we could, but the db server gods wouldn't be happy. whatever you think you are gaining by storing your data this way, is lost by all the extra code it is taking to insert, update, delete, or find any of the piece(s) of data and all the time you have spent maintaining the database structure and code just because a new January 1st rolled around. a normalized design won't require any of this, because a new year is just a value changing in an existing column of data.
  16. this is a bad database design, that's treating the database table like it is a spreadsheet, resulting in a ton of code to manipulate or retrieve any piece of data, which is why you have to write two relatively slow operating functions just to retrieve any data. research 'database normalization' to find the correct way of storing data in a database table. each piece of data should be stored in a separate row in your database table and there should only be a row when there is a piece of data. if there is a year, date, or datetime value associated with each piece of data, the database table would have a column to hold the year, date, or datetime value. to query for data for a specific year, you would just query to find the row(s) with the year value you are interested in (the mysql YEAR() function would be used to get the year portion of a date or datetime value.) next, the mysql_ functions are obsolete and have been removed from the latest version of php. you should be using either the PDO or mysqli_ php api to access your database. the PDO api is more constant and easier to use.
  17. your concatenation probably didn't work due to the semi-colons ;. those only go on the end of php statements. when not within a quoted string, the first semi-colon that was encountered was telling php that was the end of the statement. everything following that probably didn't make any sense to php and it was throwing a syntax error. to put the object method calls in the string, you would need to put { } around each object method call so that php can figure out what part is the reference to the object. you would also remove the semi-colons, unless you literally want the ; character to be in the output.
  18. because the navigation's active state and the content's display state is controlled by javascript, just adding a bookmark/anchor on the end of the url doesn't cause the client side code to 'work'. it does cause the browser to go to the correct place on the page (which is hidden in all but the hard-coded 'active' tab), but it does nothing to select the corresponding navigation tab or display the correct content. here's why this won't work without extra code - https://github.com/twbs/bootstrap/issues/2415 and a client-centric solution, if you don't like the server-centric one - https://github.com/timabell/jquery-stickytabs
  19. because the initial active pill/tab navigation and content is hard-coded into the markup, any request/redirect for the page will always go back to that specific navigation selection and content. from a server-centric standpoint, you would need to dynamically output the class="active" selector in the correct navigation and add the 'in active' keywords to the class selector for the correct content section in order to achieve this.
  20. do these images work correctly when your chat code displays them by retrieving the 'pprofilepic' value and producing an <img link? are you sure that the images exist and haven't already been removed? relative paths are relative to the current working directory. what does adding the the following to the script show - echo getcwd(); echo '<br>'; echo __FILE__; also, please browse to one of these images and post the URL for us to see. if you don't want to post your domain name, xxxx it out, but don't change anything that's after the domain name. you could always form an absolute path, starting with '/home/zhetnsdd/public_html/chat2/profile/' and concatenate the 'pprofilepic' value it. if you are going to run this script via a cron job (you are apparently browsing to it now), i'm not sure what the correct env variable would be to build that dynamically.
  21. without having all the code that REPRODUCES the problem all we can do is make guesses. some possibilities - 1) output buffering is on in the php.ini and any output you are sending from the php code is being discarded because you are doing a header(), session_start(), or setcookie() statement after the code you have posted. 2) your page is being requested twice, perhaps once by javascript and a second time by the browser, and the result you are seeing is from the second page request. if you care to post enough of your code that reproduces the problem, less any database credentials, someone could actually find what's causing the problem. edit: also, since you are determining what will be displayed on the page, you should be making a get request, not a post request.
  22. after you figure out if you are going to use prepared queries or not, forget about the INSERT ... ON DUPLICATE part of a single query that i mentioned. you already have the data inserted and an id assigned that corresponds to what is being viewed, you would just use a single UPDATE query. the following code and query will both update the view count by one and retrieve and echo the updated count value - $query = "UPDATE ".$cg->dbprefix."hdflv_upload SET times_viewed = LAST_INSERT_ID(times_viewed+1) WHERE id = ?"; // use a bound parameter in a prepared query for the $idpos value // mysqli prepared query $stmt = $con->prepare($query); $stmt->bind_param("i", $idpos); $stmt->execute(); $addone = mysqli_insert_id($con); // retrieve the updated times_viewed value echo $addone;
  23. because this value is not a string and is not being treated as a string in the sql statement, using any escape string function on it does NOT protect against sql injection. you can inject sql using a hexadecimal value (that encodes some sql syntax) that contains no sql special characters, that the escape string function has no affect on, and mysql will happily convert the hexadecimal value back to the original encoded string. this is made worse by the posted code because is_numeric() allows a hexadecimal value. you need to either validate/cast each value as the CORRECT data type that it is or use prepared sql queries. if the $idpos is expected to be an integer, you must validate/cast it as ONLY an integer value. unfortunately, using any php code that treats the value as an integer will limit the value to php's maximum integer value, which varies depending on the bit length supported on your hardware/operating system. making sure the value only contains numeric characters, see ctype_digit(), will at least limit it to an integer value, including zero. as has already been posted, using PDO for prepared sql queries is more consistent and simpler than using msyqli_ for prepared queries. also, you don't need to SELECT data in order to UPDATE it and in fact there's a race condition present where you will loose counts when there are multiple concurrent instances of your code running. you should be using one INSERT ... ON DUPLICATE KEY UPDATE ... query to do this.
  24. this is a very common error. if you search the web for it, you will get several million results that tell you what causes it and how to fix what is causing it. you cannot send any (1 or more) character to the browser before you use a header(), session_start(), of setcookie() statement. ALL THE HTML MARKUP you have before the header() statement are characters and cannot be sent to the browser. the way to fix this is to refactor your code and move the majority of your php code to the top of your file and put ALL the html document, starting with the <!DOCTYPE tag near the end of your file. the only php code that should be inside the html document as basic php statements that are concerned with displaying the dynamic portion of the html document. logging a user is has nothing to do with the html document. if you read the following post for a recommend page layout to follow, your code won't have this problem, because processing post method form data will be near the top of your file and the html document/template will be at the end - http://forums.phpfreaks.com/topic/297824-database-issues-and-working/?do=findComment&comment=1519095
  25. since you didn't post your script that's dynamically adding the repeat regions, when i tested i used a method that caused the dynamically added regions to work. which is why someone has suggested twice in this thread that you need to post the relevant code that reproduces a problem. unless you are calling your product1() function after you dynamically add a region, the current problem is mostly likely this - $('.form-control.products1').change(function () {. this won't add the change event to any classes that are created after that bit of javascript runs. change that line to the following to get the event to work for all the product select/option menus that exist in the document - $(document).on('change', '.form-control.products1' , function() {
×
×
  • 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.