Jump to content

trying to write a script which creates multiple entires into 2 tables


kingb00zer
 Share

Recommended Posts

hi I am attempting to make a registration form which creates up to 20 accounts in one go below I just used 3 to try and get it right and save myself sometime until i got it right. I already have a registration form which works but that is for the making a master account. and I used the same code, just altered to be for a diferent table with diferent feilds in it to the master account registraion form. now I seem to be getting these errors when i test it and now I am out of ideas, any clues?EDIT: I havnt actually shown when I tried to enter into both tables however the second table charactorstats was getting the same errors as game stats, i should ahve thought when titling this thread lol....Errors:Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 8Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/schulzy/public_html/roundsignup.php on line 10Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 14Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 17Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 20Thank you your gang has been created succesfully. <<< this sint actually an error it is an echo for if everything is true and the registration went through.

 log in form (html)<html><body><p align="center"> <b>register to round</b></p><table align="center"><tr><td> <form action="roundsignup.php">Name your Soldiers. All will have the same name but be numbered <br />Soldiers: <input type="text" length="20 method="post" name="soldier" id="soldier" /> <br /> <input type="submit" value="Create Gang Members" /></td></tr></form></table></body></html>

 roundsignup.php<?php error_reporting(E_ALL);  ini_set('display_errors', 1);  include('connection.php');//check for duplicate names$query1= "SELECT * FROM users WHERE solider='$_POST[soldier]'";$result1= mysql_query($query1);$num1= mysql_num_rows($result1);if ($num1 == 0) {$soldiergstats1= "INSERT INTO gamestats (soldiers, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]01', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult1=mysql_query($soldiergstats1);$soldiergstats2= "INSERT INTO gamestats (soldiers, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]02', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult2=mysql_query($soldiergstats2);$soldiergstats3= "INSERT INTO gamestats (soldiers, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]03', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult3=mysql_query($soldiergstats3);echo ("Thank you your gang has been created succesfully.");}else{echo ("Sorry but that account name is in use.");}?>

every feild in that gamestats table exists and the soldier feild has also been set as index thru php myadmin. also the part where it says '$_POSTsoldier]01' and 02 and 03 were just done as a test to see if I could number each account individually like that. Even with out the numbers I still got the same errors, also can I number accounts like that so to save people time when filling out the form? oh and btw I also had a form with 20 text inputs and attempted to insert the same stuff and got the same errors again just way more of them lol.

Edited by KingB00ZeR
Link to comment
Share on other sites

I am not sure if you copied and pasted this from your actual code, but I noticed a spelling error:

$query1= "SELECT * FROM users WHERE solider='$_POST[soldier]'";
Hope that helps!Edit: Also found this:
length="20
not ended with a double quote. Edited by dminder
Link to comment
Share on other sites

I am not sure if you copied and pasted this from your actual code, but I noticed a spelling error:Hope that helps!Edit: Also found this: not ended with a double quote.
ok I fixed that spelling mistake and I still get the same error Edited by KingB00ZeR
Link to comment
Share on other sites

OK so I have decided to leave out the part where it checks for other accounts of the same name, I can do that later. I really want to figure out how to insert multiple entries into 1 table (the 2nd table I will add at a later stage). I also found a mistake in the first block of code that I posted in this thread at the insert into (soldier, ) part I had it written as soldiers but that is fixed and still the same error.

<?php error_reporting(E_ALL);  ini_set('display_errors', 1);  include('connection.php');$soldiergstats1= "INSERT INTO gamestats (soldier, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]01', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult1=mysql_query($soldiergstats1);$soldiergstats2= "INSERT INTO gamestats (soldier, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]02', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult2=mysql_query($soldiergstats2);$soldiergstats3= "INSERT INTO gamestats (soldier, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[soldier]03', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult3=mysql_query($soldiergstats3);echo ("Thank you your gang has been created succesfully.");?>

Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 8Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 11Notice: Undefined index: soldier in /home/schulzy/public_html/roundsignup.php on line 14any ideas? anybody??

Edited by KingB00ZeR
Link to comment
Share on other sites

That means your not sending the POST data correctly. Note also that your script is very vulnerable to SQL injection.

Link to comment
Share on other sites

thanks synook, now I know roughly where to make corrections, but as for the sql injection i had not added it yet but I will take the code from the master account registration form part and apply it when this part is complete.also if you are reffering to the numbering at the end of the $_POST[soldier]01 I tested this with my master account registration form and it worked fine.

Edited by KingB00ZeR
Link to comment
Share on other sites

I think it maybe a problem with $_POST[soldier]01, try it with$currentsoldier=$_POST['soldier'].'01';$soldiergstats1= "INSERT INTO gamestats (soldier, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$currentsoldier', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')";$sgstatresult1=mysql_query($soldiergstats1);not quite sure if you trying to get post value for $_POST['soldier01']; in that case something like this should work $soldiercount="01";//was going to use increment, but you use 01, instead of 1, if you can find way of number formatting to 01 even better $currentsoldier='soldier'.$soldiercount;$soldiergstats1= "INSERT INTO gamestats (soldier, turns, money, thugs, dealers, hoes, coke, heroin, weed, xtc, ketamine, pistols, shotguns, ak47s, suvs) VALUES ('$_POST[$currentsoldier]', '10000', '2000', '200', '50', '50', '0', '0', '0', '0', '0', '50', '0', '0')"; $sgstatresult1=mysql_query($soldiergstats1);

Link to comment
Share on other sites

hmmm cant seem to get it to work, same error appearing, so I decided to just try to add the one entry instead of 3.. just off this scripts topic id liek to mention that the $_post[soldier]01 liek I orginaly did actually did work when i trialed it on the master account sign up page... maybe its my html or possible a php myadmin issue either way it has got me baffled... ill keep working on this and fingers crossed i dont come abck in a couple of house to bug you guys again heh..p.s. please excuse my typos i type quicker than I probably should :)

Link to comment
Share on other sites

Ok I figured it out using an old registration form, well when i said figured out I mean i have what i want but i still dont understand why it wasnt working on the other script. I thoght id paste the code I used to get it to work which is just my master account registration script made to add a second account and number each account01 then account02 in the users row. so my guess is maybe something wrong with the php myadmin side of things in my gamestats table.

<?php error_reporting(E_ALL);  ini_set('display_errors', 1);  include('connection.php');//check for duplicate names$query= "SELECT * FROM users WHERE username='$_POST[username]'";$result= mysql_query($query);$num= mysql_num_rows($result);if ($num == 0) {//check for duplicate emails$query2= "SELECT * FROM users WHERE email='$_POST[email]'";$result2= mysql_query($query2);$num2= mysql_num_rows($result2);if ($num2 == 0) {//check if password and email confirmation is the sameif (($_POST['pass'] == $_POST['pass2'] && $_POST['email'] == $_POST['email2'])) {// insert into users table$sql2= "INSERT INTO users (username, email, password) VALUES ('$_POST[username]01', '$_POST[email]', '$_POST[pass]')";$result2=mysql_query($sql2);$sql15= "INSERT INTO users (username, email, password) VALUES ('$_POST[username]02', '$_POST[email]', '$_POST[pass]')";$result15=mysql_query($sql15);echo ("Thank you your master account has been created succesfully.");}else{echo ("error signing up, please ensure that everything you have entered is correct.");}}}?>

hopefully this helps pinpoint the issue I had with the previous scriptEDIT: ok it is definately the gamestats table it just isnt putting any data into it (I'm messing around and trying diferent things with my master account registration script)

Edited by KingB00ZeR
Link to comment
Share on other sites

If accessing $_POST['soldier'] causes it to give a warning that soldier is an undefined index, that means that the form does not have an element with that name.
this is the form code
<form method="post" action="roundsignup.php"><u>Name your Soldiers. All will have the same name but be numbered</u> <br />	   Name your Soldiers:  <input type="text" size="15" maxlength="20" name="soldier" /> <br /> 				<input type="submit" value="Create Gang Members" />		</form>

I noticed that i placed the method="post" in the input tag then corrected it and placed it into the form tag. Now I dont get any errors but it still fails to put the soldier name into the database.below is the code for the roundsignup.php incase it makes it easier to figure out my problem

<?php error_reporting(E_ALL);  ini_set('display_errors', 1);  include('connection.php');$soldiergstat1= "INSERT INTO gamestats WHERE user='$_POST[username]' (soldier) VALUES ('$_POST[soldier]01')";$resultgstat1=mysql_query($soldiergstat1);$soldiercstat1= "INSERT INTO charactorstats WHERE user='$_POST[username]' (soldier) VALUES ('$_POST[soldier]01')";$resultcstat1=mysql_query($soldiercstat1);echo ("Thank you your gang has been created succesfully.");?>

Edited by KingB00ZeR
Link to comment
Share on other sites

Thank yuo to everyone who helped me with this, it now works... oh it feels so good that moment when somehting that has bugged you for days instanly stops bugging you :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...