Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-18-2010, 12:38 AM loop
Novice Talker

Posts: 6
Name: john
Trades: 0
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
potato is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-18-2010, 01:44 AM Re: loop
Mad182's Avatar
Skilled Talker

Posts: 54
Name: Madars
Location: Latvia
Trades: 0
PHP Code:
for($i=0;$i<$_POST['user'];$i++) {
    
//do your stuff

__________________
There's no place like 127.0.0.1

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Mad182 is offline
Reply With Quote
View Public Profile Visit Mad182's homepage!
 
Old 02-18-2010, 11:51 AM Re: loop
Novice Talker

Posts: 6
Name: john
Trades: 0
Quote:
Originally Posted by Mad182 View Post
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')");


potato is offline
Reply With Quote
View Public Profile
 
Old 02-18-2010, 11:59 AM Re: loop
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
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')");

     } 

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-18-2010, 01:17 PM Re: loop
Novice Talker

Posts: 6
Name: john
Trades: 0
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(019), mt_rand(612)); 
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(05)];


$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(015)];
}


//Gender
{
$gender = array("Male""Female");
$gen $gender[(int)rand(01)];
}

//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 users250 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
potato is offline
Reply With Quote
View Public Profile
 
Old 02-18-2010, 03:22 PM Re: loop
Novice Talker

Posts: 6
Name: john
Trades: 0
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(019), mt_rand(612)); 
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(05)];

$msg random_word();
$id random_word();

$num $_POST['user'] - 1;

$fname $firstname[(int)rand(0$num)];

$gender = array("Male""Female");
$gen $gender[(int)rand(01)];


$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..
potato is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 10:31 PM Re: loop
Novice Talker

Posts: 6
Name: john
Trades: 0
bump, anyone have any tutorials or insight on this? i need it where it will never generate the same username from the the list
potato is offline
Reply With Quote
View Public Profile
 
Old 02-20-2010, 06:09 AM Re: loop
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-24-2010, 02:16 AM Re: loop
Average Talker

Posts: 27
Name: Sumit Jain
Location: India
Trades: 0
Thanks..... i got the solution....
digitaltours is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30033 seconds with 12 queries