-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
the change you made indicates that $d['user_id'] contains some single-quotes that are part of the sql syntax. it is generally best if data is the only thing in variables and any syntax that is part of the query is only in the query statement. i'm guessing you are using DreamWeaver produced code?
-
your $d['user_id'] value probably contains something that is breaking the sql syntax. you need to ALWAYS form your sql query statement in a php variable so that you can echo/log what your query is for debugging purposes. also, your or die(...) statement on the end of the mysql_fetch_array( ) statement means that your code will die when the query doesn't match any rows. you need the or die () statement on the end of the msyql_ query() statement so that it will only trigger the die statement when the query fails due to an error and in fact the error you are getting in this case may be from a previous query statement and that the only thing wrong with the code posted in this thread is that it isn't matching any row in your database table. fix the code so that the or die(...) statements are on the mysql_query() statements and report back of you are still getting any errors from the posted code. lastly, the posted code inside each conditional statement looks identical to me. there's no point in repeating the same query and same result logic just because you have different input values.
-
How do I convert a csv file to xml in php?
mac_gyver replied to saywhatyousee's topic in PHP Coding Help
what have you tried? can you even read the csv file and access the data for each row? have you tried to even create the output file? exactly where are you stuck at in doing this? -
you need to start with the basics and learn some amount of the php/html/mysql language before you can use or write code that does something. by just trying things without knowing that meaning of each statement/line in it, leads to a lot of wasted time and frustration when trying to program. a) the code you found or were given as a starting place is 11 years out of date. i won't waste the time mentioning what about it won't work at all under the latest php version, because php.net has documented what has changed in the language over time and this information can be found on their php web site. b) that fact that you have posted the path to your files as file:///C:/Users/Stahlsta/Desktop/PHP/.... indicates two things. first, you are probably directly opening the files using those paths in your browser. this won't work because php is a server side scripting language and requires that the URL used when requesting the files (or submitting a form) involve php on the web server. second, since there is no mention of a htdocs or document root folder in those paths, you likely don't have a web server with php installed on your local development system or if you do, you haven't placed your files into the htdocs folder under that web server. the URL you would use in your browser for any of your pages on a local development system would be similar to http://localhost/file_name.ext c) the loginsuccess.php code, in addition to not working at all in the latest php version, is not secure as you need an exit; statement after the header() redirect to prevent the protected code on the rest of the page from running. it's the browser that is performing the redirect. all anyone needs to do to stay on that page is ignore the redirect. d) that whoever wrote this code named the files and database tables like - KitchenDatabase.php, `Fridge`, ... rather than general names indicating the purpose of the file, means that this code is at best leftover (pun intended) from a classroom assignment and shouldn't be the basis for your login code. file names/table names should indicate their general usage (i.e. user, product...), not actual categories of the data within them. e) the script you found is missing in some basic functionally for even a minimal login script - the passwords need to be hashed (preferably with a random salt for each user) and the form processing code needs to start with at least some logic to test if a form has been submitted. f) lastly, the mysql_ functions are depreciated starting in php5.5 and should not be used when writing new code (or learning php) as they will need to all be replaced in the future. see this link - http://www.php.net/manual/en/mysqlinfo.api.choosing.php
-
finding the array key containing highest value
mac_gyver replied to Richard_Hollenbeck's topic in PHP Coding Help
you would combine max() with array_search() should (untested) work - $key = array_search (max($arr), $arr); -
to find birthdays between a range, you would need to test the month and day only. assuming your StaffDOB is actually a mysql DATE data type, so that you can use mysql's date functions on it, your WHERE term would be - WHERE DATE_FORMAT(StaffDOB,'%m%d') BETWEEN DATE_FORMAT(CURDATE(),'%m%d') AND DATE_FORMAT(CURDATE() + INTERVAL 14 DAY,'%m%d')
-
the code/book/tutorial/course you have found to learn php from is 11 years out of date. you need to find an up to date source. the php.net documentation is a good place to start.
-
changing PHP num_rows method to SQL COUNT
mac_gyver replied to paddy_fields's topic in PHP Coding Help
you can shorten - $findCount = $result->fetch_assoc(); $totalJobCount = $findCount['jobCount']; to be - list($totalJobCount) = $result->fetch_row(); -
what is your actual database table definition? if the date/time columns are actually character/text type and don't have leading zeros on the values, the comparisons won't work.
-
Get affected rows after Delete (mysql)
mac_gyver replied to fivestringsurf's topic in PHP Coding Help
i have seen (past) cases with mysql/mysqli functions where using them in a return statement returns null (which would be treated as a zero.) you can try to assign the value to a variable, then return that variable. also, it's possible that your page is being requested twice by your browser and/or a redirect and you are seeing the result of the second page request, which would be a zero since the row would have been deleted on the first page request. you could run a select query before trying to delete it to insure it exists. this would at least get your code to tell you if it has previously been deleted. -
Solving Search function with pagination problem
mac_gyver replied to tapantor24's topic in PHP Coding Help
i recommend using http_build_query() to build the url query string from various different sources (i.e. a search value and pagination values) - ref: http://it1.php.net/http_build_query -
Solving Search function with pagination problem
mac_gyver replied to tapantor24's topic in PHP Coding Help
web servers are stateless. they don't have any idea what happened on any page request before or after the current one. you $phone value will only exist on the page request that the search form was submitted to. you need to pass the $phone value in the pagination links so that it is available on those page requests. -
without knowing the context and scope of the problem, it's not possible to directly provide an answer. but short-answer - database tables are for storing data, one data item per row. each row holds the relevant - who, what, when, where, why... information about that one piece of data, so that at any time you can query for one or more specific pieces of data out of that table. one of the red flags for a bad (difficult as possible) code/data design is a series of numbered variables/columns/fields. that says that similar/same meaning code/data is being treated separately instead of being treated with the same meaning.
-
the better way is to -
-
my reply has nothing to do with your question, but your code shows that you are trying to find the first empty column to store a value in. this is a bad database design that results in overly complicated queries and code. you need to store one piece of data per row in your database table. then storing or finding the data becomes simple.
-
since using or die() or or trigger_error() doesn't address the execution path the code takes when there is an error, unless you want your code to die() or use E_USER_ERROR with trigger_error(), using an or die() or or trigger_error() are only best used for troubleshooting purposes and it doesn't really matter which one you use in that case. actual code needs to address the execution path that is taken when there is an error, either through conditional logic or by using exceptions.
-
is this image just a pattern to style the empty cells/region or is it a specific image that conveys some information, such as a picture of something? for the first case, set the cellspacing of the table to zero and use a css class to set the background-image of the empty cells to be the url of your pattern image.
-
your make_safe method is probably breaking the sql. a) what is the code of you make_safe method? b) you should be escaping the data values being put into the query, not the entire query.
-
Best way to test my PHP code for inefficiency?
mac_gyver replied to njdubois's topic in PHP Coding Help
here's a thought concerning random unexplained page wait/hanging that seem to come/go related to code changes. if you are using session variables and have multiple requests made to the server by the same visitor's browser session, doing things like ajax requests to pages that have session start statements or dynamically producing and outputting images/media files that also have session start statements in the code, you may be having a session data file locking problem, where the visitor's session data file is being accessed by one request and additional requests wait/hang until the first request finishes and releases the lock on the session data file. -
you have an errant semi-colon ; that is terminating the while(){} loop - while (list($id, $tob) = mysqli_fetch_row($res)); { that line should be - while (list($id, $tob) = mysqli_fetch_row($res)){
-
what is your current php code and what is the resulting 'view source' of the <select> ... </select> section of the output in your browser?
-
Best way to test my PHP code for inefficiency?
mac_gyver replied to njdubois's topic in PHP Coding Help
this is just a general throwing out ideas about those two symptoms. if you have a database driven design that is on the edge of working/not working due to the amount of resources/processing/queries it uses, as the amount of data and/or the amount of visitors grow (or you are on a busy shared server where other accounts are also using the database resources), you will reach the point where the amount of processing time required exceeds the amount available. a big inefficiency is running queries inside of loops (or running queries when you don't need to), because each query you run (or each prepared query you provide data for and run) requires that the query statement or the data to be sent from php to the database server and for most simple queries, the time taken just to communicate the information is much longer than the time it actually takes for the query to run on the database server. insuring you are running only the queries you need and that those queries use appropriate indexes are the two biggest things you have within your control that affect how efficient your code uses database resources. also, doing things like having frequent ajax requests that cause queries to be performed or perhaps having the same query executed frequently, but the database server doesn't have the query cache on or set to a large enough size or perhaps queries that return a huge result that fills the cache and other queries that could have used cached results must wait for the actual query to run and retrieve the data. these and a bunch more things affect how much resources your code uses. specific help requires knowing exactly what your code/queries are doing and how frequently they are doing it. -
you need to do a 'view source' of your page in your browser when it dies, because the php/mysql error message is inside of a html <select></select> tag and won't be displayed in the content on the page (another reason to separate your business logic from your presentation logic.)
-
Newbie needing help: Table causes "syntax" error
mac_gyver replied to LDMartin1959's topic in PHP Coding Help
that's an incorrect statement. the query is failing due to an error (probably because the numerical $_GET variable is empty, but could be a half dozen other things.) a query that runs but matches zero rows does not produce errors like this when you call the fetch functions. edit: of the mysql_ functions, only mysql_result() will produce an error when there are no rows in the result set due to the data seek it performs. -
you need to find out exactly what is causing the problem. start by setting php's error reporting to E_ALL (that would let you know if the variables are not defined) and checking if the query is actually failing (the code might be reusing the $r variable inside the loop.) your system apparently has php's error_reporting turned on, but it might not be set to E_ALL. add the following statements, immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(-1); next change the line - $r = mysql_query($q); to the following - $r = mysql_query($q) or die(mysql_error());