RE: [PHP] Inserting Processed Data from One Table 2 Another!
Ok ths is great, a lovely Random Code Generator! Thanks a lot. I always wanted one of these. Actually my problem was a little different, but i was able to solve it. I was using $result twice to store to different SQL Queries, i changed the other one to $result2 and it worked. But in fact, i will now change my code to generate the Random Number which of course is much better! Thanks... T. Edison Jr. --- Wouter van Vliet [EMAIL PROTECTED] wrote: I don't see why your code is so wrong but neither do I see what it reall does. YOu are changing the clientID with some simple function into a password? As in everybody can do that trick by himself and login as whoever he wants .. What I'll mostly do for such things, is use this self written function to generate a random string and use this as generated password. it takes an integer as argument, and gives back a random code with only [A-Z][a-z] characters of a length of the given argument. And then, I'd just use the loop to roll through the ID's and insert a random code password. function generateRandomString($length) { srand ((float) microtime() * 100); for ($i=65;$i91;$i++) { $chars[] = chr($i); }; for ($i=97;$i122;$i++) { $chars[] = chr($i); }; $chrs = count($chars) - 1; for ($i=0; $i$length; $i++) { $asc = rand(0, $chrs); $code .= $chars[$asc]; }; return $code; }; $result = mysql_query(SELECT clientid FROM Clientdetails); while ($myrow = mysql_fetch_assoc($result)) { $code = generateRandomString(8); mysql_query(INSERT INTO authentication (id, pass) VALUES ($myrow[clientid], '.$code.'); }; Hope this helped you ! Greetz, Wouter -Oorspronkelijk bericht- Van: Thomas Edison Jr. [mailto:[EMAIL PROTECTED]] Verzonden: woensdag 24 juli 2002 9:02 Aan: [EMAIL PROTECTED] Onderwerp: [PHP] Inserting Processed Data from One Table 2 Another! Ok i have simple issue, i'm stuck at one point. I have a table Clientdetails which contains ClientID. I have created another table Authentication with 2 fields, ClientID and Password. I want to pick up the ClientID from table Clientdetails and insert ClientID and a Password i have generated using a code, into Authentication. So if there are 13000 ClientID's in Clientdetails, as, many rows with the ClientID it's corresponding password should be Inserted into table Authentication. I'm using the following code which i know is wrong, what would be correct? ? $db = mysql_connect(localhost,user,pwd); mysql_select_db(myDB,$db); $result = mysql_query(SELECT * FROM clientdetails,$db); if ($myrow = mysql_fetch_array($result)) { do { $some = $myrow[clientid] $newid = eregi_replace('100', '', $myrow[clientid]); $date = date(dn); $stuff = $newid.def.$date; $sql = INSERT INTO authentication VALUES('$some','$stuff'); $result = mysql_query($sql); echo All Done!; } while ($myrow = mysql_fetch_array($result)); } ? Thanks, T. Edison Jr. __ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Inserting Processed Data from One Table 2 Another!
Ok i have simple issue, i'm stuck at one point. I have a table Clientdetails which contains ClientID. I have created another table Authentication with 2 fields, ClientID and Password. I want to pick up the ClientID from table Clientdetails and insert ClientID and a Password i have generated using a code, into Authentication. So if there are 13000 ClientID's in Clientdetails, as, many rows with the ClientID it's corresponding password should be Inserted into table Authentication. I'm using the following code which i know is wrong, what would be correct? ? $db = mysql_connect(localhost,user,pwd); mysql_select_db(myDB,$db); $result = mysql_query(SELECT * FROM clientdetails,$db); if ($myrow = mysql_fetch_array($result)) { do { $some = $myrow[clientid] $newid = eregi_replace('100', '', $myrow[clientid]); $date = date(dn); $stuff = $newid.def.$date; $sql = INSERT INTO authentication VALUES('$some','$stuff'); $result = mysql_query($sql); echo All Done!; } while ($myrow = mysql_fetch_array($result)); } ? Thanks, T. Edison Jr. __ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Inserting Processed Data from One Table 2 Another!
I don't see why your code is so wrong but neither do I see what it reall does. YOu are changing the clientID with some simple function into a password? As in everybody can do that trick by himself and login as whoever he wants .. What I'll mostly do for such things, is use this self written function to generate a random string and use this as generated password. it takes an integer as argument, and gives back a random code with only [A-Z][a-z] characters of a length of the given argument. And then, I'd just use the loop to roll through the ID's and insert a random code password. function generateRandomString($length) { srand ((float) microtime() * 100); for ($i=65;$i91;$i++) { $chars[] = chr($i); }; for ($i=97;$i122;$i++) { $chars[] = chr($i); }; $chrs = count($chars) - 1; for ($i=0; $i$length; $i++) { $asc = rand(0, $chrs); $code .= $chars[$asc]; }; return $code; }; $result = mysql_query(SELECT clientid FROM Clientdetails); while ($myrow = mysql_fetch_assoc($result)) { $code = generateRandomString(8); mysql_query(INSERT INTO authentication (id, pass) VALUES ($myrow[clientid], '.$code.'); }; Hope this helped you ! Greetz, Wouter -Oorspronkelijk bericht- Van: Thomas Edison Jr. [mailto:[EMAIL PROTECTED]] Verzonden: woensdag 24 juli 2002 9:02 Aan: [EMAIL PROTECTED] Onderwerp: [PHP] Inserting Processed Data from One Table 2 Another! Ok i have simple issue, i'm stuck at one point. I have a table Clientdetails which contains ClientID. I have created another table Authentication with 2 fields, ClientID and Password. I want to pick up the ClientID from table Clientdetails and insert ClientID and a Password i have generated using a code, into Authentication. So if there are 13000 ClientID's in Clientdetails, as, many rows with the ClientID it's corresponding password should be Inserted into table Authentication. I'm using the following code which i know is wrong, what would be correct? ? $db = mysql_connect(localhost,user,pwd); mysql_select_db(myDB,$db); $result = mysql_query(SELECT * FROM clientdetails,$db); if ($myrow = mysql_fetch_array($result)) { do { $some = $myrow[clientid] $newid = eregi_replace('100', '', $myrow[clientid]); $date = date(dn); $stuff = $newid.def.$date; $sql = INSERT INTO authentication VALUES('$some','$stuff'); $result = mysql_query($sql); echo All Done!; } while ($myrow = mysql_fetch_array($result)); } ? Thanks, T. Edison Jr. __ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Inserting Processed Data from One Table 2 Another!
You might want to consider a slightly different approach - that being to use your php code to generate a delimited file of your data and use either mysqlimport from the command line if you can, or the LOAD DATA INFILE sql statement to load the file into your database. That's going to be a lot faster than running 13000 queries through your php script. ..mike.. On Wed, 2002-07-24 at 00:01, Thomas Edison Jr. wrote: Ok i have simple issue, i'm stuck at one point. I have a table Clientdetails which contains ClientID. I have created another table Authentication with 2 fields, ClientID and Password. I want to pick up the ClientID from table Clientdetails and insert ClientID and a Password i have generated using a code, into Authentication. So if there are 13000 ClientID's in Clientdetails, as, many rows with the ClientID it's corresponding password should be Inserted into table Authentication. I'm using the following code which i know is wrong, what would be correct? ? $db = mysql_connect(localhost,user,pwd); mysql_select_db(myDB,$db); $result = mysql_query(SELECT * FROM clientdetails,$db); if ($myrow = mysql_fetch_array($result)) { do { $some = $myrow[clientid] $newid = eregi_replace('100', '', $myrow[clientid]); $date = date(dn); $stuff = $newid.def.$date; $sql = INSERT INTO authentication VALUES('$some','$stuff'); $result = mysql_query($sql); echo All Done!; } while ($myrow = mysql_fetch_array($result)); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php