-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
Pagination question for limiting search results
mac_gyver replied to mike2's topic in PHP Coding Help
define: would this negatively affect my Swish-e search results? all you are doing is changing how the results are displayed on the page. what negative effect are you worried about? btw - this page is getting and displaying data, your search form should use method='get' as this will allow you to easily propagate the search term with the pagination links. modifying the code to include pagination will pretty much require a rethinking of your current code layout. what you have now is a html document that has php logic pasted into it to produce the overall document. what you need is a separation of the 'business logic' (determines what to do on the page and gets the data the page needs) from the 'presentation logic' (deals only with the production of the html/css/javascript output.) the reason for needing to rearrange the logic is the pagination code needs things like the $totalItems (this is your $result->hits value) and your swish code needs to use the $offset/$limit to accomplish the pagination. i also see that your .csv file code is inside your main data retrieval while(){} loop, running every time the loop runs. this code should run only once to produce the $companies array, i.e. it's part of the 'business logic'. edit: i also see that you have duplicated the wvb-logo-slogen.png image tag. you should not duplicate code/markup and reorganizing the logic on the page will help you see duplication since it cleans up the whole layout of the code. -
Pagination question for limiting search results
mac_gyver replied to mike2's topic in PHP Coding Help
swish has a ->seekResult() method - http://www.php.net/manual/en/swishresults.seekresult.php that would allow you to seek to the starting point in the swish result set. this would use the $offset value from the pagination code. you would then loop, up to the $limit times, calling the ->nextResult() method to get up to $limit rows from the result. you could also just initially store all the swish results in an array, in a session variable, and use array_slice() to paginate the array. the $offset and $limit from the pagination code would be the offset and length parameters in the array_slice() statement. -
if you are using notepad++ as your method of editing files, they recently introduced a feature that broke, by default, the whole purpose of editing files, i.e. to save the changes you made to the actual file when you exit the editor, but instead holds the changes in an editor session. what you see in the editor isn't what's in the file unless you explicitly save the file before you exit the editor or turn off this feature.
-
your example, after fixing the php syntax error in the first line, does work. if your tags didn't have unique delimiters (at least the closing one) - [] around them, and were only the text - A_CUSTOM and A_CUSTOM_TAG, then the code would exhibit the symptom you describe.
-
in order to use the mysql_ functions with multiple separate connections, you MUST supply the connection link resource as a parameter to the mysql_select_db(), mysql_query(), and mysql_error() functions. however, since the mysql_ functions are now depreciated, you should switch to either the mysqli_ or PDO database libraries, which both require the connection resource in all cases (mysql functions had a built in lazy-way of using the last created connection when you didn't supply the link resource.)
-
Set Multiple values to a query string in PHP
mac_gyver replied to Stefany93's topic in PHP Coding Help
you would use an array for the name attribute - name="size[]" you would also output the checked keyword for any checkbox that has already been checked, which would generally lead to using php to dynamically produce the form, rather than you hard-coding each form element. -
Help required to fully and properly parameterize a SELECT query
mac_gyver replied to excelmaster's topic in PHP Coding Help
only data values (strings, numbers, dates, ...) can be bound in prepared queries. the sql query syntax (keywords, column names, functions, operators...) is parsed when the query is prepared. only values are supplied through binding. since your $searchtype is a column name, it cannot be supplied as a bound parameter. that logic is redundant in that it repeats parts of the query that don't change. you should only code for things that are different. the logic should only validate/supply "store_name" or "item_description" as the column name that gets put into the rest of the query statement. the columns that are permitted to be used in the $searchtype need to be validated and limited to insure that only the values you have chosen can be used and to prevent sql injection or errors to be triggered (accidentally or on purpose.) one possible way - $permitted_searchtypes = array("store_name", "item_description"); // define which columns can be used as the search type $searchtype = strtolower($searchtype); // force letter case if(in_array($searchtiype,$permitted_searchtypes)){ $sql = "SELECT * FROM `shoplist` WHERE $searchtype LIKE :searchterm ORDER BY store_name ASC"; // prepared, bind, and run query here... } -
Also, Please use the forum's bbcode tags (the edit form's <> button) around the code you post in the forum.
-
a) the syntax of your BETWEEN term is incorrect. its - expr BETWEEN min AND max. where the min and max value would be provided by $minprice and $maxprice, after you have validated them (or use prepared queries.) b) you would probably want to remove the conditional logic using $minprice and $maxprice later in the code since that will add equal comparisons with the price that will probably never be true. c) your Propertyid should be unique in the PROPERTIES table, so there's no need to use distinct or GROUP BY PropertyId in the query. d) since you are using mysqli_query(), you must use mysqli_error($con) in the query error checking logic.
-
PHP Pagination working locally, but not on the live server
mac_gyver replied to Nonks's topic in PHP Coding Help
because of the mixup in the get/session variable names, about the only way the original code could work is if register_globals are on, which would cause the $_GET['sname'] and $_GET['cname'] variables to magically set the correct $_SESSION['sname'] and $_SESSION['cname'] variables. the solution is to use and match up the correct get/session names so that they are what you want and your program logic sets the session variable from the get variable only when the get variable exists and has been validated (assuming you need the session variable at all.) you currently have three different names for each set of data. pick a consistent name for each set that indicates the meaning of the data in the variable and use that same name for the get, session, and regular php variable (or just get rid of the regular php variable and use the session variable in it's place or if you don't need the session variable, just use the get variable everywhere.) -
a) this seems to be a continuation of your previous thread on this forum? if so, i/another mod will merge the two threads as the information in that previous thread would help with the suggestions being made in this thread. b) did you read the new reply in your previous thread? a member who's with godaddy asked a specific question about the windows hosting? though, if the windows hosting is with godaddy, you would need to get permission from your client for anyone to touch the account. c) you can put the error_reporting/display_errors settings into your .php script. d) while it's not relevant to the actual problem you are trying to solve, the error from the exception script on your test site is most likely because you didn't change the $_FILES[....] array index name in that script to match what your form is submitting. e) the 'Problem #2' message from your code would occur if the fopen() fails and $csvfile is a true value. about the only situation i can think of where this would occur is if safe mode or open_basedir are enabled and is preventing the fopen() from working, i.e. the file is being uploaded ($csvfile is a true value), but fopen() cannot access it (the suggested error_reporting/display_errors settings would tell you if this is the case.) if this is the case, you can use move_uploaded_file() to read/move the temp uploaded file to a file that php can access without restrictions.
-
why not just decode it and use php array functions to find/process the data - <?php $string = '[{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174222182518,"lsrc":80972326202,"ltgt":31581262572,"luuu":"groups.google.com/group/comp.infosystems.www.users/msg/9a210e5f72278328","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174457993090,"lsrc":80972326202,"ltgt":31622557610,"luuu":"support.google.com/chrome/answer/95582?hl=en","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174457997214,"lsrc":80972326202,"ltgt":31622557668,"luuu":"support.google.com/chrome/answer/95626?hl=en","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174704422109,"lsrc":80972326202,"ltgt":31675615115,"luuu":"www.google.com/support/chrome/bin/answer.py?hl=en&answer=95582","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174704422260,"lsrc":80972326202,"ltgt":31675615123,"luuu":"www.google.com/support/chrome/bin/answer.py?hl=en&answer=95626","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051896270,"lsrc":80975346908,"ltgt":31567049373,"luuu":"books.google.com/?id=0IZboamhb5EC&lpg=PA731","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051900386,"lsrc":80975346908,"ltgt":31567051168,"luuu":"books.google.com/?id=58KxPNa0hF4C&lpg=PA463","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051902110,"lsrc":80975346908,"ltgt":31567051879,"luuu":"books.google.com/?id=6xiYiybkE8kC&vq=core","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051902955,"lsrc":80975346908,"ltgt":31567052243,"luuu":"books.google.com/?id=7veohk0fkLYC&lpg=PA88","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051904343,"lsrc":80975346908,"ltgt":31567052883,"luuu":"books.google.com/?id=9iQYSQ9y60MC&lpg=PA49","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051905960,"lsrc":80975346908,"ltgt":31567053635,"luuu":"books.google.com/?id=BgZyXNIrvB4C&pg=PT12","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051911261,"lsrc":80975346908,"ltgt":31567055934,"luuu":"books.google.com/?id=Ho_RmgOnwgwC&lpg=PA8","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051913146,"lsrc":80975346908,"ltgt":31567056717,"luuu":"books.google.com/?id=JttyjBoyb3AC&lpg=PA12","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051920509,"lsrc":80975346908,"ltgt":31567059840,"luuu":"books.google.com/?id=SF7U27JsLC4C&dq=iraq+invasion+removes+hussein","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051921673,"lsrc":80975346908,"ltgt":31567060362,"luuu":"books.google.com/?id=T_0TrXXiDbUC&dq=slavery+%22American+Civil+War%22","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051922547,"lsrc":80975346908,"ltgt":31567060715,"luuu":"books.google.com/?id=UYpVAAAAYAAJ","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051925466,"lsrc":80975346908,"ltgt":31567061980,"luuu":"books.google.com/?id=Y1dOLQN9hvwC&dq=SEALs+kill+Osama+bin+Laden","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051936195,"lsrc":80975346908,"ltgt":31567066473,"luuu":"books.google.com/?id=jLy-NKnQitIC&pg=PA45&dq=uk+us+special+relationship","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051937261,"lsrc":80975346908,"ltgt":31567066890,"luuu":"books.google.com/?id=ka6LxulZaEwC&vq=annexation&dq=territorial+expansion+United+States+%22manifest+destiny%22","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051943179,"lsrc":80975346908,"ltgt":31567069364,"luuu":"books.google.com/?id=r71u_AgE7iYC&lpg=PA142","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051949934,"lsrc":80975346908,"ltgt":31567072219,"luuu":"books.google.com/?id=yd4GqkP5XYgC&lpg=PA229","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051950951,"lsrc":80975346908,"ltgt":31567072673,"luuu":"books.google.com/?id=zq4rsWNrYo4C&q=Reaganomics&dq=Reaganomics","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174052414947,"lsrc":80975346908,"ltgt":31567405066,"luuu":"books.google.com/books/about/A_History_of_the_American_People.html?id=RXSVQjz1_tMC","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174052676940,"lsrc":80975346908,"ltgt":31567608329,"luuu":"books.google.com/books/about/An_Empire_of_Wealth.html?id=rmsUs_KDgHAC","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174054227159,"lsrc":80975346908,"ltgt":31568894639,"luuu":"books.google.com/books/about/History_of_the_American_Economy_With_Acc.html?id=lyhI1q_E4G0C","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"}]'; $array = json_decode($string,true); echo '<pre>'; var_dump($array);
-
easy problem, i think ;/ selection menu not showing rows
mac_gyver replied to loxfear's topic in PHP Coding Help
your page/file has a .html extension. php code is NOT parsed in a .html file. change your page to a .php extension. -
undefined Variable Issue due to moving servers
mac_gyver replied to rachae1's topic in PHP Coding Help
way back in php4.1 (December 2001), php introduced the superglobals - $_POST, $_GET, $_COOKIE, ... in php4.2 (April of 2002), they turned register_globals off by default, because programmers were expected to start using the superglobal variables to access external data. register_globals being on started throwing deprecated errors in php5.3 (June 2009), and have been completely removed in php5.4 (March 2012.) turning register globals on is at best a stop-gap measure since they have been removed from php versions starting over two years ago. time to update your code to use $_GET['h1'] to access values supplied in the url query string. -
just dumping all your code on a help forum isn't going to get you much sympathy or help. what debugging have you done to pin down and solve the problem? also, your deadline isn't OUR problem. telling us 'I've got this form that keeps messing up' is pointless; because we are not standing right next to you and don't know what you saw that leads you to believe that your code didn't do what you expect, nor at what point in the process the problem occurred at (is there a problem with the form page itself, did the form processing code produce an error, or does the received email contain the wrong information.) so, both make an effort to find and solve your own problems and if you have to resort to getting help from someone else, tell them what symptom or error you are getting from the code and at what point in the process you got it.
- 2 replies
-
- contact form
- php
-
(and 1 more)
Tagged with:
-
also, the require statement for your database connection mysqli.php file ISN'T a URL, that's a file system path. URLs (that are used by browsers to request pages on a web server) are not the same thing as file system paths (that are used by php on the server to read files.)
-
Im confused with large csv reading line by line
mac_gyver replied to bores_escalovsk's topic in PHP Coding Help
define: per run/next run? do you mean, read the next line in the file, one at a time, each time the page gets requested? -
fputcsv stops writing after output file reaches size 848661
mac_gyver replied to ballhogjoni's topic in PHP Coding Help
do you have php's error reporting set to E_ALL and display_errors set to ON (or log_errors set to ON) so that php would be reporting and displaying/logging the errors that it detects? edit; after looking at your program logic, i'm going to guess that at some point your getProductRow() function just starts returning a false/empty array every time and the code ends up executing the continue; statement every time and is looping over the rest of the input file and not writing anything to the output. -
jpgraph dynamically produces an image (i.e. the selected content type header followed by the binary image data.) you cannot output an image directly on a html web page. you must use an <img src='url_that_results_in_an_image'> tag on your web page to cause an image to be rendered by the browser, where the url_that_results_in_an_image would be a url to a .php script that uses jpgraph inside that .php script. most of the jpgraph examples included with the jpgraph download are the .php code that would go in the file that's supplied as the url to the <img src = ' ... '> tag. you can browse directly to the .php files with the jpgraph code in them, because the browser can figure out what to do based on the content type header/binary image data the the file sends, but in order to put a dynamically created image onto a web page, you must use an <img src = ' ... '> tag.
-
sqlite: join syntax creates "no such table" error
mac_gyver replied to shutat's topic in Other RDBMS and SQL dialects
afai can recall, when you assign an alias name (your f, h, and m), you MUST use the alias name for all table references. your SELECT term must also use the aliases, not the full table names. -
the error is because you are reusing the $result variable. why do you have a loop in your code? the ->fetch_all() method fetches all the rows.
-
the php.net documentation is the best place to learn the basic syntax and usage. programming is the type of task where you must really grasp the meaning of everything, every character counts. watching videos cannot do that well because after the information goes past, it is hard to find it for reference. printed information is the best way of learning a programming language because you can easily find it to keep referring to it as many times as necessary. your error is because you are assigning one array variable - $row['id'] to a session array variable but the syntax you used on the left-hand side is not that of array variables, but of calling a function, which uses ( ). the syntax for referencing elements of array variables uses [ ] around the index/key, as in $row['id']. the syntax on the left-hand side to assign that value to a session array variable would be the same usage - $_SESSION['uid']
-
999 connections per hour is not very many. that would be 16 per minute or one about every 4 seconds. is your web site receiving that many page requests or is your code making multiple database connections each time it runs? you need to find out what your recent peak page requests per hour are and multiply that by at least five to come up with the minimum database connections per hour.
-
in case the op revisits this thread, let me introduce you to a programming pattern called - data driven design, where instead of writing, testing, and editing (every time you need to change anything) repeated regions of program logic that only differ in the values they operate on or produce, you define a data structure (array or database table) that holds the defining data that tells your simplified and general purpose code what to do. pseudo code example - // define a data map of the departments/positions and the redirect locations $dept_map['Admin']['HOD'] = 'admin/dash_admin.php'; $dept_map['Admin']['staff'] = 'admin/dash_admin.php'; $dept_map['ICT']['HOD'] = 'ICT/HOD/hod_dash.php'; $dept_map['ICT']['staff'] = 'ICT/staff/staff_dash.php'; //... repeat for the remaining departments and positions... $sql1 = // form and run your query using your chosen database functions and password hashing algorithm if(//user was found){ // log them in and redirect to the correct location $data = // fetch the row of data using your chosen database functions // you would want to set a session variable to remember who just logged in $_SESSION['user_id'] = $data['id']; // determine the redirect location - $department = $data['department']; $position = $data['position'] == "HOD" ? "HOD" : 'staff'; if(isset($dept_map[$departement][$position])){ $location = $dept_map[$departement][$position]; } else { $location = '.....'; // some url for a user who just logged in but doesn't have a valid department/position combination } } else { $location = 'indexWrongPassOrUser.php'; } header("Location: $location"); exit; to add/change/remove any of the values, you only alter the defining data, you don't touch the program logic. if the defining data is instead stored in a database table, rather than the array shown in this example, you would JOIN that table to your users table in the sql query statement, which will actually simplify the php code even more.
-
in your posted code (which is nothing like the actual form in an iframe at the link you posted), the form and your form processing code are on the same page and the error message about the undefined index is occurring before the form is submitted because there's no post data at that point. the line of code where the error is at is testing if the form has been submitted, but it first needs to test if $_POST['Submit'] exists/isset before it can test the value in it. change the line testing if($_POST['Submit'] == "Send") to the following to prevent the error - if(isset$_POST['Submit'] () && $_POST['Submit'] == "Send") { note: instead of relying on the submit button's name/value, you may want to make a hidden field in your form with name='Submit' value='Send' since not all browsers will send the submit button name/value for all possible methods of submitting the form.