Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,448
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. both of those assumptions, while might be true now, are both bad assumptions to make in database designs. you will end up programming yourself into a corner (paint yourself into a corner) that will take a lot of effort to correct later or in a real design. you also didn't answer "how exactly are you trying to use this information?", because that would let someone here help you with how you should be doing this.
  2. you can get the data directly as an array by setting the parameter in json_decode(), no need to parse anything unless you have some specific requirements, which you didn't state. all you stated is you want to get the posted wall of object data (if you echo a '<pre>' tag before that, it will be formatted as a readable wall of object data) into an array without any indication of what you wanted to parse or of what problem you had when you tried to parse it.
  3. believe it or not, you can get mysql to tell you why the query is failing. use the following in place of your mysqli_query() statement - $result=mysqli_query($con, $query) or die(mysqli_error($con)); also, i meant to type this above. your return statement and the file name funcitons.php implies the posted code is inside of a function. do NOT make a database connection, run one query, then close the database connection. you need to make ONE database connection in your main code and pass that as a call time parameter into any function that needs to use it. creating a database connection, depending on where your database server is located at with respect to your web server, can take longer than actually running the query. repeatedly opening/closing a database connection each time you run a query will noticeably make your site run slower.
  4. by setting the second parameter in the json_decode() statement to a true value.
  5. what value does it put into the field and how are you seeing what the incorrect value is in the field? some possibilities, you have another query that replaces the value after the fact with something else or if the observed symptom is due to some output from your code, you could have a logical error that is causing the wrong value to be displayed. shorter-answer: the insert query you have posted ISN'T the problem (assuming that's your actual query statement.) something else is occurring that is causing the symptom you are stating.
  6. not trying to give you a hard time, but there's not any good reason to need to do this (as trq already mentioned) and in the cases that people do try to do this, it can result in cross-linked/corrupted data should two different people insert new data at about the same time. how exactly are you trying to use this information?
  7. the warning, at the point you are trying to use the result from the query, means that the query failed to run due to an error of some kind and it returned a false (boolean) value, as has already been mentioned. a query that runs, but matches no rows (or there are not rows at all in the table to match) is a successful query and would return a result resource/result object, not a false value. your query is not running because the sql syntax is not valid, as has already been mentioned. if your code had some error checking/reporting logic to 'capture' (display or log) the mysqli_error($con) output, it would be calling attention to the point in the query that something was found that mysql didn't understand. your error checking/reporting logic would also prevent the following code from trying to use the result from a query that failed so that you don't get follow-on errors. your id field is a string data type (based on the value shown when you echoed the query statement.) the value you compare it with needs to be a string, enclosed by single-quotes inside the query statement.
  8. the way to avoid repetitious code, that only varies in a value, is to use a programming loop construct to replace the code. loops are fundamental to all programming languages and would be covered in about the third main section in any book or tutorial. sorry for the cheeky answer but this is really basic stuff that you should have already seen. the most straightforward code would use a for(){} loop to loop over a range of values. you could also produce the range of values in an array (using the range() function), then use a foreach(){} loop to loop over that array of values.
  9. if this is a one time activity, you can use a mysql LOAD DATA LOCAL INFILE ... query - http://dev.mysql.com/doc/refman/5.6/en/load-data.html there probably are csv import scripts that analyze your csv header and database columns and allow you to pick and map which csv column(s) are imported into which database table column(s). have you tried searching the Internet for an existing script that will do this? otherwise, you will need to write some php code to open, read, and parse the data out of your csv file and form and run the query(ies) to insert the data into your database table. 25k entries is not that much, you should be able to read the entire file into memory at one time to speed up the processing. you can use php's file() function to get all the lines into an array. you can then explode/access the correct column of data. i'm partial to using array_map() and a short user written function to do this without having to loop of the data in your code. you can than split the resulting array of data into chunks (see the array_chunk() function) of about 5k entries each. then loop through the chunks of arrays and implode the data within each chunk to form a multi-value INSERT query.
  10. from a functional standpoint, you need to store the integer representation of the ip addresses so that the comparisons will work and you would need to convert the client ip address to its integer representation. the dotted-quad format for ip addresses are strings and in general cannot be compared greater/less than (would require that you add leading zeros to make each quad value 3 characters.)
  11. what exactly are you trying to get your function to do? is it supposed to format and output the errors? add an error to the $error array? do something with a $_SESSION variable? setting $error[] = 'Please enter username and password.'; is about as simple as this can get. what do you need a function for? to write a function, you must first define what inputs (if any) it uses, what processing it will do, and what result or output it produces.
  12. there's not enough information in your post. do you want the current date as the first <option> choice, even if there are dates greater then the current date, or do you want the current date to be listed in the proper date order? for both cases, you need to store the data in an array using the date as the key to the array. for the first case, if the current date isn't in the array, simply output the <option> choice. for the second case, simply insert the current date into the array if it is not already present and order the array by the dates (assuming your date format can be used to order dates, see the next paragraph.) also, the format you have shown for the dates does not permit correct sorting, so either you have left out some code that produces that format or your data doesn't sort properly when the year changes value.
  13. you need to rearrange the logic on your page so that the main (business logic) php code is executed first, then you build and output the html document using the data that php produced/retrieved. for the code in post #1 in this thread, that would mean replacing the echo statements with code that concatenates the output into a php variable. you would then simply echo the php variable holding the page title and the php variable holding the main page content at the appropriate points in your html document. all the html document, from the <!DOCTYPE html> tag to the closing </html> tag, would come after the main php code on the page. edit: organizing the logic on your page the way that i have described (i.e. using php as a template engine) also eliminates a common problem like in this thread - http://forums.phpfreaks.com/topic/280490-what-is-wrong-with-the-code/
  14. so all of this is off topic since the OP needs help with what his code is doing and why it might produce the result he is getting.
  15. so since the salt is stored for each user in the database table, you would expect the OP to run two queries to accomplish this task? once to retrieve the salt, then a second query to compare the resulting salted hashed entered password with the hash stored in the table?
  16. a) the OP isn't using the code in your signature, and b) you do understand that the function in your signature only produces the $dbPass value from the original entered password and in order to check if the entered password matches, you must retrieve that $dbPass value from the database table to run it through a check function to compare it. the OP retrieving his hashed password value to run it through his hashing logic again to compare it is no different, his method is just storing the hashed password and salt as separate values, rather than storing the salt characters as part of the hash that the crypt() function does.
  17. since you have started a new thread for help with your login script, i will assume that the tail-end symptom in this thread was due to your login script not actually working and no further replies in this thread are needed?
  18. the error means that your SELECT query failed with an error of some kind. for debugging, echo mysql_error(); on the next line after the mysql_query() statement to find out why the query failed. also, since you don't have any logic in your code to test if the query worked before tyring to use the result from that query, mysql_num_rows() will always be a zero and your code will never run the echo "The username you have entered is already exist. ... logic. you need to always test if a query works without any errors.
  19. are your fields in your database table large enough to hold the values you are storing in them? are you using the same LOGIC to hash the entered password that was used during registration? did you use var_dump() or echo the two values being compared in if($hash != $userData['password']) to see what is different about them? @Muddy_Funster, password isn't a reserved mysql keyword, its a mysql function name and using it in an identifier context isn't an issue, and you would need to pull the password from the database if you were using one of the stronger password crypt/hashing methods that the OP should be using with a unique salt stored per user, which the OP is using.
  20. then somewhere between where you set $_SESSION['valid'] to a value when you logged in and the code you posted in this thread, it either got unset or something about the URL changed so that the browser is not sending the session id and the session_start() didn't resume the same session you had when you set $_SESSION['valid'] to a value when you logged in. are you sure the session_start() on your login page worked (no php errors) and that your code set $_SESSION['valid'] to a value (by checking using var_dump())? could you have code that is un-setting $_SESSION['valid'] on your login page, such as having a header() redirect that doesn't have an exit; statement after it and when the following code runs, it is un-setting $_SESSION['valid']? is the hostname (www. vs no www.) on your URL the same for the login page and the page with the code you posted in this thread? by default, the session id cookie only matches the exact same hostname variation of the URL where it was set.
  21. 1) do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would report and display any errors it detects, such as a session_start() related error? 2) what exactly is in $_SESSION['valid'] when that code runs, i.e. what does var_dump($_SESSION['valid']); show on that page after the session_start() statement?
  22. if this is your application, the data should be output in a format that supports how you are using the data, not make it harder, requiring more processing before you can even use the data. you should output the data as a JSON object with key/values that let you directly access the data (you should only output the data you want as well.)
  23. because you have provided zero information about what it does or doesn't do, you haven't gotten any specific response. the statement "does not work" is meaningless because we are not standing right next to you and don't know what you saw that leads you to that conclusion. there's a dozen different things that could go wrong in any php code that would cause it to not work. you need to clearly communicate what did happen in order to narrow down the possibilities. p.s. you are still running the same query twice. that is wasteful. just run it once, test if it returned any rows, then simply loop over those rows.
  24. is that the exact spelling and capitalization of your database column name? are you selecting that column in your query statement? do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying the errors it detects?
  25. here is the basic LOGIC you need to detect when to close the previous section, start a new section, and output data under a section - $departmentHeader=false; while( ... ){ $staffDepartment=$staff['department']; // detect a change in the department header if($departmentHeader!=$staffDepartment){ // the department changed (or is the first one) if($departmentHeader != false){ // not the first section, close out the previous section here... } $departmentHeader=$staffDepartment; // save the header // start a new section here... } // output the data under each section here... } // close out the final section here...
×
×
  • 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.