PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello,
I'm trying to write PHP that will create a table with a name provided by an HTML form (easy). And then I want to populate the table with 5000 rows which contain random values for the user and pw fields.
Here's what I have so far:
mysql_query("CREATE TABLE $album (
id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
user VARCHAR( 255 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
pw VARCHAR( 255 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
) ENGINE = MYISAM CHARACTER SET ASCII COLLATE ascii_bin")
echo "Album successfully added!";
I'm stuck with how to insert rows with random data for the user and pw fields. I've found code like this for generating randomness:
mc3 wrote:Hello,
I'm trying to write PHP that will create a table with a name provided by an HTML form (easy). And then I want to populate the table with 5000 rows which contain random values for the user and pw fields.
Here's what I have so far:
mysql_query("CREATE TABLE $album (
id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
user VARCHAR( 255 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
pw VARCHAR( 255 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
) ENGINE = MYISAM CHARACTER SET ASCII COLLATE ascii_bin")
echo "Album successfully added!";
I'm stuck with how to insert rows with random data for the user and pw fields. I've found code like this for generating randomness:
INSERT INTO $album
(user, pw)
VALUES
(SUBSTRING(MD5(RAND()) FROM 1 FOR 6), SUBSTRING(MD5(RAND()) FROM 1 FOR 6)),
(SUBSTRING(MD5(RAND()) FROM 1 FOR 6), SUBSTRING(MD5(RAND()) FROM 1 FOR 6)), etc, etc, etc
how ever many times you need rows.
I cant think of how to loop it X number of times using sql though.
Hmmmm...seems like this should work but it's not. It's printing "record added" 5000 times, which is a good sign that it's working but my table is not being updated.