-
Posts
5,537 -
Joined
-
Days Won
192
Everything posted by mac_gyver
-
in addition to needing a basic understanding of the php language before you try to use it to do anything, the biggest thing that helps with programming is to define what you are trying to do, before you try to write the code for it. trying to write code or modify existing code (which would also apply to code snippets you find or are given) without a clear definition of what end result you are trying to produce, just wastes a lot of time. so, what are you trying to do, 1) a form with inputs for city/state, and 2) form processing code that takes the submitted city/state values, retrieves the matching information, if any, from the database table, and displays the results in a particular format. you would then break down each of those main tasks into smaller and smaller steps, until you can finally write the code that accomplishes each step. for the form processing code, those steps would be - 1) create a database connection, handling any connection errors, and as has been recommend, set the error mode to exceptions so that all the rest of the database statements will throw exceptions that you can catch and handle in one place. 2) check that a form was submitted - you were shown/given a method='post' form. however, this form is controlling what will be displayed. it should use method='get'. post method forms are for changing data on the server. 3) condition/filter/validate the submitted form data. 4) if there were no validation errors, use the submitted data in a database query. 4.1) form and run the sql statement for a SELECT query with a WHERE clause that will use the submitted city/state values, using place-holders for the input parameters. 4.2) prepare the query. 4.3) bind the input parameters to the place-holders in the sql statement. 4.4) execute the query. 5) retrieve the data that the query matched, if any. since your assignment mentions using a foreach() loop, the intent would be to fetch all the rows that the query matched into an array, then use the foreach() loop to loop over that array. 6) output the data, if any, in that particular format. if there is no matching data, output a message stating so. this list of steps that you have defined will become comments in the code that you will write. give me a couple of minutes and i may (no promises) post an example using pdo to do this.
-
if you are not even sure that a $ starts a variable (programming is not about guessing or assuming, it is an exact science), you need to start with the basics. i would recommend that you read (so that you can internalize the information) at least the Getting Started and Language Reference (which covers variable naming) sections of the php.net documentation. php.net supplies the documentation in several forms, both on-line and down-loadable. i find the down-loadable .chm file particularly useful since it has a search-able index and in the cases where the index doesn't find what you want, you can use the search tab. next, if you have a question to post on the forum, limit yourself to just the relevant verbiage. we can only give an answer when we know of a specific question. just telling us you don't know what something means isn't specific enough. you must tell us what exactly you don't understand, because we are not providing free tutoring services. we are providing direction and sharing programming knowledge.
-
you would loop over - $myArray['query']['results']['quote'] and then reference the ['close'] element. the following (untested) should work - foreach($myArray['query']['results']['quote'] as $arr){ echo $arr['Close']; } if you want to display a day number/counter, initialize a php variable before the start of the loop, echo and increment it inside the loop to provide the day number.
-
you should have been getting php errors from your code. having php's errors turned on is critical for debugging problems. if you still are not seeing any php errors, after deliberately introducing problems into your code, the settings for error_reporting/display_errors may be commented out or are using invalid (false values) settings. if you need help with the error settings, post the actual lines for them from your php.ini file.
-
switching to a different database api requires that you learn enough about the statements you are using, so that you can apply them to your own code. the PDO database api is the best and most consistent choice as a replacement for the mysql_ statements. the best place to start learning about any of the php statements is the php.net documentation. there are usually workable code examples in the documentation. next, your database table design is bad. databases are not spread-sheets. laying out a table with a sequence of name/numbered columns makes for a lot of extra code and queries to create, find/display, update, or delete any of the data. there should be one row for each separate data item in a database table.
-
there's no guarantee of what php.ini php is using. to find the php.ini that php is using, create a .php script file with the code - <?php phpinfo(); ?> in it and browse to the url of the file. the Loaded Configuration File line in the output is the php.ini that php is using.
-
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? the most likely problem is that the mysql_ extension is not installed/enabled in your php configuration. next, the mysql_ functions are obsolete and will be removed from php soon. you should be using the PDO (the best option as it has a more consistent interface) or mysqli_ database functions in your php code. the php version you are using will be throwing a php error at the mysql_connect() statement to alert you about this. lastly, the mysql_ functions don't have an OOP style interface, so there is no ->connect_error properly at all to test. this in itself should be throwing a php error.
-
there are three (or more) possibilities - 1) you actually have two rows in your database table (did you refresh the display of the information to make sure?) 2) the code you have shown us is inside of a loop of some kind. 3) you have managed to store that string of data into two of the database fields, with the rest of the fields empty.
-
for debugging purposes, you can make a test page with a form that submits some dummy post data to your ipn.php script so that you can SEE what your script is doing. you would also temporarily set php's error_reporting to E_ALL and display_errors to ON in your ipn.php code. doing this will run your code and let you see any php errors (i suspect you may have a permission problem with the log file) and let you see if the curl statements are producing errors. this will at least get you to the point of having an "INVALID" response back from paypal and getting the error logging to work, since the dummy post data won't match a real transaction. you can also use this test method and 'fake' a "VERIFIED" response in your logic to let you test and debug your database code.
-
that's more than a couple of errors. a couple of errors would be 2 - did you look at and try to find why your code is producing any of those errors? and given that cyberRobot told you the reason for one of them, why didn't you at least fix that one? with your 60 posts and 2+ months on this forum, you should be at the point, after just a couple (2) or a few (3-4) weeks, of being able to find and fix simple things like undefined variables and undefined indexes in posted form data. in one of your previous threads, someone suggested a code layout for your page. this was primarily to add origination to your code, but it was also to help make your code foolproof, so that you won't have undefined variables that are dependent on either a query retrieving the variables or a form submission supplying the same variables. there was in fact a comment in code in that thread that read -
-
when paypal makes a http request to your ipn php page, the only input will be the $_POST data. there will be no $_SESSION data, because the request isn't coming from the visitor. your ipn script must also go through a data verification process with the paypal server to insure that the ipn request actually came from paypal. i recommend that you research the ipn documentation and search the web for existing ipn php scripts to see how they are coded.
-
easier version - $file = 'formdata.log'; $data = date('Y-m-d H:i:s')." Agent:$_SERVER['HTTP_USER_AGENT']\nPost:".print_r($_POST,true)."\n"; file_put_contents($file,$data,FILE_APPEND);
-
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.
-
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.
-
what result are you getting in the browser, the contactthanks.php page or the error.htm page?
-
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
-
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.
-
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.
-
what have you tried? because the fun part of programming is in actually seeing code that you wrote produce the result that you want.
-
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.
-
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 }
-
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.
-
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.
-
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.
-
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.