RE: [PHP-DB] Insert, Arrays, & Null
Terrific! I tried an example assigning the array to a variable using the if-else statements before creating the query. Now the table contains values and NULLs. Is there something wrong about using the SET clause version? I like to see the assignments for each column/value side by side. Is there an advantage to using the VALUES clause? Thank you for your assistance. Zach -Original Message- From: Rick Emery [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 8:42 AM To: 'Zach Curtis'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Insert, Arrays, & Null Is there some reason you are using the SET-clause version of INSERT? Also, given that cusa, cusb, cusc are INTs, DO NOT enclose in single-quotes You can do as I've done in the past; check for value of cusa and create INSERT accordingly: -Original Message- From: Zach Curtis [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 9:29 AM To: Rick Emery; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Insert, Arrays, & Null The data being read dynamically into the array could contain values which are NULL (the default) or numeric (if a numeric value exits). However, the query is using a INSERT INTO and I can't seem to form this query to account for either a NULL or numeric value. Zach -Original Message- From: Rick Emery [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 8:18 AM To: 'Zach Curtis'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Insert, Arrays, & Null When you say "...account for either a numeric or NULL value ...", do you mean SELECT a value that could be NULL? If so, the query is "SELECT * FROM mytable WHERE cusa IS NULL || cusa >= 0" -Original Message- From: Zach Curtis [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 9:11 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Insert, Arrays, & Null I have attempted to insert data from an array into a table in which the values are string and numeric or NULL. The string values are no problem ($password, $int_id), but when I try to insert a value which may be either numeric or NULL (cusa, cusb, cusc) I can't produce a query that accounts for either a numeric or NULL value. I have tried various combinations of queries that include using ', ", and ., in the query, however those queries usually result in either NULL values not be inserted into the table, a parse error, or a failed query. # partial mysql table definition password CHAR(8) NOT NULL, int_id VARCHAR(4) NOT NULL, cusa TINYINT UNSIGNED NULL, cusb TINYINT UNSIGNED NULL, cusc TINYINT UNSIGNED NULL, PRIMARY KEY(password, int_id) // partial php script // *** // the following (example) values are variable b\c the data are being read into this script dynamically // alpha values $password = "test"; $int_id = "a"; // numeric or NULL values $data_array = array(); $data_array["cusa"] = NULL; // can be numeric or NULL $data_array["cusb"] = 0; // can be numeric or NULL $data_array["cusc"] = 9; // can be numeric or NULL // *** // this results in cusa = 0 in the table and not NULL $query = "INSERT INTO s999dat SET password='$password', int_id='$int_id', cusa='$cus_array[cusa]', cusb='$cus_array[cusb]', cusc='$cus_array[cusc]' "; Any thoughts on how I can create this query that can account for either a numeric or NULL value coming from the dynamic array? Thank you. _ Zach Curtis Programmer Analyst POPULUS www.populus.com _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Insert, Arrays, & Null
The data being read dynamically into the array could contain values which are NULL (the default) or numeric (if a numeric value exits). However, the query is using a INSERT INTO and I can't seem to form this query to account for either a NULL or numeric value. Zach -Original Message- From: Rick Emery [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 8:18 AM To: 'Zach Curtis'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Insert, Arrays, & Null When you say "...account for either a numeric or NULL value ...", do you mean SELECT a value that could be NULL? If so, the query is "SELECT * FROM mytable WHERE cusa IS NULL || cusa >= 0" -----Original Message- From: Zach Curtis [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 9:11 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Insert, Arrays, & Null I have attempted to insert data from an array into a table in which the values are string and numeric or NULL. The string values are no problem ($password, $int_id), but when I try to insert a value which may be either numeric or NULL (cusa, cusb, cusc) I can't produce a query that accounts for either a numeric or NULL value. I have tried various combinations of queries that include using ', ", and ., in the query, however those queries usually result in either NULL values not be inserted into the table, a parse error, or a failed query. # partial mysql table definition password CHAR(8) NOT NULL, int_id VARCHAR(4) NOT NULL, cusa TINYINT UNSIGNED NULL, cusb TINYINT UNSIGNED NULL, cusc TINYINT UNSIGNED NULL, PRIMARY KEY(password, int_id) // partial php script // *** // the following (example) values are variable b\c the data are being read into this script dynamically // alpha values $password = "test"; $int_id = "a"; // numeric or NULL values $data_array = array(); $data_array["cusa"] = NULL; // can be numeric or NULL $data_array["cusb"] = 0; // can be numeric or NULL $data_array["cusc"] = 9; // can be numeric or NULL // *** // this results in cusa = 0 in the table and not NULL $query = "INSERT INTO s999dat SET password='$password', int_id='$int_id', cusa='$cus_array[cusa]', cusb='$cus_array[cusb]', cusc='$cus_array[cusc]' "; Any thoughts on how I can create this query that can account for either a numeric or NULL value coming from the dynamic array? Thank you. _ Zach Curtis Programmer Analyst POPULUS www.populus.com _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Insert, Arrays, & Null
I have attempted to insert data from an array into a table in which the values are string and numeric or NULL. The string values are no problem ($password, $int_id), but when I try to insert a value which may be either numeric or NULL (cusa, cusb, cusc) I can't produce a query that accounts for either a numeric or NULL value. I have tried various combinations of queries that include using ', ", and ., in the query, however those queries usually result in either NULL values not be inserted into the table, a parse error, or a failed query. # partial mysql table definition password CHAR(8) NOT NULL, int_id VARCHAR(4) NOT NULL, cusa TINYINT UNSIGNED NULL, cusb TINYINT UNSIGNED NULL, cusc TINYINT UNSIGNED NULL, PRIMARY KEY(password, int_id) // partial php script // *** // the following (example) values are variable b\c the data are being read into this script dynamically // alpha values $password = "test"; $int_id = "a"; // numeric or NULL values $data_array = array(); $data_array["cusa"] = NULL; // can be numeric or NULL $data_array["cusb"] = 0; // can be numeric or NULL $data_array["cusc"] = 9; // can be numeric or NULL // *** // this results in cusa = 0 in the table and not NULL $query = "INSERT INTO s999dat SET password='$password', int_id='$int_id', cusa='$cus_array[cusa]', cusb='$cus_array[cusb]', cusc='$cus_array[cusc]' "; Any thoughts on how I can create this query that can account for either a numeric or NULL value coming from the dynamic array? Thank you. _ Zach Curtis Programmer Analyst POPULUS www.populus.com _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Why NULL?
Yes, I did not receive any replies to that message yesterday. Here is my code (condensed) as well. What ends up happening is that when I write a variable for a field that did have data, for example "cus034a", to the db it shows a value of "0" when I intended it to be "NULL". Thanks. Zach # partial table definition username CHAR(6) NOT NULL, password CHAR(8) NOT NULL, int_id VARCHAR(4) NOT NULL, cus034a TINYINT UNSIGNED NULL, cus034b TINYINT UNSIGNED NULL, cus034c TINYINT UNSIGNED NULL, sat01 TINYINT UNSIGNED NULL, PRIMARY KEY(password, int_id) // php script // INITIALIZE DATA ARRAY function initialize_data() { // create array to store record $data_array = array(); $data_array["username"] = ""; $data_array["password"] = ""; $data_array["int_id"] = ""; $data_array["cus034a"] = NULL; $data_array["cus034b"] = NULL; $data_array["cus034c"] = NULL; $data_array["sat01"] = NULL; ... ... ... return $data_array; } // CREATE ARRAY TO HOLD FLAT FILE $file_array = array(); $file_array = file(DAT_FILE); $count = count($file_array); if ($count == 0) echo "No records found in dat.cgi file."; // initialize data array $data_array = initialize_data(); // $i is the current element in the $file_array // LOOP THRU FLAT FILE while ($i < $count) { // extract header data $data_array["username"] = trim(substr($file_array[$i], 0, 12)); $data_array["password"] = trim(substr($file_array[$i], 12, 8)); $data_array["int_id"] = trim(substr($file_array[$i], 20, 4)); // extract response data for ($j = 0; $j < $data_array["num_responses"]; $j++) { $i++; $extract_array = explode(",", $file_array[$i]); if ($extract_array[0] == "cus034a") { $data_array["cus034a"] = $extract_array[1]; } elseif ($extract_array[0] == "cus034b") { $data_array["cus034b"] = $extract_array[1]; } elseif ($extract_array[0] == "cus034c") { $data_array["cus034c"] = $extract_array[1]; } elseif ($extract_array[0] == "sat01") { $data_array["sat01"] = $extract_array[1]; } ... ... ... else { echo "Could not process response data for int_id: $int_id" . "and password: $password recorded."; } } // end for // WRITE RECORD TO DB TABLE $date_time = date("Y-m-d H:i:s"); $result2 = mysql_query("INSERT INTO s999dat SET username= '". $data_array["username"] ."' , password= '". $data_array["password"] ."' , int_id= '". $data_array["int_id"] ."' , cus034a= '". $data_array["cus034a"] ."' , cus034b= '". $data_array["cus034b"] ."' , cus034c= '". $data_array["cus034c"] ."' , sat01= '". $data_array["sat01"] ."' , ... ... ... ); if (mysql_affected_rows() == 0) { echo "Error adding record to db." . "int_id: $int_id" . "and password: $password" . mysql_error() . ""; exit; } $i++; // INITIALIZE DATA ARRAY $data_array = initialize_data(); } // end while -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Why NULL?
I have a loop process that reads a record out of a flat file, stores the data for a given record in an array, writes the record to the db, resets the data in the array, then iterates again thru the loop. Not every record has a value for each field. For example, Not every record has a value for the field "cus034a". Since this is numeric type data, I do not want the value in the db to be "0" if there is no value for the field (it should be NULL). # partial table definition cus034a TINYINT UNSIGNED NULL, sat01 TINYINT UNSIGNED NULL, What I try to do is set the array to NULL values before iterating the loop again. However, if I do this and the next record does not have a value for "cus034a", the value in the db still ends up being "0". $data_array["cus034a"] = NULL; $data_array["sat01"] = NULL; I must be doing something wrong? Thank you. Zach Curtis POPULUS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] NULL Values
I have a loop process that reads a record out of a flat file, stores the data for a given record in an array, writes the record to the db, resets the data in the array, then iterates again thru the loop. Not every record has a value for each field. For example, Not every record has a value for the field "cus034a". Since this is numeric type data, I do not want the value in the db to be "0" if there is no value for the field (it should be NULL). # partial table definition cus034a TINYINT UNSIGNED NULL, sat01 TINYINT UNSIGNED NULL, What I try to do is set the array to NULL values before iterating the loop again. However, if I do this and the next record does not have a value for "cus034a", the value in the db still ends up being "0". $data_array["cus034a"] = NULL; $data_array["sat01"] = NULL; I must be doing something wrong? Thank you. Zach Curtis POPULUS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] # of Records in Table
You are incorrect regarding my appreciation of the help I receive from the list. I very much value the help received from everyone who is a contributor to the list. This is one of the reasons (of many) I chose to develop with PHP/MySQL. At this point in time I mainly receive help, however, when my knowledge and experience increases I hope to help those with questions. And the wheel goes round and round. Zach -Original Message- From: DL Neil [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 24, 2002 2:02 AM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table Zach, On the subject of sharing information we differ big-time: have you heard the story about the three blind men attempting to describe an elephant? Apparently you have failed to appreciate the self-help nature of the list. No one is paid to help you. However your behavior demands/evidences more goodwill and effort from your (several) correspondents than you have demonstrated yourself. "Relational" technology is all about the logical interrelationship between elements of data, both between tables and within a table. Perhaps some reading/revision is required. Accordingly without information about the subject-table, you are left with the two somewhat-artificial solutions offered: incremented field or timestamp as key, and a nagging feeling that wonders if there might be a 'better way'. You have just mentioned the serial file/data source. That opens a whole new avenue of attack! However time and goodwill can both be quickly exhausted. Let us know how you get on with the suggestions made so far, and if they don't work/you think there might be a better way, consider another approach for assistance. =dn - Original Message - From: "Zach Curtis" <[EMAIL PROTECTED]> To: "DL Neil" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: 24 January 2002 00:01 Subject: RE: [PHP-DB] # of Records in Table > There are many columns of data in the table. The only column that I would > like to extract a value from is the password field (this is the key as > well). I do not have an AUTO_INCREMENT field. Although, I see how adding > that field could be of use by using it with the SELECT MAX() as you > mentioned. > > The last record is whatever the last record was inserted using INSERT INTO. > To give you the overall picture of what I am trying to accomplish: > > 1) I am opening up a db table and searching for the password of the last > record in the table > 2) I then open a flat file and search for that password and grab the next > record after that (as records are appended to the end of the flat file) and > any other subsequent records added to the flat file > 3) Write those new records to the db table > > In this scenario, the last record would be the last record from the flat > file added to the db table. > > Another suggestion from [EMAIL PROTECTED] was to: > > Select your password field, and whatever other fields you need to > Use > -mysql_num_rows() to capture the number of rows returned > -mysql_data_seek() to position pointer on last row (remember indexing > starts at 0) > -mysql_fetch_row() or mysql_fetch_array(), your choice, to return the > data. > > This is done with one select statement, however all the passwords from the > table have to be loaded into array (perhaps not the most efficient way? But > better than what I had come up with.). > > I do generally find that the more brief I am in describing an issue, the > more likely I am to get a reply. Then details can be given if needed, in > further correspondences. > > I will give that AUTO_INCREMENT and SELECT MAX() a try as well. > > > Zach > > -Original Message- > From: DL Neil [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 23, 2002 3:27 PM > To: Zach Curtis > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] # of Records in Table > > > Zach, > We're going back and forth on this and getting no where... > > So far all you have informed us is that the table has one column, which > contains a bunch of passwords (I also > suggest that this is not really the case and there'll at least be some sort > of userId field - but you haven't > bothered to tell me/us that) > > The concept of "last" in relational terminology is ambiguous. Do you mean > last entered, or do you mean the row > with the field containing the highest value in the column - for example. > > Some people are used to the idea that there is also some 'phantom' rowId > that counts/labels each row. In other > file systems this might have been the case, but the physically last record > in an RDBMS table-file may not > conform to either of the "last" definitions menti
RE: [PHP-DB] # of Records in Table
There are many columns of data in the table. The only column that I would like to extract a value from is the password field (this is the key as well). I do not have an AUTO_INCREMENT field. Although, I see how adding that field could be of use by using it with the SELECT MAX() as you mentioned. The last record is whatever the last record was inserted using INSERT INTO. To give you the overall picture of what I am trying to accomplish: 1) I am opening up a db table and searching for the password of the last record in the table 2) I then open a flat file and search for that password and grab the next record after that (as records are appended to the end of the flat file) and any other subsequent records added to the flat file 3) Write those new records to the db table In this scenario, the last record would be the last record from the flat file added to the db table. Another suggestion from [EMAIL PROTECTED] was to: Select your password field, and whatever other fields you need to Use -mysql_num_rows() to capture the number of rows returned -mysql_data_seek() to position pointer on last row (remember indexing starts at 0) -mysql_fetch_row() or mysql_fetch_array(), your choice, to return the data. This is done with one select statement, however all the passwords from the table have to be loaded into array (perhaps not the most efficient way? But better than what I had come up with.). I do generally find that the more brief I am in describing an issue, the more likely I am to get a reply. Then details can be given if needed, in further correspondences. I will give that AUTO_INCREMENT and SELECT MAX() a try as well. Zach -Original Message- From: DL Neil [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 3:27 PM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table Zach, We're going back and forth on this and getting no where... So far all you have informed us is that the table has one column, which contains a bunch of passwords (I also suggest that this is not really the case and there'll at least be some sort of userId field - but you haven't bothered to tell me/us that) The concept of "last" in relational terminology is ambiguous. Do you mean last entered, or do you mean the row with the field containing the highest value in the column - for example. Some people are used to the idea that there is also some 'phantom' rowId that counts/labels each row. In other file systems this might have been the case, but the physically last record in an RDBMS table-file may not conform to either of the "last" definitions mentioned above. There is no such 'highest' in an RDBMS unless you put it there - as mentioned by another correspondent, it's a good idea to use some sort of 'id' field in every table. This can be generated for you with the AUTO_INCREMENT feature. With appropriate design, eg first record has id=1 and the succeeding records have id-s with ascending values, then you can use SELECT MAX() against the 'id' or possibly against the AUTO_INCREMENT feature. These commands are well documented - RTFM. Many tutorials with plenty of examples of authentication techniques exist on the PHP/MySQL web sites. Next time, please don't be so (repeatedly) parsimonious in the provision of information, if you expect/hope that someone is going to give their (free) time to help you out. (grumble) =dn - Original Message - From: "Zach Curtis" <[EMAIL PROTECTED]> To: "DL Neil" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: 23 January 2002 21:52 Subject: RE: [PHP-DB] # of Records in Table > The key field is the password field, which is also the field that I would > like to retrieve for that last record. > > > Zach > > -Original Message- > From: DL Neil [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 23, 2002 2:08 PM > To: Zach Curtis > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] # of Records in Table > > > Zach, > > How can this "last record" be identified? Is there a key field or something > similar? > > Again: We might need to see the table definition to answer this. > > Please advise, > =dn > > > - Original Message - > From: "Zach Curtis" <[EMAIL PROTECTED]> > To: "DL Neil" <[EMAIL PROTECTED]> > Sent: 23 January 2002 20:49 > Subject: RE: [PHP-DB] # of Records in Table > > > > The last record should be whatever the last record is in the table. For > > example, if there are 1000 records in the table which COUNT(*) will tell > me, > > how can I get the password for record 1000. The only thing I can do that > > would probably work is two query statements, one selecting COUNT(*) and > the > > other selecting "password". W
RE: [PHP-DB] # of Records in Table
Excellent. That is more efficient (one select statement) than what I was trying to do. Zach -Original Message- From: Miles Thompson [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 2:20 PM To: Zach Curtis; [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table Select your password field, and whatever other fields you need Use -mysql_num_rows() to capture the number of rows returned -mysql_data_seek() to position pointer on last row (remember indexing starts at 0) -mysql_fetch_row() or mysql_fetch_array(), your choice, to return the data. One select. One bit of relational theory I always ignore, but have come to appreciate as I gain experience, is the virtue of having a unique key on every table in a database. If that's a key I can rely on to steadily increase in value, so much the better. Hope this helps and gets you out of your fix - Miles Thompson At 01:52 PM 1/23/2002 -0700, Zach Curtis wrote: >The last record should be whatever the last record is in the table. For >example, if there are 1000 records in the table which COUNT(*) will tell me, >how can I get the password for record 1000. The only thing I can do that >would probably work is two query statements, one selecting COUNT(*) and the >other selecting "password". What I don't like about this method is that I >would have to retrieve all of the passwords into an array, which I would >assume would be slow on larger tables. Ideally, I thought their would be a >way to do this operation in one select statement. Any thoughts? > > >Zach > >-Original Message- >From: DL Neil [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, January 23, 2002 1:11 PM >To: Zach Curtis; [EMAIL PROTECTED] >Subject: Re: [PHP-DB] # of Records in Table > > >Zach, > > > What syntax can I use to determine how many records are in a MySQL table >and > > then retrieve the value of the field "password" for the last record? I >tried > > using some combinations of COUNT(*) and LIMIT with no success. > > >SELECT COUNT(*) will answer the first part. What did you try that lacked >success? > >How do you define "last record"? We might need to see the table definition >to answer this. > >Regards, >=dn > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] # of Records in Table
The key field is the password field, which is also the field that I would like to retrieve for that last record. Zach -Original Message- From: DL Neil [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 2:08 PM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table Zach, How can this "last record" be identified? Is there a key field or something similar? Again: We might need to see the table definition to answer this. Please advise, =dn - Original Message ----- From: "Zach Curtis" <[EMAIL PROTECTED]> To: "DL Neil" <[EMAIL PROTECTED]> Sent: 23 January 2002 20:49 Subject: RE: [PHP-DB] # of Records in Table > The last record should be whatever the last record is in the table. For > example, if there are 1000 records in the table which COUNT(*) will tell me, > how can I get the password for record 1000. The only thing I can do that > would probably work is two query statements, one selecting COUNT(*) and the > other selecting "password". What I don't like about this method is that I > would have to retrieve all of the passwords into an array, which I would > assume would be slow on larger tables. Ideally, I thought their would be a > way to do this operation in one select statement. Any thoughts? > > > Zach > > -Original Message----- > From: DL Neil [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 23, 2002 1:11 PM > To: Zach Curtis; [EMAIL PROTECTED] > Subject: Re: [PHP-DB] # of Records in Table > > > Zach, > > > What syntax can I use to determine how many records are in a MySQL table > and > > then retrieve the value of the field "password" for the last record? I > tried > > using some combinations of COUNT(*) and LIMIT with no success. > > > SELECT COUNT(*) will answer the first part. What did you try that lacked > success? > > How do you define "last record"? We might need to see the table definition > to answer this. > > Regards, > =dn > > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] # of Records in Table
The last record should be whatever the last record is in the table. For example, if there are 1000 records in the table which COUNT(*) will tell me, how can I get the password for record 1000. The only thing I can do that would probably work is two query statements, one selecting COUNT(*) and the other selecting "password". What I don't like about this method is that I would have to retrieve all of the passwords into an array, which I would assume would be slow on larger tables. Ideally, I thought their would be a way to do this operation in one select statement. Any thoughts? Zach -Original Message- From: DL Neil [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 1:11 PM To: Zach Curtis; [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table Zach, > What syntax can I use to determine how many records are in a MySQL table and > then retrieve the value of the field "password" for the last record? I tried > using some combinations of COUNT(*) and LIMIT with no success. SELECT COUNT(*) will answer the first part. What did you try that lacked success? How do you define "last record"? We might need to see the table definition to answer this. Regards, =dn -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] # of Records in Table
It does not. However, I could easily add this in if you have a suggestion that would work. Ideally, I thought their would be a way to do this operation in one select statement. Any thoughts? Zach -Original Message- From: Jim Lucas [php] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 1:10 PM To: Zach Curtis; [EMAIL PROTECTED] Subject: Re: [PHP-DB] # of Records in Table does the table have an autoincrement column? Jim Lucas - Original Message - From: "Zach Curtis" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, January 23, 2002 10:27 AM Subject: [PHP-DB] # of Records in Table > What syntax can I use to determine how many records are in a MySQL table and > then retrieve the value of the field "password" for the last record? I tried > using some combinations of COUNT(*) and LIMIT with no success. > > Thanks. > > > Zach Curtis > POPULUS > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Decrypting PASSWORD() from MySQL
This is how I'm going to work things. Store the password using PASSWORD() in the table. Allow user to request their forgotten username and/or password. If the password is requested, I will reset the password to a random value and store this in the table using PASSWORD(). The username and/or password will then be emailed to the user. I will also provide a location where the user can change their password once they are authenticated in the members area. I think this approach allows the password to maintain a certain level of security and give the user the greatest flexibility on maintaining their password. Zach -Original Message- From: matt stewart [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 20, 2001 2:19 AM To: 'Zach Curtis'; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Decrypting PASSWORD() from MySQL I would go for the "generate new random password" approach - email the new random password to the registered email address, then they can log in using it and reset it to whatever they want. probably easier than using lots of code encrypting and decrypting things? Let me know what you decide on, and if you do enc/decrypt stuff, i'd be interested in seeing the code for a similar thing myself! Matt -----Original Message- From: Zach Curtis [mailto:[EMAIL PROTECTED]] Sent: 19 December 2001 20:27 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Decrypting PASSWORD() from MySQL Thanks for the suggestions. I guess I can try to: A) Store the password in plaintext if I need to retrieve the password. B) Store the password using PASSWORD() and then generate a new random password if needed, replacing the old password. C) Look into mcrypt, ENCODE()/DECODE(), encipher/decipher Thanks, Zach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 19, 2001 12:56 PM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Decrypting PASSWORD() from MySQL Yet another example of ted's out-to-lunchness... Use the mcrypt functions on the password... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.307 / Virus Database: 168 - Release Date: 11/12/01 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.307 / Virus Database: 168 - Release Date: 11/12/01 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Decrypting PASSWORD() from MySQL
Thanks for the suggestions. I guess I can try to: A) Store the password in plaintext if I need to retrieve the password. B) Store the password using PASSWORD() and then generate a new random password if needed, replacing the old password. C) Look into mcrypt, ENCODE()/DECODE(), encipher/decipher Thanks, Zach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 19, 2001 12:56 PM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Decrypting PASSWORD() from MySQL Yet another example of ted's out-to-lunchness... Use the mcrypt functions on the password... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Decrypting PASSWORD() from MySQL
Fortunately, this application is still in testing, therefore the users and passwords in the db are meaningless. However, I thought storing encrypted passwords in a db was a good idea, that is if can retrieve the decrypted password. Can this be done? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 19, 2001 12:29 PM To: Zach Curtis Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Decrypting PASSWORD() from MySQL Well, it's (intended to be) difficult. Perhaps you can NULL it out and have them put in a new password... On Wed, 19 Dec 2001, Zach Curtis wrote: > I have a form for a user to request their forgotten username and password by > entering their email address. I then process this and use mail() to send > them their username and password. However, the password is stored in an > encrypted PASSWORD('password') field in the MySQL table. How can I retrieve > the decrypted password in a SELECT statement? > > For example, the following results in retrieving the encrypted password. > > $result = mysql_query("SELECT userName,password,email FROM members WHERE > email='$email'"); > if (!$result) > echo "Could not execute database query:" . > mysql_error() . ""; > > $row = mysql_fetch_array($result); > $userName = "$row[userName]"; > $password = "$row[password]"; > $email = "$row[email]"; > > > Thank you. > > > Zach Curtis > Programmer/Analyst > POPULUS > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Decrypting PASSWORD() from MySQL
I have a form for a user to request their forgotten username and password by entering their email address. I then process this and use mail() to send them their username and password. However, the password is stored in an encrypted PASSWORD('password') field in the MySQL table. How can I retrieve the decrypted password in a SELECT statement? For example, the following results in retrieving the encrypted password. $result = mysql_query("SELECT userName,password,email FROM members WHERE email='$email'"); if (!$result) echo "Could not execute database query:" . mysql_error() . ""; $row = mysql_fetch_array($result); $userName = "$row[userName]"; $password = "$row[password]"; $email = "$row[email]"; Thank you. Zach Curtis Programmer/Analyst POPULUS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Converting Date Form Fields
Ah, the join function...I see implode() will also perform the same task. That was what I needed to do. Thanks! Zach -Original Message- From: matt stewart [mailto:[EMAIL PROTECTED]] Sent: Friday, November 16, 2001 9:06 AM To: 'Zach Curtis'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Converting Date Form Fields put them into an array $date_stuff[0] = $date_year; $date_stuff[1] = $date_month; $date_stuff[2] = "01"; $date_to_enter = join('-',$date_stuff); then whack $date_to_enter into your database - obviously if the input to $date_month is "Jan", you need a case statement, or something like that to make sure you change it to "01". Hope it helps ;) Matt -Original Message- From: Zach Curtis [mailto:[EMAIL PROTECTED]] Sent: 16 November 2001 16:02 To: [EMAIL PROTECTED] Subject: [PHP-DB] Converting Date Form Fields I have two HTML form fields birthMonth (e.g., Jan=1, Feb=2...) and birthYear (e.g., 2001=2001, 1999=1999...). How can take these two individual form fields, then add in a default value of "1" for the birthDay (this is not asked in the form), and put this data into a MySQL table field birthDate with field type DATE (-MM-DD)? The part I do not know how to accomplish is taking these form fields and then combining them into a date field/format. Thank you. Zach Curtis POPULUS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.295 / Virus Database: 159 - Release Date: 01/11/01 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.295 / Virus Database: 159 - Release Date: 01/11/01 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Converting Date Form Fields
I have two HTML form fields birthMonth (e.g., Jan=1, Feb=2...) and birthYear (e.g., 2001=2001, 1999=1999...). How can take these two individual form fields, then add in a default value of "1" for the birthDay (this is not asked in the form), and put this data into a MySQL table field birthDate with field type DATE (-MM-DD)? The part I do not know how to accomplish is taking these form fields and then combining them into a date field/format. Thank you. Zach Curtis POPULUS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]