Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. care to share what those errors were so that we don't have to guess? we don't have the ability to run your code with your data, so you must share what you know about a problem in order to help those that would take the time to try and help you with your code problems.
  2. you need an indication of the value being returned by the mail() function. for the time being, forget about redirecting all over the place. start with something like - if ($success){ echo "the mail statement returned a TRUE value"; } else{ echo "the mail statement returned a FALSE value"; } i looked at the hostgator faq concerning php/sendmail and apparently the mail() statement can be used to send email through their mail server, though i wouldn't use their example code, it's just more crap php code that's been posted on the web.
  3. what result are you getting in the browser, the contactthanks.php page or the error.htm page?
  4. no, it's not passing anything from js to php. the two php variables contain those literal strings - <script>document.write(winW)</script> and <script>document.write(winH)</script>. when you are echoing those php variables in the page that gets output to the browser, at that point there will be the - <script>document.write(winW)</script> and <script>document.write(winH)</script> code. when this code is executed in the browser they do display what you expect, because the browser is where the winW and winH variables exist. to send ANYTHING from the browser to php, you must make a http request to the server and pass the values in the http request. see the following example in the php.net documentation - http://php.net/manual/en/faq.html.php#faq.html.javascript-variable
  5. you should only have one instance of the login code on any site. what you are describing you want to do is react to a problem by cleaning up a mess in it after the fact. programming is a proactive process, not a reactive one.
  6. in addition to what Psycho stated, your error handling needs to produce a user error message - tell the user specifically what they did that didn't work, if it's something they can correct (missing data, incorrect formated data, username/email already in use...) or output a generic failure message if the problem is an error in the application (database query errors...) and generate an application error message that contains the exact information about who, what, when, where, and why something failed, that you log on a live server and display when developing/debugging your code. if you use trigger_error() to handle the application error message, it makes use of php's error_reporting/display_errors/log_errors settings so you can control what happens with the message by altering the same settings that control what happens with php detected errors. edit: here's probably what the vague failure message is due to. the following, being used after several of the queries, is mistaken logic - if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure } a false $result i.e. the !$result, means that the query failed due to an error of some kind, a connection error, a problem with the sql syntax, a problem with the table/columns... only the mysql_numrows() value means that the query didn't match any rows. those two different conditions need to be handled separately as they mean something different.
  7. what have you tried? because the fun part of programming is in actually seeing code that you wrote produce the result that you want.
  8. your symptom of a user being able to log in (or perhaps it means they are already logged in when visiting the login page) without needing to go through the email activation step sounds like the email address was already present and activated from previous testing. are you deleting the row(s) from your database table and logging out between tests? are you sure your registration code that's checking if an email address/username is already present is actually doing what you expect? what is the full registration code? is your login code checking that the visitor is NOT already logged in before allowing them to log in again? the code you have posted has at least one header() redirect that doesn't have an exit/die statement after it. if you have code later in the same file that's doing something with the database table, that could account for the symptom. other than that, there's nothing in the snippets of posted code that would allow what you are stating as a symptom. and while this has nothing to do with the problem, why are you looping over the result from your queries. for a query that will at most match only one row, just fetch the row.
  9. the mysql syntax error is most likely due to the ( ) around the column = 'value' term. to build the terms in an array, instead of concatenating them with the sql, you would store them in an array - $terms = array(); // define/initialize the array before you use it // at the point of producing one of the column='value' terms - $terms[] = "assigned_id = {$p_assg}"; // store the term (you would want to do this dynamically in a loop rather than write out each logic test.) // at the end of the section of code, test if the array holds anything to operate on - if(!empty($terms)){ // there's at least one term in the array $term = implode(',',$terms); // note: this works even if there is only one entry in the array - you just get that one entry without the ',' // your code to form and run the sql query would go here, since if there's no column='value' term, there's nothing to update }
  10. this seems to be a common task. you have far too many queries and too much code. you need to separate the concerns by first retrieving the data and storing it in php array variable(s), then loop over that data to produce the output. you can then troubleshoot each concern separately. separating the different concerns also groups the database specific statements together so that if you need to change the type of database server, you can do it all in one place without needing to touch the code that's responsible for producing the output. see the following example - // simulated data from one query for whatever range of branch names and range of dates you have chosen in the implied query // use ORDER BY BRANCH in the query to get the branch names in the order that you want in the final result $rows[] = array('branch'=>'b1','date'=>'2015-08-02','sales'=>'1000110.00'); $rows[] = array('branch'=>'b1','date'=>'2015-08-03','sales'=>'1189015.00'); $rows[] = array('branch'=>'b1','date'=>'2015-08-04','sales'=>'1902110.00'); $rows[] = array('branch'=>'b1','date'=>'2015-08-05','sales'=>'1000122.00'); $rows[] = array('branch'=>'b2','date'=>'2015-08-02','sales'=>'2002110.00'); $rows[] = array('branch'=>'b2','date'=>'2015-08-03','sales'=>'1701110.00'); $rows[] = array('branch'=>'b2','date'=>'2015-08-04','sales'=>'2980110.00'); $rows[] = array('branch'=>'b3','date'=>'2015-08-02','sales'=>'1597110.00'); $rows[] = array('branch'=>'b3','date'=>'2015-08-03','sales'=>'2201110.00'); /* i would loop over the result from your database query and produce two arrays. the first array gets all the dates. the second multi-dimensional array holds the data, using the branch as the index for the first dimension, the date as the index for the second dimension, and the sales as the stored data value. */ $dates = array(); // all the dates. this, with the array_unique() statement, accomplishes the same as the DISTINCT date query, without the query $data = array(); // the data, with branch and date as the index foreach($rows as $row){ $dates[] = $row['date']; // you could test if a date isn't already in the array, but using array_unique, once, after the loop will be faster $data[$row['branch']][$row['date']] = $row['sales']; } /* use array_unique() on the first array, then sort that resulting array. this will produce an array of unique dates in ascending order for producing the heading and for accessing the data under those headings. */ $dates = array_unique($dates); sort($dates); /* to produce the result, loop over the second array's first dimension (branch), outputting the branch name as the label for the row. then, loop over the first array, and use each date to access the data, if any, for the current branch for that date. if there isn't a value, output whatever indication you want (0, ----, n/a, blank). if there is a value, output the value. repeat for all branches being looped over. */ $no_data = 'n/a'; // what to display when there is no data for a column $date_format = 'n/j/Y'; // format for displaying dates $currency = '$'; // symbol for currency $content = "<table><tr><th>BRANCH/DATE</th>"; // produce heading foreach($dates as $date){ $dt = new DateTime($date); $df = $dt->format($date_format); $content .= "<th>$df</th>"; } $content .= "<th>TOTAL</th></tr>"; // produce data section foreach($data as $branch=>$arr){ $content .= "<tr><th>$branch</th>"; foreach($dates as $date){ $value = isset($arr[$date]) ? $currency.number_format((double)$arr[$date],2) : $no_data; // handle what to show in the cells with no data $content .= "<td>$value</td>"; } $total = array_sum($arr); $content .= "<td>$currency".number_format($total,2)."</td></tr>"; } $content .= "</table>"; echo $content; your task to make this work with your database would just be to form and run the one query that retrieves the data you want and store it in an array named $rows. you would also need to style the output the way you want it.
  11. if you post the error, someone can help you find what's causing it. you can greatly simplify the code that's building the sql query statement by storing the column = 'value' pairs in an array, then simply implode the array with a comma between the elements. also, you don't need to check if values where changed or not in your code. update queries do this for you. they read the row of data and check if the values are the same. if they are, the update query skips actually updating/storing the data back to the disk.
  12. the error ultimately means that the SELECT query on line 176 in functions_global.php failed due to an error of some kind and there is no result set to fetch anything from. the error handling logic in this code is nonsense. it doesn't handle anything. if there is a database error, you would output a user message alerting the user that the page isn't working at all, and when developing/debugging, you would display the actual error information and on a live server you would log the actual error information. you would also prevent the remainder of the code that's depended on the database working, from running so that the code doesn't throw more errors. the error you are seeing is a follow-on error because the code didn't prevent the fetch method from trying to run after a query error occurred. the error you got isn't where the actual problem is at. i would change the class_db_handle.php error_handler() method to use trigger_error() to display/log the actual error information and then die() with a final user error message that the 'page isn't working at this time'. trigger_error() uses php's error_reporting/display_errors/log_errors settings. error_reporting should ALWAYS be set to E_ALL and when developing/debugging code, display_errors should be ON and on a live server, display_errors should be OFF and log_errors should be ON.
  13. also, the form that's being produced by the code in this thread doesn't have the ability to insert new items to the cart. it is only adjusting quantities. it only needs to update non-zero quantities and delete any row(s) with a quantity of zero. and the biggest reason why the updating of the quantities isn't working as expected is because your form is foobar. you need to decide if you are going to have one form that updates all the quantities at once or have individual forms for each item in the cart and update the quantity for just that item when the quantity gets changed in the form field.
  14. rather than to try and MAKE your existing code do what you want, i would just take the list of sections from the linked to post and define what you have and what you want to do for each section (which would become comments in the code). when you get to the point of creating the code for each of those sections, you can reuse some of your existing code. this is the list of those sections, with some specific comments relative to what you are doing - initialization - your head.php file is apparently part of the html page markup? if so, you should require it in the html page/template section. start of database dependent code - you should switch to the PDO api to replace the mysql_ functions. it is more consistent and it is easier to use exceptions with to handle all the database errors than the msyqli_ api. determine user state and permissions - the userid you reference in the code should be from a session variable. there's a comment in your code about it being from a cookie. you should NOT use a cookie to store the user's id. since your code REQUIRES a userid to work, you should make sure there's an id before running any of the code that's dependent on the id value. post method form processing - your form should use method='post' since you are changing data on the server. get requests should be used to control what to display on a page, not to change data. get method business logic - this is the code that retrieves just the data to display the cart. it's the sql statement, running the query, and fetching any/all the rows into a php array variable. end of database dependent code - no comment beyond what is mentioned at the linked to post. get method presentation logic - since you are calculating tax, shipping, and totals (which you can probably do most of in the data retrieval query), you would perform those calculations in this section while you are looping over the contents of the cart and producing the output in a php variable(s). i see that you are using htmlspecialchars() on some values being used in queries and in calculations. htmlspecialchars() is an output function. you use it at the point where you are producing output that goes to the browser. it actually has no effect on the numbers you are using it on and is just cluttering up the code where it is being used that doesn't have anything to do with output to the browser. you are also running a query inside of a loop. you should instead JOIN the postage table in with the cart data retrieval query. html page/template - no comment beyond what is mentioned at the linked to post.
  15. i'm surprised you are still trying to get this code to work. you could have completely rewritten it by now and gotten it to do what you want. even ignoring that your programming editor is using line endings that are non-standard, resulting in the forum software adding over 600 blank lines that we have to wade through, this code is disorganized to the the point that i cannot even determine where to look to find what may be causing the symptom you are asking about and it's so disorganized that you cannot troubleshoot it or isolate just the relevant part to post for us to consider. you need to organize and separate the different concerns in the code, this will make it easier to write, change, or debug. see the following post for a layout suggestion - http://forums.phpfreaks.com/topic/297824-database-issues-and-working/?do=findComment&comment=1519095 in addition to just the organization of the code, here are some specific things i see in the code that either won't work or are contrary to good programming - 1) you are using a get method form to alter data on the server. a post method form should be used (you even have two nested <form> tags, which are invalid and the inner one is using method='post', which has no effect, because the first <form tag with method='get' wins.) 2) htmlentities() is an output function, not an input function. using it on the input data isn't going to protect against sql injection. you need to properly escape/case input data or use prepared queries to protect against sql injection. 3) you have some variables - $HTTP_REFERER and $userID that unless you are using an old version of php, these don't exist, which may be the cause of the symptom you are asking about. 4) your database statements don't have any error checking logic and the msyql_ database statements are obsolete and will be removed from php fairly soon. 5) your queries for inserting/updating the rows in the basket should be replaced with a single INSERT ... ON DUPLICATE KEY UPDATE query. there's no need to first try to select a row, then either insert or update the row. just run a single INSERT ... ON DUPLICATE KEY UPDATE query. with the appropriate index set up, it will insert a row if it doesn't exist or update it if it does. 6) item #5 would also apply to your 'shopper' table, which i'm guessing is an order table? if the information in the 'shopper' table is just derived information, you shouldn't have the table at all.
  16. what makes you think that the php source code in a .php file would be accessible?
  17. this is exactly the same as what your last thread was about. if the query runs without any errors, the mysqli_query() statement returns a result resource that you use to access the result of the query (fetch data, check the number of rows...) not matching a row is not an error, it's an empty result set (no rows.) the mysqii_query() statement returns a false value only if the query failed due to an error of some kind, usually something wrong with the sql statement, the database, or the database connection. the php error message you are getting about the parameter you are passing to the mysqli_num_rows() function not being of an expected value supersedes the value the mysqli_num_rows() function is designed to return. if you are passing garbage into the function, you get garbage out. your code needs to test if each query runs or fails before you can use the result from the query. this is not just a debugging step when you have a problem. you must always do this. if the query has failed, you need to use the error information from php/mysql to find out why and fix the problem and you should stop the code from running any further statements that are dependent on the result of the query, since there isn't any. the error you are getting in this thread is a follow-on error due to a problem earlier in the code. it's not where the problem is at.
  18. there's no need to do an update query at all. you don't need to store the location in your equipment table, because you know the location from the location table. you are just duplicating data that you can easily find by running a query that JOINs the two tables.
  19. your post contains absolutely no information upon which to help you find what's wrong with what you are doing. you got an answer that was equally useful (42 is the Answer to the Ultimate Question of Life, the Universe, and Everything from the The Hitchhiker's Guide to the Galaxy.) the only thing anyone can determine from your post is that the problem is somewhere in what you are doing. care to show us your query and code that reproduces the problem so that someone could tell you if the problem is in your database query, in the php code retrieving the data from the database query, or in the html that's being produced?
  20. the answer is 42
  21. the four biggest problems with the code are - 1) you have stored same meaning data in two separate tables, one for members and one for clients, which you are querying for but not using. 2) you are retrieving all the data, not just the data being displayed. you are outputting all the data to the client for it to handle. 3) you are running multiple queries inside of a loop. 4) some of your data is not stored correctly, requiring you to do a substr_replace() on it every time you use it. items #2 and #3 are the cause of your performance problem. you should only retrieve the data you are currently displaying and i'm betting that all those queries can be replaced with a single query.
  22. in order to fix a problem, you must first find the cause of the problem. if you had a noticeable change in the page generation/loading time as the number of data items increased, your code is doing something extremely inefficient and it may be that caching cannot be used due to the nature of the data or won't have any effect on the problem. if you want someone here to help find the cause of the problem and make suggestions that would help, you will need to post enough of your code and some sample data that demonstrates and reproduces the problem.
  23. @Sedona, you need to be careful when posting the debugging output you are getting. it contains cookie values that will allow anyone to visit your site and impersonate you. I reported the two previous posts in this thread that contain those values and they were hidden/removed. Now you have posted two more sets of cookie values for someone to use. this header is indicative of going through a proxy server, either where the client is at or the web server is behind a proxy where it is hosted. either of these, or even a .htaccess file could be causing this, but i doubt it would be dependent on there being a completely specified http url or not in the posted data. if that's your whole form processing code in post #31, there's nothing in it that could be causing this, aside from the fact that it isn't bothering to test if a from was submitted at all. you didn't post your form/the whole client-side code.. i'm guessing you have some client-side validation that could be causing this, only when it finds something that starts with a completely specified http url? i also don't see where you are logging the information that scootstah gave you code to do.
  24. validation of the form data and using the form data are two different concerns and have to be separated. you have to validate the form data first, then use the resulting error information to determine what the rest of the code should do. if you use an array to hold your validation errors, your logic will be easier to write. create an array to hold the errors - $errors = array(); to added errors to the array - $errors[] = "some validation error message"; to test if there are not or are errors at any point in your program flow - if(empty($errors)){} - no errors or - if(!empty($errors)){} - there are errors.
  25. i'm going to guess this is a symptom of a page getting requested twice/redirected back to, combined with php's output_buffering being on to hide things (thanks php), and the second request doesn't have any post data and you are only seeing the output from the second/last request. to start with, the php code you posted isn't even checking if a form was submitted, so any time the page gets requested, it will run that code. if the page was requested with a get request, $_POST will be empty and you will get an empty value inserted into your database table and your "New record created successfully" message will be output. i'm not sure if the phpinfo() output you posted was supposed to be from the result of submitting the form with a valid url, but the REQUEST_METHOD showing in that output is GET. any chance that your page is doing a header() redirect back to itself based on some condition related to the url/non-url being submitted? it would take seeing all your code involved with this problem, less any database credentials, posted in the forum, for anyone else reading this thread to help. by sending code via pm, you are preventing anyone else, with a fresh set of eyes, from offering any specific help.
×
×
  • 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.