-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
If you are serious about making a real application (something that will be used outside of a programming classroom assignment), your first step will be to store your dates as a DATE data type. As you have discovered by attempting to write the query in your first post in this thread, NOT using the data type that was designed for a specific purpose results in writing more difficult code and queries that take longer to execute. Using a DATE data type will result in less storage requirements, faster queries, and simpler code. You can use the mysql STR_TO_DATE() function directly in a query to INSERT any starting date format into a DATE data type (you can also use the STR_TO_DATE() function to populate a new DATE column from your existing data.) Or you can produce a DATE data type in your php code at the same time you are validating the supplied data values. You can use the msyql DATE_FORMAT() function directly in a query to format a DATA data type as any format you want.
-
UPDATE members SET last_report_n = STR_TO_DATE(last_pirep,'%m.%d.%Y')
-
Same concept as used in your other thread dealing with converting dates - UPDATE your_table SET time_column = TIME(CONCAT(other_column,'00'));
-
Kind of depends of where the data is now and where you want to get it to. Do you want to do this when you import CSV data or is it already in a column in a table and you want to set an actual column to the converted valued?
-
Insert Date from PHP form into MySQL date column
PFMaBiSmAd replied to mtnmchgrl's topic in PHP Coding Help
-
The value in $search has a length that matches the visible characters. Are you sure you have data that matches that value and are you executing that exact same query directly against your database when it does return results? Using LIKE 'xxxxx' for an exact match is unusual (there are minor differences between a LIKE and an = comparison.) Have you tried an = comparison - WHERE Appr_Value.Account = {$search} (try both without and with single-quotes around the value) What is the definition of that column in your database table?
-
Insert Date from PHP form into MySQL date column
PFMaBiSmAd replied to mtnmchgrl's topic in PHP Coding Help
That's a typo. An empty action="" attribute refers to the same page, so it does not matter. You should remove the addTournament2.php that is outside of the <form > tag. -
nevermind.
-
An UPDATE query that does not have a WHERE clause will match and therefore operate on all rows in your table. You don't even need any php code as you can execute the query directly against your database using your favorite database management tool.
-
Given that the function is not present in the php version you are using and the code won't work at all, the solution is to update the code to current php standards. Ref: http://en.wikipedia.org/wiki/Deprecation
-
$result will only be false if the query fails due to an error (sql syntax, database problem...) If the query executes without error, even if there are zero matching rows in the result set, $result will contain a result resource and pass the tests in your code. You need to test the number of rows returned by the query.
-
Insert Date from PHP form into MySQL date column
PFMaBiSmAd replied to mtnmchgrl's topic in PHP Coding Help
Your INSERT query has a number of syntax problems. Your code should have basic error checking and error reporting logic to get it to at least tell you when the query fails. The problems - 1) Single-quotes around column names make them strings, not column names. 2) Single-quotes around NULL makes it the string 'NULL' not the NULL keyword. 3) You have () around two of the values. Assuming the format in the $_POST variable is yyyy-mm-dd and you are going to take care of validating it and escaping it before putting it into the query. This will work - $query="insert into tournaments (tourneyID, tourneyName, gameDate) values (NULL,'{$_POST['tourneyName']}', '{$_POST['gameDate']}')"; -
The cookie you use for authentication purposes should only identify the visitor (you keep the logged in/logged out status only on the server) and it should not identify the visitor using an easy to guess or produce value, such as a username or a sequential user id number. I would recommend that you generate a unique id (http://us2.php.net/manual/en/function.uniqid.php) for each user and store that in the cookie and with the user information in your user table. You would then use that unique id from the cookie to identify the visitor and match his row in the user table. If the user table says he is currently logged in, you could then set a session variable to indicate that the current visitor is logged in.
-
Edit: Basically says the same as above ^^ session_register(), session_is_registered(), and session_unregister() were depreciated 8 years ago, finally throw a depreciated error in php5.3, and have been completely removed in php6. You should not even know there is a function named session_register(). Either someone disabled it in your php version or you are using php6. To set or reference a session variable, you use the $_SESSION array (also requires a session_start() statement on any page the sets or references a session variable) - $_SESSION['some_name'] = some_value; if(isset($_SESSION['some_name'])){ // do something if the variable is set echo $_SESSION['some_name']; }
-
Insert Date from PHP form into MySQL date column
PFMaBiSmAd replied to mtnmchgrl's topic in PHP Coding Help
What format are you entering in the form? You would not necessarily use the mysql date_format() function as its' purpose is to take a DATE value and produce another format from it. Your current problem is because the first parameter in the date_format() would need to be enclosed in single-quotes if it is not a column name or another mysql function. However, you might look at the STR_TO_DATE() function if the format from the form is not yyyy-mm-dd. Date values are strings and need to be enclosed in single-quotes in the query (unless you are using a mysql function that returns a string or a column that is a DATE type.) If the $_POST variable is in the correct format, you would just need to enclose it in single-quotes inside the query string and not use any mysql functions with it. Eventually, you should be validating the format in the post variable and escaping it to prevent sql injection. -
The suggestion to post your code properly in the forum was so that more of the helpful forum members would even look at it. Posting code using the code /code tags also adds highlighting that usually helps point out where something is wrong in a file.
-
If you post any more code, please post it between the forum's tags. See the # button in the forum's menu to put tags around selected text when you are writing your post.
-
That would cause the query to check if you are online, not if your friend is online. Should work - ON ud.userId = uf.friend_userId
-
Help - My $_SESSION vars are being lost after a HEADER.
PFMaBiSmAd replied to cjp_24's topic in PHP Coding Help
Any chance that your staring page is sometimes with the www. (hostname/subdomain) on the URL and sometimes without the www. on the URL but your header() redirect specifically matches only one version of the hostname/subdomain and the times it works is when the starting URL and redirect have the same hostname/subdomain and the times it does not work is when the starting URL and redirect don't have the same hostname/subdomain? -
You can (simply) use the mysql STR_TO_DATE() function in the UPDATE query to convert any textual format date into a mysql DATE value - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date
-
I don't see a question, problem, or error mentioned, but if it was something like "The second while() loop is being skipped, how do I reset the result resource row pointer back to the beginning so that the second loop will reuse the result from the query?", the answer would be to see this link - mysql_data_seek
-
You cannot include php code using a URL. You must use a file system path. A URL causes a HTTP request for the file, the same as if you browsed to it. You only receive any HTML output from that file (not to mention it takes 50-100 times longer for a HTTP request than it does reading the file through the file system.)
-
What does a phpinfo() statement show for your error_reporting and display_errors settings?
-
Why is logged in status not getting set?
PFMaBiSmAd replied to twilitegxa's topic in PHP Coding Help
The code Andy-H posted contains a fatal parse error (which will let you test if you successfully turn on the two settings I suggested.) Fatal parse errors result in blank pages when the error_repoting/display_errors settings are not the suggested values (for development/debugging.) It is also using !isset() for the name/password form fields, which won't work because the form fields will be set simply because they exist in the form (your original code was correctly using empty().) -
Beginner creating a user registration page
PFMaBiSmAd replied to bobby317's topic in PHP Coding Help
You need to post your code between the forum's or tags. See the or buttons in the forum's menu to put the or tags around selected text when you are writing your post.