DEVILofDARKNESS Posted June 6, 2009 Share Posted June 6, 2009 Okay, I've made a register-page, but if I test it out on my localhost, it always add two nations, two users (all with the same name but with a different id). I can't see why it inserts 2 rows each time so what is wrong, or how can I figure this out? <?php session_start(); require_once './config.php'; $page = $_GET['page']; $prev = $_SESSION['prev']; if(isset($_POST['page1'])){ header('location:./register.php?page=2'); }elseif(isset($_POST['page2leader'])){ if($_POST['regradiolead']){ $_SESSION['regradiolead'] = $_POST['regradiolead']; header('location:./register.php?page=31'); }else{ header('location:./register.php?page=32'); } }elseif(isset($_POST['page2civilian'])){ header('location:./register.php?page=32'); }elseif(isset($_POST['page31'])){ $_SESSION['nationname'] = $_POST['nationname']; $_SESSION['username'] = $_POST['username']; $_SESSION['pass'] = $_POST['password']; header('location:./register.php?page=41'); }elseif(isset($_POST['page32'])){ $_SESSION['regradiociv'] = $_POST['regradiociv']; header('location:./register.php?page=42'); }elseif(isset($_POST['page41'])){ header('location:./login.php'); }elseif(isset($_POST['page42'])){ $_SESSION['username'] = $_POST['username']; $_SESSION['pass'] = $_POST['password']; header('location:./register.php?page=52'); }elseif(isset($_POST['page52'])){ header('location:./login.php'); } ?> <html> <head><title>Register -- Europia</title></head> <body> <?php switch($page){ case 1: echo "It's the end of year 9 from the galactic calendar, after 9 year of peace, a new generation of leaders has been born, ready to overthrow the current leaders and ready to rule over the world. You're one of these born leaders and you have the power and the knowledge to start an own nation. Maybe you're rich enough to buy right now a region, or maybe you will have to wait and take your chance later. You have 150 Salidrian-Zet (Salidrian-Zet (S~Z) is the currency In Europe since year 1), IF YOU THINK YOUR READY<br><form action='' method='post'><input type='submit' name='page1' value='GO ON'></form>"; $_SESSION['prev'] = 1; break; case 2: if($prev=='1'){ $query = "SELECT * FROM regions WHERE in_use = 'No'"; $result = mysql_query($query); echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; echo "<tr><td>Name</td><td> </td></tr>"; while($regions = mysql_fetch_array($result)){ echo "<tr><td>" . $regions['region_name'] . "</td><td><input type='radio' name='regradiolead' value='" . $regions['region_id'] . "'></td></tr>"; } echo "<tr><td colspan='2'>If nothing appears above this text it means that all regions are in use, you can now do two things, 1) Wait untill their are added new regions and be verry fast to take them (just go away) 2) You can start as a civilian of someone else his nation and plan a tactic to do a coup! (CIVILIAN)</td></tr>"; echo "<tr><td><input type='submit' name='page2leader' value='LEADER'></td><td><input type='submit' name='page2civilian' value='CIVILIAN'></td></tr></form>"; $_SESSION['prev'] = 2; }else{ echo 'Please Start from page 1!'; } break; case 31: if($prev == '2'){ echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; echo "<tr><td>Nation Name:</td><td><input type='text' name='nationname'></td></tr> <tr><td>User Name:</td><td><input type='text' name='username'></td></tr> <tr><td>Password:</td><td><input type='password' name='password'></td></tr> <tr><td colspan='2'><input type='submit' name='page31' value='GO ON'></td></tr>"; echo "</table></form>"; $_SESSION['prev'] = 31; }else{ echo "Please Start From Page 1"; } break; case 32: if($prev == '2'){ echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; $query = "SELECT * FROM regions WHERE in_use = 'Yes'"; $result = mysql_query($query); while($regions = mysql_fetch_array($result)){ echo "<tr><td>" . $regions['region_name'] . "</td><td><input type='radio' name='regradiolead' value='" . $regions['region_id'] . "'></td></tr>"; } $result = mysql_query($query); echo "<tr><td colspan='2'><input type='submit' name='page32' value='FINISH'></td></tr>"; echo "</table></form>"; $_SESSION['prev'] = 32; }else{ echo "Please Start From Page 1"; } break; case 41: if($prev == '31'){ $nationname = $_SESSION['nationname']; $regionid = $_SESSION['regradiolead']; $username = $_SESSION['username']; $pass = $_SESSION['pass']; $password = md5('f4lcon$€' . $pass . 'l1ve€$'); $query = "INSERT INTO nations(nation_name,nation_capital,leader) VALUES ('$nationname','$regionid','1')"; $result = mysql_query($query); $query = "SELECT nation_id FROM nations WHERE nation_name = '$nationname'"; $result = mysql_query($query); list($nationid) = mysql_fetch_row($result); $query = "UPDATE regions SET nation_id = '$nationid' WHERE region_id='$regionid'"; $result = mysql_query($query); $query = "UPDATE regions SET in_use = 'Yes' WHERE region_id='$regionid'"; $result = mysql_query($query); $query = "INSERT INTO users(user_name,user_pass,nation_id,leader,money) VALUES ('$username','$password','$nationid','Yes','150')"; $result = mysql_query($query); $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query); list($userid) = mysql_fetch_row($result); $query = "UPDATE nations SET leader = '$userid' WHERE nation_id='$nationid'"; $result = mysql_query($query); echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; echo "<tr><td>Okay, All is updated, and your ready to rule over your brand new nation!<br>The only thing that you have to do is login and Play!!</td></tr> <tr><td><input type='submit' name='page41' value='LOGIN'></td></tr>"; echo "</table></form>"; }else{ echo "Please Start From Page 1"; } break; case 42: if($prev == '32'){ echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; echo "<tr><td>User Name:</td><td><input type='text' name='username'></td></tr> <tr><td>Password:</td><td><input type='password' name='password'></td></tr> <tr><td colspan='2'><input type='submit' name='page42' value='FINISH'></td></tr>"; echo "</table></form>"; $_SESSION['prev'] = 42; }else{ echo "Please Start From Page 1"; } break; case 52: if($prev == '42'){ $username = $_SESSION['username']; $pass = $_SESSION['pass']; $password = md5('f4lcon€$' . $pass . 'l1ve€$'); $nationid = $_SESSION['regradiociv']; $query = "INSERT INTO users(user_name,user_pass,nation_id,leader,money) VALUES ('$username','$password','$nationid','No','150')"; $result = mysql_query($query); echo "<form action='' method='POST'><table border='0'><form action='' method='POST'>"; echo "<tr><td>Okay, All is updated, and your ready to start your live as a civillian. Just login and Play!!</td></tr> <tr><td><input type='submit' name='page52' value='LOGIN'></td></tr>"; echo "</table></form>"; }else{ echo "Please Start From Page 1"; } break; default: echo "Oops, you have to go to <a href='./register.php?page=1'>page 1</a> to register!."; break; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 put exit(); right after all of your header(..); Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted June 6, 2009 Author Share Posted June 6, 2009 Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.