-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
you have far too much code, making it hard for you and us to see what the code is supposed to be doing. just some of the problems are - 1) you have several places where you are using data that may not even exist, which will result in errors or incorrect output when it doesn't. if code requires an input value, all the code dependent on that input should only be executed if the input is present. 2) your login check isn't stopping program execution when the visitor isn't logged in. all the code is still running for a non-logged in visitor. 3) you are running queries inside of loops. this is a performance killer. 4) looping over query data where there will be at most one row. this just adds clutter to the code. 5) not using each set of the retrieved data inside of loops. this will typically result in only the last set of data being used after the end of the loop. 6) you have all kinds of variables that you are producing but don't use at all. i recommend laying out the code on your page with the different concerns separated. see the following code layout that will help you do this - http://forums.phpfreaks.com/topic/297824-database-issues-and-working/?do=findComment&comment=1519095 the biggest help will come through separating the get method business logic from the get method presentation logic. this will group all the database dependent code together, allowing you or us to see just what the query/data portion of the code is doing so that it can be simplified.
-
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? do you have the PDO error mode set to exceptions so that any PDO statement that throws an error would cause an exception so that your main code only has to deal with error free execution of the PDO statements?
-
there's something faulty with your method of learning and programming. you have hundreds and hundreds of forum posts around the web, yet, you don't seem to have learned any of the methods that are being used, that would allow you create (or debug problems with) your own code. each of your posts are missing basic 'how to' building block information that you should have learned along the way. it doesn't even appear like you understand what each of your files are trying to accomplish. if you did, you wouldn't have changed the query in the code that's building the select/option menu. a large amount of generalization, continuity, and consistence is required in programming. you need find a different approach that will allow you to learn the meaning of what you are doing, so that anything you learn can be reused the next time you do something similar.
-
your code doesn't have anything in it to just send to one selected phone number. you are querying for and looping over all the `repairs` db table data in the second piece of code. 1) your select/option menu should use the id as the value that will be submitted. not the customer phone number. this will make it easier to validate the submitted data. 2) you would use the submitted id to query for the actual phone number, then retrieve just that single row to get the phone number. 3) why are you even looping in the second piece of code? 4) do you have any security in place to control who can access either of the two pages you have shown? as it stands now, anyone who can visit these pages can cause a message to be sent to any phone number stored in your data. are you even looking at your code? the computer can only do what the code you write tells it to do. if you are querying for the wrong data, in this case all the data, and looping over data, when you should be fetching at most one row, that's on you.
-
someone, or a bot script, probably gained access to your account., especially if you used a common or weak password or you use the same password everywhere on the web and an account that didn't properly hash the stored passwords has been compromised. there are other possibilities, such as someone managing to reset your password, which would allow them to gain access to your account, but if you were able to log in to your account using your existing password without any problems, that isn't the case. or perhaps you have remained logged in since your last real activity on the forum and your computer/browser/network has been compromised and someone got the 'remember me' cookie value and was able to impersonate you on the forum.
-
php is a server-side scripting language. ALL THE PHP CODE YOU HAVE ON THE PAGE RUNS WHEN THE PAGE GETS REQUESTED. javascript is a client-side scripting language. by the time any of it runs, the php code has long since finished running. the ajax request would need to submit the form data to the url of a .php page that contains php code to call to the sendemailfn() function and then output the value returned from the function back to the client-side code as a response to the ajax request. since using ajax to submit form data to a php page is a common task, i recommend that you read through some web based tutorials to see how to do this.
-
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.
-
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?
-
Fetching table info based on array values
mac_gyver replied to lquidsilver's topic in PHP Coding Help
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? -
Parse error: syntax error, unexpected 'exit' (T_EXIT)
mac_gyver replied to chiranjiv's topic in PHP Coding Help
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. -
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.
-
is your code echoing the $output variable?
-
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.
-
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?
-
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.
-
Insert using prepared procedure puts bad data in the table
mac_gyver replied to doni49's topic in MySQL Help
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. -
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.
-
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.
-
Insert using prepared procedure puts bad data in the table
mac_gyver replied to doni49's topic in MySQL Help
is there a chance that the date value contains some non-printing/white-space characters? what does using var_dump($txn['date']); show? -
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.
-
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.
-
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.
-
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.
-
Help with redirecting to specific nav-pill on same page
mac_gyver replied to rodb's topic in PHP Coding Help
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 -
Help with redirecting to specific nav-pill on same page
mac_gyver replied to rodb's topic in PHP Coding Help
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.