Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. If you are actually getting the expected data from your posted code, but after that point it is turning into a 1 or a 0, you would need to debug why that is happening and at what point the value is what you expect and at what point it is not. For us to be able to help you, you would need to post the code that reproduces the problem and show an example of the data you are using. If your print_r($price3); statement shows the correct value, post that so that we can see what it is you are working with. If the value is stored in the database table correctly (have you looked directly in the table using your favorite database management tool?), but it is displayed incorrectly when you retrieve it, the problem is in the display logic and you would need to post that.
  2. Your mysql_select_db() statement is probably failing with an error, either because the database name being used in it is incorrect, or perhaps has a letter-case difference (database and table names are case-sensitive on some operating systems/mysql configurations.)
  3. That's a php error message. That's not what someone asked you.
  4. What exactly did your use of mysql_error reporting state was the reason why the query is failing?
  5. The most straight-forward query would be to use WHERE column NOT IN (sub-query). To find new products - SELECT * FROM temp_table WHERE id NOT IN (SELECT id from permanent_table) To find discontinued products - SELECT * FROM permanent_table WHERE id NOT IN (SELECT id from temp_table)
  6. If your session id cookie is securely (the point of this thread) set up, it will only be sent by the browser when the request is via the https protocol. So, a visitor that is logged in via https won't appear to be logged in when he makes a http request because the session id cookie won't be sent with the request and you won't know on the server that you should redirect them to the https protocol. You would need to put a flag in the URL (just a ?s that you would test if it isset) that indicates to the logic that it should redirect to the htpps protocol. Once the redirect occurs, the session id cookie would be sent by the browser with the https request and the visitor would be matched up with his session data file. If someone who isn't logged in tried to add the flag to the url, the only result would be to redirect to the https protocol, which should then remove the flag from the url and redirect back to the http protocol.
  7. Computers are completely literal in what they do. To compare any letter-case variation with your allowed extensions, you would need to use strtolower on the value before using it in the in_array() statement. If you include a hidden MAX_FILE_SIZE field in the form (there are examples in the php.net upload handling documentation), php should check the content-size header of the file being uploaded and abort the upload at the start.
  8. Here's an issue with your present scheme. The TIME data type is limited to 838:59:59. If you have a need to store or calculate values greater than that, you should instead store the time in either the number of minutes or if you have the need for finer resolution, in the number of seconds, in an integer data type large enough to hold the maximum value you will ever need and perform the math in terms of minutes (or seconds) and convert the result to hours:minutes (or hours:minutes:seconds) when you display the value.
  9. You don't have to select data, modify it, then update the column with the new value. All you need to do is execute the UPDATE query with the calculation in it. The following SINGLE query should work - UPDATE aircraft SET utilization = ADDTIME(utilization,?) WHERE registration = ? The 1st parameter is the $block_time, the 2nd parameter is the $equipment. However, for what you are doing, you should treat the utilization an accounting ledger, where you add a row to a table with the registration number, the block_time, and things like the date/time of the trip, who entered the data, ... You would then just sum the block_times for any registration number to get the total utilization or the utilization between any two dates... This will keep a record of the entries and will prevent things like a duplicate update from messing up the data.
  10. I would have the server send the order to a fax machine at the restaurant through an Internet based fax service.
  11. it's because you are using the value after the end of the loop, not inside the loop, where it was designed to be used.
  12. If you posted what you tried and stated what result or error you got that leads you to believe that it didn't work, someone could directly help with the problem.
  13. You are logically OR'ing the values in your query statement. That creates a TRUE boolean value and all the rows having a user_id that equates to a TRUE (probably all of them) are matched. You would either need to create a query WHERE user_id = 5 OR user_id = 6, ... or use the IN() comparison - WHERE user_id IN(5,6,7)
  14. The first two Notice: Undefined index: ______ messages are because the person writing the code you found didn't know or care if it would gradually create a giga-byte size error log, filled up with undefined index/variable notice messages that would make finding actual errors next to impossible. The correct way of detecting a variable that might not exist (a $_POST variable that will only be set when a form as been submitted or a $_SESSION variable that will only be set when the visitor is logged in), is to use isset. The code at the first error should be - if(isset($_POST['username'])){ The code at the second error should be - if(!isset($_SESSION['admin']) || $_SESSION['admin'] != "admin"){ (never mind that a session variable that indicates the current visitor is logged in as an admin, that contains that person's username, will only allow ONE admin with the username 'admin') The Fatal error: Call to undefined function session_register() message is because you have a php version where the very old and depreciated session_register() function has finally been removed. The correct way of setting or referencing session variables is to use the $_SESSION array. You also need a session_start(); statement on any page that sets or references a $_SESSION variable. Since the rest of the code you posted is already using $_SESSION variable(s), It's likely that there is already a session_start() statement present (it must occur in the code before anything is output to the browser), and you simply need to remove the session_register() statement from your code.
  15. @White_Lily, Please stop posting nonsense code and code that doesn't directly address the problem in the thread. The line of code - $_SESSION["admin"]; DOESN'T actually do anything, nor does posting it tell the OP what he needs to do or why he needs to do it. The line of code itself is wrong and it doesn't teach anything or explain the problem. And if you had looked at the code the OP posted, he already has this - $_SESSION['admin'] = $username; in it. If you had explained what he needs to add to get that line of code to work and why, what to remove and why to fix the session_register error, you would have helped and possibly gotten a 'like' for the post. Posts that don't explain what the OP is doing wrong and what he needs to do instead, DON'T HELP and don't teach anything. They just throw the thread off topic, taking up the time of other members pointing out problems in it.
  16. A HTTP 500 error for a php page is usually the result of a fatal parse or fatal runtime error, but that the error_reporting/display_errors settings are not set up to report or display all php detected errors.. Since the problem occurs when you try to log in, that eliminates a fatal parse error as the cause, at least in the main file. You need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system.
  17. In case someone didn't state it already, you should NOT use the global keyword to bring data into a function, ever. For this exact reason. You must dedicate that variable to that specific purpose and can not reuse it anywhere else in the entire application for any other purpose. It just takes more time when writing the code, because someone must keep track of all of the variable names and it takes a huge amount of time debugging anything that goes wrong. Data should only be passed into functions as call-time parameters.
  18. The code you posted, for a starting value of 250.54, outputs Money:250.54 or Money:£250.54, depending on if the line that concatenates the £ symbol is being used. Therefore, that's not the code that reproduces the problem. Let me put this another way, until you post actual code that reproduces the problem, you are not going to get a solution. You are doing something that doesn't work and the only way we can help is if you show us the code that you need help with. If you had done so yesterday when you started this thread, you could have had this solved yesterday.
  19. You have to show us your exact code that reproduces the problem, from the point where you are retrieving/var_dumping the value, through to the code that is displaying the incorrect value, if you want us to do more than offer guesses as to what is causing the problem.
  20. You would use a LEFT JOIN between table 1 and table 2 ON the book id. This would give you all the matching rows from table 1 and if there is matching information from table 2, you would get a non-null value from an table 2 column that you select. A null value from a selected table 2 column would indicate that the user hasn't read the current book being displayed.
  21. An INSERT query that fails due to an error, doesn't necessarily mean that the data you tried to insert already exists. There are other things that can cause a query to fail, especially since you are not escaping the string data being put into the query and the other functions you are using on the data won't prevent single-quotes from causing the query to fail with an error. Likewise, an INSERT query that runs without producing an error, doesn't necessarily mean that the row was inserted correctly, such as string data that was longer then the field size and was truncated. For an INSERT query, you need test if the query executed without any errors, then use mysql_affected_rows to test if the row was actually inserted.
  22. The data is being returned with each requested item as a separate line, and each call to fgetcsv only reads one line - <?php $url = 'http://finance.yahoo.com/d/quotes.csv?f=l1&s=GBPUSD=X+GBPEUR=X'; $handle = fopen($url, 'r'); if ($handle) { $usd = fgetcsv($handle); $eur = fgetcsv($handle); fclose($handle); } echo $usd[0]; echo $eur[0]; ?>
  23. P.S. By having your form processing code AFTER the point where you are retrieving the data, you won't see any comment that is added until the page gets loaded again. Form processing code needs to be near the top of the code on the page.
  24. I'm not sure how your first - SELECT * FROM abstrktmainblogs f ... query is even matching one row, because by your own definition, blogcomment is a zero for the main blog posts, so s.blogcomment < f.blogcomment (this side is a zero) won't ever be true. Your foreach(){} loop is just iterating over the columns of the row that your query fetched, so you are getting the contents of the inner loop repeated for each column that the * selected. Speaking of using SELECT * in a self joined query, since the left and right columns have identical names, that is not giving you the values you want/need. You need to specifically list out the columns you want from the left and right parts of the join. By your own definition, the blogcomment column for comments is the id of the main blog post. I don't know why you didn't use that for the join condition or as the value passed through the form. Also, by using the title as the join condition, your queries will be slower and you cannot ever repeat a title. Your join condition should be ON the main blog id = comment blogcomment and you need to pass the main blog id through the form to associate the comment with the blog post. Id's are unique, titles are not guaranteed to be. Using an inner join will only return results that have comments. Any main blog entry that doesn't have a comment won't be present in your first SELECT * FROM abstrktmainblogs f ... query, assuming the rest of that query is doing what you expect. Your inner loop is reusing the $r variable, so there's no way the outer loop will do what you expect. Your use of isset($_COOKIE['userid']) to detect if someone is logged in and can post a comment will allow anyone to do so because anyone (or a bot script) can create and send a cookie to your web page. Also, by using the users id column as the cookie value, someone can just cycle through values and impersonate anyone in your users table. At a minimum, you need to generate a unique and hard to guess and hard to duplicate value and store that in the cookie and store that in a separate column in your users table. You would then use the value from the cookie to match up the user and his data in the users table. You would also use the fact that your query on the users table matches a row to determine if the visitor is logged in and the comment form is displayed and the form submission is processed. By setting up your log in system this way you can prevent users from posting (i.e. suspend or ban them) by having a status column in the users table that you check to see what the user is allowed to do. Lastly, you should not run queries inside of loops. Your goal should be one query that gets the information you want in the order that you want it. I'm not sure what ORDER you want the results, but the following query will get the information that you want (the alias names are b = blog, c = comment) - $query = "SELECT b.id, b.title, b.username, b.date_posted, b.post, c.username as c_username, c.date_posted as c_date_posted, c.post as c_post FROM your_table as b LEFT JOIN your_table as c ON b.id = c.blogcomment WHERE b.blogcomment = 0 AND b.page_id = $pg ORDER BY b.id, c.id";
  25. You still have a GROUP BY term in your query, so of course you only get one consolidated row. That's the opposite of what kicken stated and showed in his example query statement -
×
×
  • 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.