Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. you have to use all sqlsrv_ functions. the mssql_ functions are obsolete and haven't been available on windows since php 5.3.
  2. the header('location: ...') is only telling the browser to make a http request for a page. if this is causing a new browser tab to open, there must be something somewhere else in the code on the page to cause it. this is not being caused by the header() statement. why do you have so much repetition in your code? this just makes for a lot of extra work for you, especially when you need to fix or change anything in the code. currently, you need to add protection against sql injection for all those queries, which there are actually only two different variations of a single query. by refactoring your code so that the sql query statement only exists once, adding sql protection, or changing anything about the query, would only have to be done in one place.
  3. your current database design will only work, using a JOIN query, if each username only has one row in the ca_processed (invoice) table, which would be useless in a real application. in this case, the username does become the value that relates any row(s) in the ca_my_payments table to the one correct row in the ca_processed table. you would however not use SUM(p.total_payment) to come up with the total_invoice amount as that would repeatedly add the amount for each JOINed row between the two tables. if you have more than one row for any username in the ca_processed table, you can use a UNION query to sum up all the invoice amounts and the payment amounts for each username, but i doubt that's your goal.
  4. your code that is executing the sql query statement is not inside the loop. it's after the end of the loop. therefore it is only executing the sql query statement that was formed in the last pass through the loop. wouldn't you have to execute the sql query statement inside the loop?
  5. you do realize that we have no idea what pre-built application you are trying to make work and cannot help you based on the information you are posting. i recommend that you contact the author of the script to get support for it.
  6. does your code use the ldap functions? if not, that error is not relevant.
  7. a JOIN is used when you have related data between the tables. an example would be a user table and your ca_processed table. a query to retrieve user information and his related row(s) from the ca_processed table would use a (LEFT) JOIN query. the user_id, defined in the user table, would be used in the ca_processed table to relate the user's rows in the ca_processed table to the user they belong to. your two tables don't have any defined relationship between them. if you have multiple rows in ca_processed for any username and multiple rows in ca_my_payments for the same username, you will get the result of every row for that username in the first table joined to every row for that username in the second table. if you had an invoice table (which i guess is what your ca_processed table is), that assigned an invoice_id to the invoiced amount and you stored row(s) in a payment table, related to the corresponding invoice using the invoice_id, you would use a (LEFT) JOIN query to get the amount of the invoice and any amounts paid toward that invoice because you now have a defined relationship between the data in the two tables. the reason i mentioned a user table in the example of a join query, is because you shouldn't have usernames/emails duplicated in these two tables. you should have the user information stored in only one place, then use the user_id in any tables holding information that's related to the user.
  8. your post contains no information upon which to help you. all you have done is told us that something doesn't produce the correct output. it would take knowing what conditions are required by the code and what the current values being tested actually are. what troubleshooting have you done to try to find the cause of the problem?
  9. yes, you should dynamically produce the form using the data from the database. a goal to keep in mind when programming, is to try to write general purpose, data driven, code. by storing the questions (which is just some content as far as the computer is concerned) in a database, the questions can be changed, added, and removed simply by changing the data. the code that retrieves and displays the data will remain the same. also, by storing the questions and any options in a database, this assigns identifiers to that information, that you would use when processing/validating and storing the answers (this is shown in the relationships between the tables in diagram that Barand gave.) this results in simpler code, more easy to secure code, the least amount of data storage requirements, and results in the fastest operating design.
  10. in addition to the above problems, you have a fundamental logic error in your code - if($tblnames == 'cryptokeys'){. $tblnames isn't the variable holding each table name inside the loop. see the following much simplified code that should (untested) work - <?php $pdo = new PDO( 'mysql:host=' . DB_HOST_R2D2 . ';dbname=' . DB_DATABASE_DNS, DB_USER_DNS, DB_PASSWORD ); //yoda pdo settings $pdoyd = new PDO( 'mysql:host=' . DB_HOST_YODA . ';dbname=' . DB_DATABASE_DNS, DB_USER_DNS, DB_PASSWORD ); $pdoyd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdoyd->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $tblnames = array('cryptokeys', 'domains', 'records'); // column names per each table $cols['records'] = array('id', 'name', 'type', 'content', 'ttl', 'prio', 'change_date', 'disabled', 'ordername', 'auth'); $cols['domains'] = array('id', 'name', 'master', 'last_check', 'type', 'notified_serial', 'account'); $cols['cryptokeys'] = array('id', 'domain_id', 'flags', 'active', 'content'); //loop through yoda and trunacate all 3 tables foreach($tblnames as $tbl){ echo $sql = 'truncate '.$tbl; echo '<br>'; $pdoyd->query($sql); } foreach($tblnames as $tbl){ echo $query = "INSERT IGNORE INTO $tbl (`".implode('`,`',$cols[$tbl])."`) VALUE (:".implode(',:',$cols[$tbl]).")"; echo '<br>'; $stmt = $pdoyd->prepare($query); $select_results = $pdo->query("SELECT * FROM ".$tbl); while ($row = $select_results->fetch(PDO::FETCH_ASSOC)) { $stmt->execute($row); } }
  11. you need to have php's error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. your sql query statements, at least the first INSERT statement, i stopped looking after that point, are throwing errors, which would result in uncaught exceptions for the posted code. at least the first INSERT statement doesn't contain a correct list of column names or place-holder names and will be throwing sql errors. there are other sql syntax errors in the queries as well. i also recommend that you form your sql query statements in php variables, so that you can echo them to see if the sql syntax is correct. to make the list of column names, you should implode() the array holding the column names, with a comma as the implode separator. you can make the list of place-holder names by using a ',:' as the implode separator. edit: also, when posting code on the forum, please use the forum's bbcode tags (the edit form's <> button) around code.
  12. the error about the header() ... states that some output was sent to the browser and on what line all or the end of that output was at, that's preventing the header() from working. you would need to find and fix what is causing that output.
  13. that stops the reporting of all errors. that should be - error_reporting(E_ALL);
  14. just to be clear, you are stating that with the echo 'Your roster has been updated ...'; statement in the code and the header() statement commented out, and you are sure the code you are showing us is is the correct and complete code that's being ran on the server, and the rank/crew type is not "Captain" and is not "First Officer", that all you get is a blank page? if so, what does the 'view source' of that blank page in your browser show? also, is there any chance that the blank page you end up on is frontend_login.php or some other page than the one you are showing us the code for? what is the $_SESSION['Code'] value for this case where it isn't working? if is seems like i/we are being skeptical, it's because the symptom you are stating is impossible for the posted code. so, either the code being posted isn't what is being ran or the symptom being reported isn't correct. there's actually a ton of stuff this code is doing that isn't needed and can be greatly simplified, but having nothing to do with the current problem.
  15. in order to successfully use the php mail() function (or any of the php functions), you must make use of the documentation for that function. you cannot simply make up, guess, or assume what to do. the mail() function takes at most 5 parameters. the first three parameters - to, subject, and message, are required. the 4th parameter, additional_headers, is generally required since most php installations don't have a default from email address set up or it isn't a valid email address for your account/domain. the 5th parameter, additional_parameters, is rarely used. your use of the mail() function would be throwing php errors about the number of parameters. when larning php, developing php code, or debugging php code, you should have php's error_reporting set to E_ALL and display_errors set to ON to get php to help you by reporting and displaying all the errors it detects. you would also want to temporarily comment out any header() redirects since php also has a setting that's turned on by default, that would prevent you from seeing anything your code or php outputs prior to the redirect. all of those variables, $name,$company,$tel,$address,$city, ... should be going into producing the message parameter, in the $message variable. lastly, these emails are NOT being sent from the person who is filling in the form data. they are being sent from the mail server at your web hosting. the From: mail header must be an email address with a domain that is directly tied to your web hosting or if the domain is not hosted at the same address as your mail server, you must have an SPF DNS record where the domain is hosted at, that says your sending mail server is authorized to send emails for that domain. in either case, you should have a proper SPF DNS record that the receiving mail server can use to verify that the sending mail server matches where the email says it is coming From:. you can put the entered name/email in a Reply-to: header, if you want the ability to hit the reply button in a mail client and use that name/email as the reply to address. if you are doing this for real, you must validate that all the external data is of the expected format and doesn't contain things like valid mail headers, in order to prevent mail header injection, particularly for any values you are putting into the additional_header parameter.
  16. so, that was a lie. someone took the time to ask you if the spelling and capitalization matched the column name. they didn't do that because they needed practice typing. that was asked because the spelling and capitalization must be correct for your code to work.
  17. then the most likely cause would be empty data in that column or data that looks like a html tag (has < > around it) so that it doesn't display anything. are you sure you have data in that column? could you have executed a query that cleared all the user names/set them to empty strings? what does the 'view source' of the output in your browser show?
  18. is your database column spelled and capitalized exactly as username ?
  19. your error message has changed, because the problem changed. the original error was due to fg_membersite.php, not membersite_config.php. in the first post, the require_once() for membersite_config.php was working. it was the require_once() for fg_membersite.php, inside of membersite_config.php, that wasn't working. the most immediate problem is now the path for membersite_config.php. all the folders in question are inside a folder named gesdocente. you either need to add the gesdocente folder to the absolute path you are making for all the require_once() statements OR you need to make the relative path using two .. for all the require_once() statements. edit: relative paths, anything that starts with a ./ or ../ are relative to the main file that was requested, because when you include/require code into your main file, its scope when it runs is the main file, not where it is stored at on the server.
  20. there are three other serious problems with your code - 1) the mysql_ functions are obsolete and have been removed from the latest php version. if you or your web host updates to the latest php version, your code will stop running at all and will need to be rewritten. to avoid wasting time learning obsolete methods that will have to be redo in the near future, you should be using either the PDO or mysqli_ database functions. PDO is the best choice, especially if using prepared queries. 2) your code has little to no protection against sql injection or of special sql characters in the data causing sql errors. the easiest and most constant way of protecting against these problems are to use prepared queries. 3) don't use the GLOBAL keyword to being data into a function. this breaks encapsulation and you might as well not be using functions. you should pass any data into a function as call time parameters.
  21. using a unique composite index - http://www.sitepoint.com/use-unique-indexes-mysql-databases/
  22. unfortunately the OP didn't actually answer the question that was asked. the problem is most likely because his code/database design allows multiple rows with the same combination of values to be inserted into his database table. your database table needs to enforce uniqueness. you need to define a unique composite index for the (catid1, catid2) columns so that you can only insert one row for any combination of values. you should also give those columns names that indicate their true purpose so that anyone reading the code/query can understand what the values mean.
  23. first of all, there's no issue posting code from a programming editor - if (isset($_POST['brand'])) { print "BRAND: " . $brand . "<br />"; } else { print "NOT SET"; } you would need to state how you were attempting to post the code and what sort of problem or error you got in order get help with what was going wrong. i posted the above simply by selecting it (left-button drag over the text) and copying it (right-button. select the copy option) in my editor, then right-button, select the paste option, in the forum post where i wanted it to be placed. the php isset() statement does exactly what its name implies and what the php.net documentation states, it tests if a php variable is set. other than php null values, it doesn't care what's in the variable being tested. if a form has been submitted, any named text, password, textarea, and usually submit form fields, that exist within the form tags will cause the corresponding php $_POST (or $_GET, if using a get method form or a link) variable to be be set, regardless of the value from the form field. only named un-checked check-box and un-selected radio-button form fields, that are part of any form, won't be set when a form has been submitted. to test what's in a php variable, you need to actually test the value in the variable. by definition, all submitted form data are string data. therefore, one method would be to test if a variable is or is not an empty string - if($_POST['brand'] != ''){ // the contents of the variable is not an empty string } else { // the contents of the variable is an empty string } if you want to disallow values that consist entirely of white-space characters, use trim() on the data first. you can also use empty() to perform this test. however, php considers all the following things to be 'empty' - therefore, if a 0 is a valid value for a form field, a "0" would be in the $_POST variable, and it would be considered empty() by php.
  24. it's not clear what the issue is. what update are you talking about? you have an UPDATE query, but i suspect you are talking about the INSERTed data or are you talking about just refreshing the page? in general, when asking for help, since we are not sitting there with you, you need to show what result you are getting and at what point you are getting it, and either clearly state or show what is wrong with that result, and also show or state what result you expected to get.
  25. when you var_dump the json decoded array, the whole thing if you need to, add echo '<pre>'; before the var_dump() statement so that the output will be human readable. then you need to identify which elements you need from the data. for once-per-order data, you would just access the correct array elements. for repeated data, you would loop over the correct array elements. if you need more specific help, you will need to show us or tell us specifically what elements of the array you need, show us the code you tried, show us what wrong result you got, and what result you expected from that data.
×
×
  • 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.