 |
|
|
02-18-2010, 12:38 AM
|
loop
|
Posts: 6
Name: john
|
Hello,
I am trying to make a simple POST form where the user inserts a number, that number is then sent over to my php file where it will run my mysql_query as many times as the user specified. anyone know how I can accomplish this?
index.html
Code:
<form action="insert.php" method="post">
Number of users? 250 max <input type="text" name="user" />
<input type="submit" />
</form>
insert.php
Code:
mysql_query("INSERT INTO signup (email, username, pwd, gender, addtime, logintime)
VALUES ('$emails', '$fname', '120b6602eff2164ce0d131b597e4449e', 'Male', '1263160374', '1263679544')");
This isnt the full source of course although this is the statement i need to loop
thanks in advance 
|
|
|
|
02-18-2010, 01:44 AM
|
Re: loop
|
Posts: 54
Name: Madars
Location: Latvia
|
PHP Code:
for($i=0;$i<$_POST['user'];$i++) { //do your stuff }
|
|
|
|
02-18-2010, 11:51 AM
|
Re: loop
|
Posts: 6
Name: john
|
Quote:
Originally Posted by Mad182
PHP Code:
for($i=0;$i<$_POST['user'];$i++) { //do your stuff }
|
So like this?
PHP Code:
for($i=0;$i<$_POST['user'];$i++) {
mysql_query("INSERT INTO signup (email, username, pwd, gender, addtime, logintime) VALUES ('$emails', '$fname', '120b6602eff2164ce0d131b597e4449e', 'Male', '1263160374', '1263679544')");
}
|
|
|
|
02-18-2010, 11:59 AM
|
Re: loop
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
You should validate that input:
PHP Code:
if(is_numeric($_POST['user']) && $_POST['user'] <= 250)
{
for($i=0;$i<$_POST['user'];$i++) {
mysql_query("INSERT INTO signup (email, username, pwd, gender, addtime, logintime)
VALUES ('$emails', '$fname', '120b6602eff2164ce0d131b597e4449e', 'Male', '1263160374', '1263679544')");
}
}
|
|
|
|
02-18-2010, 01:17 PM
|
Re: loop
|
Posts: 6
Name: john
|
insert.php
PHP Code:
<?php
//database info mysql_connect("localhost", "xxxxxx", "xxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxx") or die(mysql_error());
//random word function function random_word() { $seed = (integer) md5(microtime()); mt_srand($seed); $word = mt_rand(1,99999999); $word = substr(md5($word), mt_rand(0, 19), mt_rand(6, 12)); return $word; }
//random extension (will select one per page for consistancy)
{ $extensions = array("com", "net" , "ca" , "org" , "com.au" , "co.uk"); $ext = $extensions[(int)rand(0, 5)]; }
$msg = random_word(); $id = random_word();
//users { $firstname = array(
//Insert Usernames here, be sure to have the quotations and comma for example "potato",
"potato", "gullpennd9", "dd95o2", "ho3v214", "penaals9", "purplebrat18ew", "zdajletc", "vatnar0j", "gydlynwyrdu", "BRAILDIMAMBly", "mannarkx", "cpk", "Prapetnim", "corsSpose", "Spielturm", "sokurov"
);
$fname = $firstname[(int)rand(0, 15)]; }
//Gender { $gender = array("Male", "Female"); $gen = $gender[(int)rand(0, 1)]; }
//email address $emails = "$fname$lname@$msg.$ext";
//mysql command *you shouldnt need to edit this at all* if(is_numeric($_POST['user']) && $_POST['user'] <= 250) {
for($i=0;$i<$_POST['user'];$i++) {
mysql_query("INSERT INTO signup (email, username, pwd, gender, addtime, logintime) VALUES ('$emails', '$fname', '120b6602eff2164ce0d131b597e4449e', 'Male', '1263160374', '1263679544')");
} } ?>
test
post.class.php
PHP Code:
<div id="container"> <div id="header"><div id="header_left"></div> <div id="header_main">xxxxx</div><div id="header_right"></div></div> <div id="content"> <form action="insert.php" method="post"> Number of users? 250 max <input type="text" name="user" /> <input type="submit" /> </form> </div> <div id="footer"><a href="http://www.xxxxxxxx" target="_blank">Powered by xxxxxx</a></div> </div>
index.php
PHP Code:
<?php require_once("post.class.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Potatoadder - xxxxxx</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head>
<body> </body>
Here is my complete source code, it doesnt insert into the db like it should when i submit it on index.php or when i try it on post.class.php directly. sorry im really not a php coder, this is really a script broken down and modified by me
|
|
|
|
02-18-2010, 03:22 PM
|
Re: loop
|
Posts: 6
Name: john
|
Okay i got it working although its not generating all of them but im assuming because it generates randomly from the list, how can i have it rather than random, add them going down the list and never repeat the same one?
PHP Code:
<?php
//database info mysql_connect("localhost", "xxxx", "xxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxx") or die(mysql_error());
//random word function function random_word() { $seed = (integer) md5(microtime()); mt_srand($seed); $word = mt_rand(1,99999999); $word = substr(md5($word), mt_rand(0, 19), mt_rand(6, 12)); return $word; }
//users { $firstname = array(
//Insert Usernames here, be sure to have the quotations and comma for example "potato",
"potato", "viciatia", "lapideedm", "ehremg", "kotlovijo", "razjurilapa", "fwndelerzz", "Canerottimx", "Miraudoen", "z2t1u1rajb", "bbbluecrushow", "vxm002yw", "upalitw", "ambiguousjkj", "myjabberaj", "zeeduivelfo", "imixtiuneiz", "bukovskile", "prejmuirevt", "avhopparkx", "redhairkidrv", "Lisiewskikc", "arrenanteps", "kislusvy", "doprinosidu", "ladyphotoil", "uvijegy", "councilac", "Balouxle", "precejamcu", "nizakaoh", "parresiavp", "abakafkwabg", "sikhatsipd", "Waydaybyperarmz", "knuspernnt", "Masciullons", "hartantoy", "tredPhexMeelell", "gwenwynolcv", "ddiheuraio", "foroveintiunohs", "naskoolsevp", "vertebraepq", "sbleisiaunp", "Langbartzt", "rubenygeay", "buchuaqr", "freniainipssk", "dzcdzcax", "indokoltbd", "Hilaannuardnm", "vondiolakf", "pugaishel", "sbleisiauzs", "fbernadwi", "Capellezz", "pittyensidexe", "standabx", "utumikaofh", "justessafm", "syrpurbm", "ForoarbimaTarby", "pemanjatwb", "infavatofx", "drhtajimaga", "towerringpq", "Dartiziotr", "blankistabx", "Pasewalkfh", "tonelaxesf", "Tinjankal", "fyrripartmy", "Nissiriose", "aerencymavn", "comineeap", "Centorinoiw", "bingelingvj", "mythologyii", "kvadrirado", "Messbuchze", "chapichapokx", "babyrachelsy", "mafijahyi", "inwaliKahht", "torinesehb", "solucijomce", "chickblogcz", "hugotivay", "xr7005uw", "Eltermanyr", "Kenieiqs", "xxoney4evaoxxaw", "afmynduner", "aljaaryf", "Rebughigg", "Amigoiy", "tostexb", "2ly1atlzn", "relasiecg", "addasadwyrl", "pernette78us", "jrschott511ue", "nagingbz", "ambrozijilc", "Bratfischef", "nampiovawp", "mancharmeah", "ensetatsny", "XNX24Xvg", "LiceScuctow", "ducht5qt", "ugrijuwy", "Messkanaliy", "nedjenkins89vq", "klmn89cy", "gullilr", "4s5p2roggo", "impozycjath", "po1ly1zj", "dashibbsio", "inntekenyl", "gigacyclezm", "quecomoqueuenn", "apartarempi", "discornarne", "rondejarea", "frankiepypbf", "number1lustakq", "Fakyseespaxcd", "pfkhuaeocjdjq", "bloditikd", "aukafundavh", "Biancagi", "xylophonal", "Greenwellmu", "paddymoo64yg", "mph0506ik", "foletonwd", "soplarteky", "rococurf", "Fittowont", "hregissips", "Arinnyunloalaul", "jokergrl13pq", "Gegrappegmenogu", "rikkixip", "apesaradaeh", "gelincirin", "titulahma", "opolopblogue", "Lognervw", "podlogomil", "Gipsfaserit", "fonefrombezakoh", "sabrevu", "kipijq", "Typemareecq", "Leiselezu", "grolassonkt", "shotieartsl", "zazasblogos", "zbijenoyl", "agosaitnn", "gneisigqr", "eikirnarbf", "mapacheblogqw", "lecavaif", "zingenazoav", "uelezu", "ragamuffin633tm", "klitusiemho", "skainiojapv", "tabanohl", "elbarcorojoau", "tevyantsks", "Klekariz", "speeteBoypeit", "labakhulusk", "seckanjafo", "pukksteinhy", "grochowaew", "bodorfaizi", "esteumj", "plovommf", "Swadmiddemidl", "Zimmitihk", "benjyzn", "seckanjavi", "najsutszyqj", "applemagyq", "dovijems", "tishsqt", "sweetlollibw", "opprinneep", "fordulgatyq", "colegasderuteqq", "novazelanda09he", "semenskihrf", "haishAffodomz", "ocarinieh", "apartvs", "Ekofiskuh", "desdeelratongn", "stroomuv", "elanykr", "Vedoatolo", "rescrivutkq", "cascaraisld", "PhyncSmencynt", "Wierzbaal", "merkingals", "Greenwelldp", "Artiniawnyq", "Aulehk", "neogaboxni", "stadiconk", "gambraucr", "zarivalann", "bezguvc", "o2chjd", "Mobantuja", "crorryirlgn", "Qoqodalaou", "zadziorekhn", "Ceglarskikn", "Countud", "valenzinemq", "Miraudoba", "mehdibzk", "immergitqs", "xenamaxos", "Kuttlerjc", "bocabarregj", "i2chtqy", "aktynowywu", "iffdpqa", "vadilajc", "prullybumos", "mojojojotvl", "brynjudl", "tlholece", "citatziy", "refritowq", "amoryodioxm", "Boglionehe", "anymmeplykk", "doubt133tu", "justinaernijd", "paseasquirtmt"
);
}
//mysql command *you shouldnt need to edit this at all* if(is_numeric($_POST['user']) && $_POST['user'] <= 250) {
for($i=0;$i<$_POST['user'];$i++) {
$extensions = array("com", "net" , "ca" , "org" , "com.au" , "co.uk"); $ext = $extensions[(int)rand(0, 5)];
$msg = random_word(); $id = random_word();
$num = $_POST['user'] - 1;
$fname = $firstname[(int)rand(0, $num)];
$gender = array("Male", "Female"); $gen = $gender[(int)rand(0, 1)];
$emails = "$fname@$msg.$ext";
mysql_query("INSERT INTO signup (email, username, pwd, gender, addtime, logintime) VALUES ('$emails', '$fname', '120b6602eff2164ce0d131b597e4449e', 'Male', '1263160374', '1263679544')");
} }
print "Success!"; ?>
Last edited by potato; 02-18-2010 at 03:30 PM..
|
|
|
|
02-19-2010, 10:31 PM
|
Re: loop
|
Posts: 6
Name: john
|
bump, anyone have any tutorials or insight on this? i need it where it will never generate the same username from the the list
|
|
|
|
02-20-2010, 06:09 AM
|
Re: loop
|
Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
|
add a flag of "used" to the array.
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
02-24-2010, 02:16 AM
|
Re: loop
|
Posts: 27
Name: Sumit Jain
Location: India
|
Thanks..... i got the solution....
|
|
|
|
|
« Reply to loop
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|