phpSensei Posted December 16, 2007 Share Posted December 16, 2007 I just did that on my page, too. It just doesnt add it to DB.. <?PHP include('Connect.php'); include('top.php'); $userID = $_COOKIE['UserID']; $submit = $_POST['submit']; $pokemonname = $_POST['pokemon_name']; $attack = $_POST['pokemon_attack']; $defence = $_POST['pokemon_defence']; $pokemonimage = $_POST['pokemon_image']; $pokemonimage2 = $_POST['pokemon_icon']; $gender = $_POST['pokemon_gender']; $level = $_POST['pokemon_level']; $exp = $_POST['pokemon_exp']; $attack1 = $_POST['attack1']; $attack2 = $_POST['attack2']; $attack3 = $_POST['attack3']; $attack4 = $_POST['attack4']; $Hi="0/"; $result="SELECT * FROM pokemon_info WHERE user_id=$userID"; if (!isset($_COOKIE['UserID'])) { echo "Sorry, you are not logged in."; include('bottom.php'); exit; } if(mysql_num_rows(mysql_query($result)) != 0) { echo "Sorry, you already have your starter"; include('bottom.php'); exit; } else{ if ($submit) { switch($pokemonname){ case "Piplup": $pokemonimage="http://i13.tinypic.com/6jzrsdv.png"; $pokemonimage2="http://i4.tinypic.com/6uepa2h.png"; $attack="20"; $defence="15"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $exp= '0/'.rand(20,50); break; case "Chimchar": $pokemonimage="http://i10.tinypic.com/6p98rch.png"; $pokemonimage2="http://i15.tinypic.com/717m0oy.png"; $attack="18"; $defence="17"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $exp= '0/'.rand(20,50); break; default: $pokemonname="Turtwig"; $pokemonimage="http://i9.tinypic.com/6sapvo1.png"; $pokemonimage2="http://i12.tinypic.com/81i2tkl.png"; $attack="15"; $defence="20"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $exp= '0/'.rand(20,50); break; } $result2="INSERT INTO pokemon_info (user_id,pokemon_name,pokemon_attack,pokemon_defence,pokemon_image,pokemon_gender,pokemon_icon,pokemon_level,pokemon_exp,attack1,attack2,attack3,attack4) values ('$userID','$pokemonname','$attack','$defence','$pokemonimage','$gender','$pokemonimage2','$level','$exp','$attack1','$attack2','$attack3','$attack4')"; mysql_query($result2)or die(mysql_error()); echo "You have obtained your starter. It is $pokemonname."; } else{ echo "<html> If you refresh this page before getting a starter, you will not obtain a starter, and it will take up a spot in your party. <form method='POST' id='frm'> <input type='hidden' name='submit' value='1'><br> <b>Choose your pokemon</b><br /> <select name='pokemon_name'> <option value='Turtwig'>Turtwig</option> <option value='Piplup'>Piplup</option> <option value='Chimchar'>Chimchar</option> </select> <b> Choose it's gender</b> <br /> <select name='pokemon_gender'> <option value='Male'>Male</option> <option value='Female'>Female</option> </select> <input type='submit' name='submit' value='Get starter'> </form> </html>"; } } include('bottom.php'); exit; ?> Whats wrong? since when do you put a break after a default? <?php switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; default: echo "i is not equal to 0, 1 or 2"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415907 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 aren't you suppose to have a break after each thing in a switch? they do it here too http://www.tizag.com/phpT/switch.php Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415909 Share on other sites More sharing options...
phpSensei Posted December 16, 2007 Share Posted December 16, 2007 aren't you suppose to have a break after each thing in a switch? they do it here too http://www.tizag.com/phpT/switch.php That is just how I learned it, and that site is pure crap, I have seen alot of errors on their. I would rather go by php.net then tizag. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415912 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 oh I learned it from tizag and I just assumed you are suppose to have a break after each conditional statement on a switch, Ill check php.net right now to see if they have anything on this Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415916 Share on other sites More sharing options...
phpSensei Posted December 16, 2007 Share Posted December 16, 2007 oh I learned it from tizag and I just assumed you are suppose to have a break after each conditional statement on a switch, Ill check php.net right now to see if they have anything on this http://ca.php.net/manual/en/control-structures.switch.php You could use endswitch. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415917 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 I'm not sure, but try this: <?php include('Connect.php'); include('top.php'); $userID = $_COOKIE['UserID']; $submit = $_POST['submit']; $pokemonname = $_POST['pokemon_name']; $attack = $_POST['pokemon_attack']; $defence = $_POST['pokemon_defence']; $pokemonimage = $_POST['pokemon_image']; $pokemonimage2 = $_POST['pokemon_icon']; $gender = $_POST['pokemon_gender']; $level = $_POST['pokemon_level']; $exp = $_POST['pokemon_exp']; $attack1 = $_POST['attack1']; $attack2 = $_POST['attack2']; $attack3 = $_POST['attack3']; $attack4 = $_POST['attack4']; $Hi="0/"; $result="SELECT * FROM pokemon_info WHERE user_id=$userID"; if (!isset($_COOKIE['UserID'])) { echo "Sorry, you are not logged in."; include('bottom.php'); exit; } if(mysql_num_rows(mysql_query($result)) != 0) { echo "Sorry, you already have your starter"; include('bottom.php'); exit; } else{ if ($submit) { switch($pokemonname){ case "Piplup": $pokemonimage="http://i13.tinypic.com/6jzrsdv.png"; $pokemonimage2="http://i4.tinypic.com/6uepa2h.png"; $attack="20"; $defence="15"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $con = rand(20,50); $exp= "0/$con"; break; case "Chimchar": $pokemonimage="http://i10.tinypic.com/6p98rch.png"; $pokemonimage2="http://i15.tinypic.com/717m0oy.png"; $attack="18"; $defence="17"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $con = rand(20,50); $exp= "0/$con"; break; default: $pokemonname="Turtwig"; $pokemonimage="http://i9.tinypic.com/6sapvo1.png"; $pokemonimage2="http://i12.tinypic.com/81i2tkl.png"; $attack="15"; $defence="20"; $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $level= rand(1,10); $con = rand(20,50); $exp= "0/$con"; break; } $result2="INSERT INTO pokemon_info (user_id,pokemon_name,pokemon_attack,pokemon_defence,pokemon_image,pokemon_gender,pokemon_icon,pokemon_level,pokemon_exp,attack1,attack2,attack3,attack4) values ('$userID','$pokemonname','$attack','$defence','$pokemonimage','$gender','$pokemonimage2','$level','$exp','$attack1','$attack2','$attack3','$attack4')"; mysql_query($result2)or die(mysql_error()); echo "You have obtained your starter. It is $pokemonname."; } else{ echo "<html> If you refresh this page before getting a starter, you will not obtain a starter, and it will take up a spot in your party. <form method='POST' id='frm'> <input type='hidden' name='submit' value='1'><br> <b>Choose your pokemon</b><br /> <select name='pokemon_name'> <option value='Turtwig'>Turtwig</option> <option value='Piplup'>Piplup</option> <option value='Chimchar'>Chimchar</option> </select> <b> Choose it's gender</b> <br /> <select name='pokemon_gender'> <option value='Male'>Male</option> <option value='Female'>Female</option> </select> <input type='submit' name='submit' value='Get starter'> </form> </html>"; } } include('bottom.php'); exit; ?> Thats stupid, why would connect make a differance? And phpsensei, I just deleted break. No differance in outcome. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415918 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 what do you mean why would connect make a difference? and yea I was looking through php.net right now and I dont really think it matters for the last conditional statement on a switch, you can use break, nothing, or if formatted correctly from the beginning use endswitch; Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415920 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 I already included connect. Why would $con 0/$con Make a differance? I dont even want it to be $con, I want it to be rand. Can you check my script and see why it's wrong? Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415922 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 oh you mean the variable $con is already defined.... just change the variable name then.... Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415923 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 oh you mean the variable $con is already defined.... just change the variable name then.... No, Im saying whats the point of having $con there if I need rand? Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415929 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 Oh, sorry. I got mixed up. I thought you ment $con as connect. Anyways, that still deosnt work. Still dsiaplys 0.. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415930 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 damn you dont need to be so bitchy about it, you're just making yourself look like a fool, just because it has the letters "con" in it does not mean it has anything to do with connecting anything, it is a variable that I myself defined in your script and told it to choose a random number like you wanted! Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415931 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 How was I bitchy about it? I just got mixed up.. And it still wont work. I dont think it has anything to do with that, it's the insert into, I think. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415932 Share on other sites More sharing options...
Northern Flame Posted December 16, 2007 Share Posted December 16, 2007 oh alright then, well i don't really know why its not accepting it in your database, but I am leaving soon so i am going to log off, if i still see this topic open when i get back i will try to solve it then..... Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415933 Share on other sites More sharing options...
phpSensei Posted December 16, 2007 Share Posted December 16, 2007 Is the database field where you are putting $exp = "0/".$con into a varchar? Post the stucture for your database, I think its all wrong. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415934 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 Its bigint, why? Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415936 Share on other sites More sharing options...
phpSensei Posted December 16, 2007 Share Posted December 16, 2007 Its bigint, why? OMFG, this is why you have been complaining so much. It has to be Varchar 225 Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415937 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 Oh, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415939 Share on other sites More sharing options...
phpSensei Posted December 16, 2007 Share Posted December 16, 2007 Oh, thank you. You need to provide the people that are helping you with as much information as you can. You also need to read about creating database tables, and data types. Return us with good news if it works. Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415940 Share on other sites More sharing options...
Xyphon Posted December 16, 2007 Author Share Posted December 16, 2007 It works. Im pretty much a complete idiot at MySQL, sorry XD Quote Link to comment https://forums.phpfreaks.com/topic/81821-solved-unexpected-on-last-line/page/3/#findComment-415941 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.