NewcastleFan Posted November 6, 2011 Share Posted November 6, 2011 Hey guys, I've been playing around with this open source php game, I'm having problems with the registration system. For some reason the script is echoing back that there is no password in the password fields. When in fact there is: Add_player.php: <?php session_start(); session_register("pid"); include("common.inc"); include("date.inc"); include("header.inc"); dbConnect(); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\"") or die(mysql_error()); if ($name == "" || $password1 == "") { echo "<center><div class=\"sheader\">Oh dear me!</div> You have to actually enter a name and password!"; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($name == $password1) { echo "<center><div class=\"sheader\">Oh dear me!</div> You can't make the password the same as the name. People will guess your password!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (strlen($password1) < 6) { echo "<center><div class=\"sheader\">Oh dear me!</div> Passwords must be at least 6 characters, otherwise they are easy to guess!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (mysql_fetch_row($res)) { echo "<center><div class=\"sheader\">Oh dear me!</div> Player $name already exists, try a different name."; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($password1 != $password2) { echo "<center><div class=\"sheader\">Oh dear me!</div>"; echo "The two passwords didn't match - type carefully now!."; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } echo "<div class=\"sheader\">Registration for $name successful</div>"; $cp = crypt($password1); $dateArray = getdate(time()); $likeNowScoob = $dateArray["year"] . "-" . $dateArray["mon"] . "-" . $dateArray["mday"]; if ($character < 1 || $character > 9) { die("you are an idiot"); } pdm_characters(); $res = mysql_query("select type from $dbName.pdm_characters where cid = $character") or die(mysql_error()); $t = mysql_fetch_row($res); pdm_stuff(); $specRes = mysql_query("select sid from $dbName.pdm_stuff where sid >= 28 and sid <= 33 and type like \"%$t[0]%\"") or die(mysql_error()); $res = mysql_query("BEGIN") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_players (name, used, dob, cpass, char_id, roundswon, evo, aWeapon, dWeapon) VALUES (\"$name\", 1, \"$likeNowScoob\", \"$cp\", $character, 0,0,0,0)") or die(mysql_error()); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\" for update") or die(mysql_error()); $row = mysql_fetch_row($res); $pid = $row[0]; $res = mysql_query("insert into $dbName.pdm_league (id, highest, days_no_1, yesterday, longPoints) VALUES ($pid, 16777215, 0, 16777215, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_stats (id, level, attack, defence, health, speed, exp, ko, healthpercent, fights) VALUES ($pid, 1, 100, 100, 100, 100, 0, 0, 10, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_clanmembers2 (id, clanTag, applyTag, utype) VALUES ($pid, NULL, NULL, '')") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_money (id, bank, wallet, bankdate) VALUES ($pid, 0,0, '0000-00-00')") or die(mysql_error()); while ($row = mysql_fetch_row($specRes)) { $res = mysql_query("insert into $dbName.pdm_specials (id, sid, qty, switch) values ($pid, $row[0], 0, 1)") or die(mysql_error()); } $res = mysql_query("COMMIT") or die(mysql_error()); session_register("playerName"); $playerName = stripper($name); echo "<P><diV>Welcome $playerName, click the Fight link down the left to fight your first opponent.</div>"; include("main_screen.inc"); include("footer.inc"); ?> Character_form.inc: <center> <form method="post" action="add_player.php"> <P> <table cellpadding="0" cellspacing="0"><tr><td align="center"> <?php dbConnect(); pdm_characters();#check HEAP table exists $res = mysql_query("select cid, name, type from $dbName.pdm_characters order by type") or die(mysql_error()); $marker = "X"; $firstOne = 1; $cTypes["A"] = "Alien"; $cTypes["M"] = "Magic"; $cTypes["S"] = "Spirit"; while ($row = mysql_fetch_row($res)) { if ($marker != $row[2]) #new type (alien/magic etc) { if ($marker != "X") { echo "</table>\n"; } $cn = $cTypes[$row[2]]; echo "\n<table cellpadding=\"0\" cellspacing=\"0\" border=1> <tr><td colspan=\"3\" align=\"center\"><div class=\"sheader\"> $cn characters</div></td></tr><tr bgcolor=\"#efefef\">"; $marker = $row[2]; } echo "\n<td><table><tr><td align=center>$row[1]</td></tr><tr><td align=center> <img alt=\"Pick me!\" src=\"images/$row[0]0.gif\"></td></tr><tr> <td align=center><input type=\"radio\" name=\"character\" value=\"$row[0]\""; if ($firstOne and $character == "") { $firstOne = 0; echo " CHECKED "; } if ($character == $row[0]) { echo " CHECKED "; } echo "></td></tr></table></td>"; } echo "</tr></table> <table width=\"551\" cellpadding=0 cellspacing=0><tr><td colspan=\"3\"><div class=\"sheader\">character details</div></td></tr> <tr><td align=\"center\">Name<br><input size=20 maxlength=20 type=text name=\"name\" value = \"$name\"></td>"; ?> <td align="center">Password<br><input type="password" name="password1" size=20 maxlength=20></td> <td align="center">Password again<br><input type="password" name="password2" size=20 maxlength=20></td></tr> <tr><td colspan="3" align="center"><input type="submit" value="Register my character"></td></tr></table> </td></tr></table> <hr> </form> </centER> Anyone able to offer up any advice or where its going wrong, If I remove the validation stuff, it still doesn't insert the user into the database. Cheers Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 6, 2011 Share Posted November 6, 2011 extract($_POST); // or $password1 = $_POST['password1']; extract Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Hi Andy, Thanks for your quick reply? Are you suggesting I use extract to de-bug the script? I'm not 100% sure on the meaning of your post :S sorry. Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 You haven't defined the name and password variables Add this before the query $password1 = $_POST['password1']; $password2 = $_POST['password2']; $name = $_POST['name']; Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 You haven't defined the name and password variables Add this before the query $password1 = $_POST['password1']; $password2 = $_POST['password2']; $name = $_POST['name']; Hi Gotharious, Thanks for that! I thought it was declared but guess that was on another copy. I've added that in and now I get the error "you are an idiot" - lol. Which comes from this line: if ($character < 1 || $character > 9) { die("you are an idiot"); } Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 what I meant is, after you posted to add_player.php you're using the variables $name $password1 and $password2 which are not defined, you have to set them to the right $_POST[''] so when you use them in your query, it's known that password1 is the password the user entered in the form that has the name "password1" Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 where exactly did you declare $character? Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 <?php session_start(); session_register("pid"); include("common.inc"); include("date.inc"); include("header.inc"); dbConnect(); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\"") or die(mysql_error()); $password1 = $_POST['password1']; $password2 = $_POST['password2']; $name = $_POST['name']; $character = $_post['character']; if ($name == "" || $password1 == "") Character is declared there now. However will character and name work like that? As in the character_form.inc they must have backslashes else it produces and error: <td align=center><input type=\"radio\" name=\"character\" value=\"$row[0]\""; <tr><td align=\"center\">Name<br><input size=20 maxlength=20 type=text name=\"name\" value = \"$name\"></td>"; Will I need to declare them as character\ and name\? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2011 Share Posted November 6, 2011 I can tell by looking at just the first few lines that the code is old. It's using deprecated functions, and is written to depend on register_globals being On (which is a bad idea). It should be gone through and brought up to date. Also, you should be developing with the following directives in your php.ini file so notices, warnings and errors are reported. error_reporting = -1 display_errors = On Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 No, you don't need to Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Thanks guys realised I needed POST not post on characters and it has worked. I'm just playing about with this code really Pikachu, once I get a bit better at this stuff I'll try and bring it up to date Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2011 Share Posted November 6, 2011 OK. It might be a good learning experience to go through it and see what's wrong with it . . . Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 6, 2011 Share Posted November 6, 2011 You also should NOT use extract on external data, without preventing it from blindly overwriting existing variables, as it will allow a hacker to set any of your program variables to anything he wants. Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 and I think you should follow Pikachu's advice... this guy is GOOD, he's like solving all my problems Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Yeh I'm playing about with it on a free host at the moment, seems like the sessions don't work anymore either. Would it be best running this on an older server? Also I don't think I can edit the php.ini file on the free host. http://deathmatch.hostei.com is the site, can sign up but it just logs you out atm ha. Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 what do you mean by "don't think sessions work any longer"? you need to add session_start() at every page you use the sessions in Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Yeh sorry did not mean sessions in general meant the session_register. Just had a google and saw it was stopped in PHP 4.2. What's the current day replication of it? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 6, 2011 Share Posted November 6, 2011 You should be learning php and developing/debugging php code on a local development system. There's no need to have a live server and you waste a huge amount of time constantly uploading code just the see the result of each change to the code. Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 I do have XAMMP on my local host, but when ever I have been working on little test scripts in the past, they have worked on my local host, but not when I've added them to a live environment, Have I got XAMMP setup wrong? Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 Ok, stupid question but happens often Do you change your mysql connection configuration when you use them in a live environment? cause I've seen lots of people forget that Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Ok, stupid question but happens often Do you change your mysql connection configuration when you use them in a live environment? cause I've seen lots of people forget that Haha yeh, I always change the configurations. It's often things like unexpected " in Tstring and errors like that I get when moving from local to live. Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 I'm not sure about that, but I get that a lot too, perhaps using the same php version in live and local environments would solve this problem, not sure tho Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 Possibly! I'm beginning to think I've bitten off more than I can chew with this project now. PHP Seems a lot more complex than I first thought . Would I be better off not working with old code to teach my self things? lol Quote Link to comment Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Share Posted November 6, 2011 There are few things about php, that are so simple but drives you nuts make you sometimes feel like you want to stop trying, and then suddenly, browsing online you find the answer and PHP is all fun again. I think what you should do, instead of just asking people for help in a code, and then take their input and that's it, is to understand why it didn't work before, and why it now works, if you understand that, you will be able to relate when you encounter a similar problem and be able to figure out the problem. Or you can get a ps3, start playing pro evolution and win for Newcastle... sounds more fun lol Quote Link to comment Share on other sites More sharing options...
NewcastleFan Posted November 6, 2011 Author Share Posted November 6, 2011 There are few things about php, that are so simple but drives you nuts make you sometimes feel like you want to stop trying, and then suddenly, browsing online you find the answer and PHP is all fun again. I think what you should do, instead of just asking people for help in a code, and then take their input and that's it, is to understand why it didn't work before, and why it now works, if you understand that, you will be able to relate when you encounter a similar problem and be able to figure out the problem. Or you can get a ps3, start playing pro evolution and win for Newcastle... sounds more fun lol Haha don't need to win for newcastle atm! they are doing that themselves! haha.I'm to planning on giving up completely may just change project due to this one basically needed to be re-written to modern php! Thanks for all of the help guys. 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.