-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
this is a sign that the host-name/sub-domain part of the url (the www. vs no www.) is inconstant and is changing due to the redirects and your session cookie setting for the domain isn't set to match all variations of your domain name. the php.net documentation tells you how to set it so that it does, but your code should also be consistent in the variation of your domain name that is being used. you also need a exit; statement after the header() redirect to prevent your code on the protected page from running while the browser is requesting the target url in the redirect. this could also be the cause of unusual session operation, if the rest of your code on the page is clearing or modifying the session variables. lacking a real permission system, you need to use in_array() to test if a value is or is not one of several possible choices. your code would end up looking like - // define the user types that are admins - $admin_types = array("Admin","Owner","Moderator"); // test if the current user is not an admin type if(!in_array($_SESSION['SalesCRMA'],$admin_types) { header('Location: http://www.mysite.com/logout.php'); exit; }
-
in addition to posting your code, you have to provide information about what works and what doesn't, what error or symptom you are getting that leads you to believe that your code doesn't work, and what result you did get. your post does contain information about what result you expected, through it's not entirely clear, without your code, exactly at what point you expect that result. if what you are describing is storing data into a database table, you would NOT combine the information into one field/column. you would have separate columns for the different information and only combine them when you display the information.
-
your database design needs help. you should not create x empty rows, then try to manage the data in those rows. you should only insert data that exists and delete data that gets removed. you can limit the maximum number of rows that can be inserted by using an INSERT ... SELECT query, with a COUNT() term and comparison in the SELECT part to only insert a row if the count is less than the maximum. to do this, you need to have a unique composite index set up for the player_id/card_id columns so that you cannot insert the same card_id for any player more than one time. see the following query - INSERT INTO player_deck (player_id, card_id, card_amount) SELECT -- the following values being SELECTed are the data to insert, unknown if you can use place-holders and bound data 1234, 4, 1 FROM DUAL -- dual is an allowed dummy table name to satisfy the FROM ... WHERE syntax WHERE (SELECT COUNT(*) FROM player_deck WHERE player_id = 1234) < 5 -- insert the data if the WHERE (subquery count) < 5 is TRUE the 1234, 4, 1 example data are the player_id, card_id, and card_amount values. you would supply these to the query. the player_id value occurs a second time later in the query. the 5 in the < 5 is the limit. you would change it to 60. if the count is less than this value, the row will be inserted. if the count is equal to greater than this value, the row will not be inserted. if you are actually trying to insert this data if it doesn't exist or update the card_amount if a row already exists, you can add an ON DUPLICATE KEY UPDATE ... to the end of this query (just tested.)
-
was just going to post the same. none of the UPDATE queries being shown make sense. you need to define what you are going to do for all the different possibilities and to get help from us, you need to provide that definition so that we understand all the different possibilities. for the input data, what will it look like when adding card(s) that don't exist? what will it look like when modifying existing card amounts? what will it look like when you remove card(s)? is the card_amount always 1? is the card_amount a value of a card, that is fixed or variable for any card id or is it the number of cards with that id, assuming you can have more than one of any card id? are there always 60 ids and 60 amounts in the submitted data? what do the -1 you have shown in the sample data mean? then, for each of the possibilities of adding cards, removing cards, or changing the card_amount, you would design the correctly type of query to insert, update, or delete the data.
-
in programming, the best way of dong something requires knowing the context. what are you actually doing, what problem are you having by doing it this way, and how many times in a program are you going to be doing it (if you have a set of data, you would use an array, and the coding would use a different method, than for one discrete variable)? the best answer for your situation may be to always define the variable with a default value first. the best answer for your situation may be to use something like a ternary operator to define and give the variable a value if a set of conditions are true or a default value if the conditions are not true. the best answer for your situation may be to skip over all the code that's dependent on a variable if the conditions are not met.
-
array keys/indexes must be unique, so your anticipated result is not possible. not knowing why are you doing this, what you are ultimately using the data for, which would produce the best result, i would recommend making an array with the start value as the main array key and the (start)/title/description data as sub-arrays under any start value. it would look like - $data['201601221400'][0] = array('start' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.' ); $data['201601221400'][1] = array('start' => '201601221400', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.' ); $data['201601221400'][2] = array('start' => '201601221400', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.' ); you would produce this by looping through the data, using the 'start' value as the main array key and appending an array consisting of the start, title and desc - $data = array(); foreach($items as $arr){ $data[$arr['start']][] = $arr; } echo '<pre>'; print_r($data);
-
no, you wouldn't have columns like that. i reviewed your last database related thread and a member mentioned Normalization. this is the same thing. short answer - there's one row in a table for each item of data and all the same meaning data is in the same table. by storing the data correctly, you can write simple queries that find any data that you want. storing the data correctly will also eliminate all the code you have to move data between tables. something tells me that the data you are showing us in this thread is actually derived/accumulated data. you should be calculating this when needed, not storing it in a table.
-
JOIN's are used when there is a relationship between different meaning data in tables. an example would be a clan table, that defines the clan name and assigns an id to each clan and a table holding the data you currently have. if you want to retrieve the clan name for display or search for data using the clan name, you would join the two tables using the clan_id columns. for what you are doing, you should have ONE table holding all the results. the date column you have will let you retrieve the data you want. If you want to retrieve the n most recent weeks worth of data, you would add a term in the WHERE clause to match rows having a date value greater then or equal to the starting date you are interested in.
-
Login script. Join table "user" to table "admin"
mac_gyver replied to Andy_Kemp's topic in PHP Coding Help
you need to add the login form/form processing at any point that you expect a user to be logged in and she/he isn't. if you are at the point of needing a user permission system, you should probably be at the point of having a web site that handles all the processing/content through one main file, not though having a separate file for each different thing your site does. when a user logs in, you are authenticating who they are. this only involves matching the username and the hashed password in the user table and storing the user id in a session variable. to determine what a user may do or see on any page request, you would take the user id from your log in system and retrieve their current permissions. the reason to do this on each page request is so that any changes made to the permissions will take effect immediately. the code on your page would test if the current user has permission to perform any action or view any content that you have defined in your permission table. -
you would use a html array name for the rec form field, where the array key is the SKU number - name='rec[1769057]' this will result in an array in $_POST['rec'] that you can use php's array functions on, such as a foreach(){} loop to loop over.the elements when providing data to your sql query.
-
rather than expect someone to do your work for you, how about sitting down and trying yourself. have you defined the work-flow that a site visitor will go through from arriving at the site, as an unknown 'guest' user, through completing payment for an order, and beyond when the ordered items are shipped, received, and possibly returned? This will define what data each page on the site will need to process and store as input data or retrieve for use to display the page. This will define the types of information you will need to have database tables for. then, before you write any code or create any database tables, take the design you have theorized, and 'walk' through the process for a made up user and some made up items to see if your design does what you want. modify your design as needed and repeat until you are confident you have covered 99% of the possibilities. then, write and test the code and queries that implement your design, making any needed changes along the way.
-
i'm wondering why the code in this thread, using mysqli, threw a way the code you posted in your last thread on this forum, using pdo, that apparent had a working date search - http://forums.phpfreaks.com/topic/300742-paginate-search-results/ especially since you have now posted that previous code, less the pagination logic, on at least one other help forum, expecting someone to spoon-feed you with the information you need to paginate the results. programming requires that you learn the meaning of what you are doing so that you can write code that brings together different concepts. all you are doing is trying to smash together pieces that don't even work together. by throwing away code and starting over, sometimes in a single thread, you are also throwing away the help you have gotten, because people are not going to keep reading randomly changing code from you to try and figure out what you are currently doing. if you want help, stick with one set of code and FIX the problems in it (using PDO is your best choice, since you need to use a prepared query to get the external data securely into the query). don't keep starting over. it will take you forever to accomplish anything.
-
your code is all over the place. in addition to mixing mysqli and PDO statements, you are making (apparently) two different PDO database connections AND the WHERE ... clause in your data retrieval query must be used in the total row count query so that the two queries match the same set of rows. you should form the the WHERE ... clause in a php variable, then use that variable in both queries. you should also get the total row count first, so that you can use it to limit the maximum page number so that a programming error or someone feeding your code invalid/large page numbers doesn't waste resources running the data retrieval query that will never match any data. edit: you also have a problem with the pagination links and the date filtering, you need to propagate any selected date filtering in the pagination links so that the the code will properly select data on each page.
-
you would start by storing the dates using a mysql DATE data type, so that you can do date comparisons (to select the range of dates you are interested in) and so that you can order the data by the date. you would then run a query that selects the data you want in the order that you want it. you would probably want a secondary sort order on the description so that the links are in alphabetical order within any date. you would fetch the data into a multi-dimensional array, using the date as the main array key/index. this will give you a sub-array of data for each date. because the quote data is not directly related to the links data, you would query for it separately and fetch it into its own array using the date as the array key/index. you would then just loop over the main array to access each date, then loop over the sub-array for each date and output the data the way you want. you would use the date value from the main loop to access any quote(s) for that date in the quote data array.
-
is the openssl extension installed and enabled? you will need it for php to be able to establish a https connection.
-
need help with a strange behaviour in php
mac_gyver replied to shan2batman's topic in PHP Coding Help
it's probably something in the 'dbconfig.inc.php' file. or if the posted code is being included/required into another file, it's coming from something in the main file. -
// set a default value if not already set - if(!isset($_SESSION['posY'])){ $_SESSION["posY"] = 50; } // and if you really, really, really are creating more variables holding values that you already have variables for (what's wrong with using $_SESSION["posY"] ?) - $posY = $_SESSION["posY"];
-
move_uploaded_file not giving error but not moving file
mac_gyver replied to davidannis's topic in PHP Coding Help
are you sure about the spelling and capitalization of the path in all cases, in all the code and when looking for the file? could you also have a /home/lineligh/public_html/art3/artwork/ folder or a folder with a space in a part of the path? how are you submitting the data to the form processing code and viewing the result from your debugging statements? you could have a case where the data is being submitted twice, the second time without any successfully uploaded file, and the file is being deleted. the only requirement in your logic to run the move_uploaded_file() statement is that $_FILES['picture']['name'] is set. this however doesn't guarantee that there is a successfully uploaded file. lastly, does your server have the stupid Suhosin hardened kluge present? it has a habit of making perfectly good code, not work? -
move_uploaded_file not giving error but not moving file
mac_gyver replied to davidannis's topic in PHP Coding Help
it's likely that your actual complete code is deleting the file after you have moved it to the folder. i'm betting if you put a die; statement after the echo '<br>$result: '.$result; line, that the file will be present in the folder. edit: btw - how do you know the file isn't in the folder? what method are you using to get a listing of the files, since the fault may be in the method being used? -
if you review your previous thread on the forum ( http://forums.phpfreaks.com/topic/279439-simple-shopping-cart/ ), where you were using array indexes with sequential numerical endings, the same as what you are doing now, someone suggested a simplified approach that reduced the amount of code to almost nothing. you need to define a data structure that supports what you are doing, not make it harder. i'm betting if you use the same approach that was suggested in that previous thread, and use the name as the array index and the corresponding value as the array value, and just delete (unset()) the element(s) from the array, it will solve your problem.
-
and do you have control over this application such that you would be able to change or define what form and format the output data is presented as? does this data source have the ability to send the data to a web server (to a URL) or does it require human intervention to get it to produce and display the data? if you don't have any control over the data source, you will need to write code to process the data in whatever form and format it is available as. getting people to list all the possible ways to do something isn't useful, since all the suggestions may not even be compatible with the data source. care to share some actual information about what this application/data source is and what form (file, text output on the display on a computer, ...) this data is available as, so that the suggestions being given will be targeted to the actual problem?
-
first of all, you are asking about a value in a column, not a row. the answer is to add some programming logic to the code that's INSERTing the data. they call this stuff software for a reason. if it doesn't do what you want, you can change it to suit your needs. you should actually have a jobtype table that defines the different jobtype names and assigns a jobtype_id to each one. it's the jobtype_id that should be stored in the jobtype column. you should not be regularly dumping this data into a combined database table. you should do this once for the existing data, then use the single combined database table from that point forward.
-
no. you cannot just change the name. the parameters that the two different sets of functions took are different. you must read the php.net documentation, for whatever function you are trying to use, so that you will gain an understanding of what parameters it requires and what they mean. there are also basic examples to be found in the php.net documentation along with user contributed notes.
-
start with the first error message. i'm betting it concerns an undefined variable $id on about line 12 in your code. this is the line of code - $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); where in your code, prior to that line, have you defined a variable named $id and assigned it a value? the answer is you haven't. unfortunately, php at one time (14 years ago) would have defined the $id variable, based on the existence of the $_GET['id'] variable. this however resulted in a huge security hole and was turned off by default 14 years ago and was finally removed from php a few years ago. for there to be a variable named $id, you must create it and assign a value to it from the $_GET['id'] variable or you must use the $_GET['id'] variable in your code. however, putting external data directly into an sql query statement allows sql injection and anyone can run any sql they want on your server. the best way of preventing sql injection is to use prepared queries, with place-holders in the sql statement were data goes, then bind the actual data or variable holding the data with the place-holder. also, the mysql_ functions are obsolete and have been removed in the latest version of php. you should be learning to use either the PDO (the best choice, especially if using prepared queries) or mysqli_ functions. lastly, for the rest of the undefined variable errors. your page is dependent on there being an id value to put into the sql query statement, the sql query running without any errors, and upon the sql query finding a matching row in the database table. if all three of these conditions are not met, there will be no data to display. in this case, you should output a appropriate message on the page to let the user know what's wrong and not try to reference non-existent data.
-
javascript does not provide any protection for the server-side code. any value that anyone or a bot script wants, can be submitted to the server-side code, without using any of your client-side code (other than to learn the field names to use.) the server-side code must have protection in it.