Jump to content

dannerz

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by dannerz

  1. I'll start copy pasting and editing (thanks)
  2. echo "you bought 1 archer"; $data = mysql_query("SELECT Vals FROM vals2 WHERE ValsN = 'archers'"); if ($data == false) exit("This has failed"); $msg = mysql_fetch_assoc($data); echo "<br />"; echo $msg;//this just says that it is an array echo "<br />"; echo $data; echo "<br />"; $msg2 = mysql_num_fields($data); echo $msg2; echo "<br />"; $msg3 = mysql_fetch_row($data);//this is not shown for some reason echo $msg3; This is the code. I'd like to get a number out of the db, and convert the resource into just a number value or string, then alter the number in PHP (i know how to do that part) then put the number back into the db (I think I can do that also) I just don't know how to convert a resource ("$data") into a variable to use in the PHP code. Hopefully you know what I mean. (the output of the above code is) Shop choice method. you bought 1 archer Array Resource id #4 1
  3. Thanks. Maybe I'll try to figure out how to buy a book from amazon or something similar.
  4. What would the first steps to learning how be?
  5. Hello. I would like to know how to make a user account. I want to make a game someday, and the plan is to make the game using php, MySQL and maybe also java script. I know a small amount of things, but now I want to learn how to make user accounts.
  6. I signed in, then it said i was banned. I don't know what to do about the ban.
  7. Hello. I am wondering if anyone would like to talk with me on skype. I want to make a PHP game. At this point I don't think the manuals can tell me enough, even though I understood some of it. So anyways, if you would like to give a guy a little bit of help, please do. PM me if you are interested. Also if you cannot chat with me about it, maybe show me where I can find a good PHP irc chat room.
  8. I figured this out on my own. It requires simply that I put <select name="unit2" size="1"> So, the mods can lock this thread if they want. I'm glad I learned it.
  9. <html> <head> <title> Intro Room </title> </head> <body> Welcome to the shop. <br /> To the left is how many of this you want to buy. <br /> To the right is what you want to buy. <br /> <br /> <form action="shop1b.php" method="post"> Amount of this you want to buy: <input type="text" <input name="unit"> What you want to buy: <select> <option value="archer">archer</option> <option value="immortal_archer">immortal_archer</option> <option value="shield_infantry">shield_infantry</option> <option value="immortal_shield_infantry">immortal_shield_infantry</option> </select> <input type="submit"> </form> Archers : 1 hp, 1 attack, 0 defense, 100$ each. <br /> Immortal archers same status but can't be destroyed. 1000$ each. <br /> Shield_Infantry 1 hp, 0 attack, 2 defense, 100$ each. <br /> Immortal shield infantry same status but can't be destroyed. 800$ each. <br /> </body> </html> This is the code^. I was hoping that which ever option you select, it would give that string to $_POST somehow. But I don't know how to do it yet.
  10. ok buddy i will try that out right away. edit: ok it works, thanks allot. This helps be allot.
  11. <form action="shop1b.php" method="post"> Option number placed here: <input type="text" <input name="unit"> <input type="submit"> </form> This is what I've got so far. I can send 1 variable to the next page, which is "shop1b.php", but I don't know how to send more than one variable to the next page, and if I did send 2 variables, how would I use each of them in php?
  12. I just cut and pasted something out of the manual. It seems that it works now.
  13. ok, I just made a little bit of progress. $con = mysql_connect("localhost", 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db("test")) { echo "Failure" . mysql_error(); exit; } $buy = $_POST["unit"]; if ($buy == "1") { echo "you bought 1 archer"; // FROM not FORM. $data = mysql_query("SELECT Vals FROM vals2 WHERE ValsN = 'archers'"); if ($data == false) exit("This has failed"); $msg = mysql_fetch_assoc($data); echo "<br />"; echo $msg; echo "<br />"; echo $data; } ^That is my code. It echos something that says "Array Resource id #4". I'm wondering what do I do next to turn the resource into an integer or a string?
  14. it is returning a false. the error said it was a boolean value. this is as far as i got: $data = mysql_query("SELECT `test`.`vals2` FROM `vals2` WHERE `ValsN` = 'archers'"); if ($data == false) exit("This has failed"); $msg = mysql_fetch_assoc($data); echo $msg; echo $data; I'm sure I got the query wrong. In my screen shot i showed which part of the database I wanted to access.
  15. I noticed that and fixed it but i can't edit my first post it seems. What is the query returning anyways? When I try to echo it i get nothing.
  16. The manuals are amazing, but I lack the understanding to fully use them at this time. What i meant about "id as userid, fullname, userstatus, sometable" was that I don't know how each of those are supposedto be filled out, and what they are normally supposedto be like. The example query, i am not sure what to replace the examples with, you see. Once I understand it better I wont be asking about it and using up precious time, but right now I'm an absolute beginner, so that is why i made this thread.
  17. http://php.net/manual/en/function.mysql-fetch-assoc.php I found this after your suggestion. In the first example, part of it says: <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?> where it says: $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; I don't know what this means. What is id as userid, fullname, userstatus, sometable. ? This is why I the manuals are not enough for me on their own. They make referrences to things that a person is already supposedto know, but I don't know it.
  18. Which manual? I got the "SELECT Vals FORM vals2 WHERE ValsN = 'archers' " from SQLZOO. Even when I read the manual, the example seems to involve an interface that I do not have. Is there some other thing other than phpadmin that is used to manage a database in sql ? I was hoping someone could correct the code. I just changed it so that there is a " right before and after the query. Now there is no error message but I was hoping to get it to return the integer 0.
  19. if ($buy == "1") { echo "you bought 1 archer"; $data = mysql_query(SELECT Vals FORM vals2 WHERE ValsN = 'archers'); echo $data; } if ($buy == "2") { echo "you bought 5 archers"; } This is the code I am using.^ To manage the data bases I use http://localhost/phpmyadmin/ There is a table already that I made in phpadmin. http://s43.photobucket.com/user/fruitpooper/media/screenshot_zpsd9a1eeef.jpg.html I took a screen shot of it. The screen shot is above, as I can't paste it. Parse error: syntax error, unexpected T_STRING in D:\xampp\htdocs\MP_game\shop1b.php on line 21 This is the error message I get. All I want to do is read and change numbers. I had to edit this post too.
  20. <form action="shop1b.php" method="post"> Option number placed here: <input type="text" <input name="unit"> <input type="submit"> </form> <br /> Select a number, which ever number you select causes you to buy a certain amount of a certain unit. <br /> <br /> 1 = buy 1 archer. - 100 gold <br /> 2 = buy 5 archers. - 500 gold <br /> 3 = buy 50 archers. -5000 gold <br /> <br /> 4 = buy 1 shield man. - 100 gold <br /> 5 = buy 5 shield men. - 500 gold <br /> 6 = buy 50 shield men. -5000 gold <br /> this is the first html page <?php $buy = $_POST["unit"]; if ($buy == "1") { echo "you bought 1 archer"; } if ($buy == "2") { echo "you bought 5 archers"; } if ($buy == "3") { echo "you bought 50 archers"; } ?> and that is the php page which the single number is $_POST ed to. I had hoped that you could $_POST more than one number or string in a single form. Maybe you can and i dont know. But, the thing I posted just now works for me. I had to do some thinking.
  21. <form action="shop1b.php" method="post"> Buy this many archers: <input type="text" name="unit1"> <input type="submit"> </form> <form action="shop1b.php" method="post"> Buy this many shield men: <input type="text" name="unit2"> <input type="submit"> </form> I am using two forms, but i wanted to use about 20. Then they go to shop1b.php <?php $buy = $_POST["unit1"]; if ($buy == "1") { echo $_POST["unit1"]; echo $buy; } else exit("Please use only numbers."); $buy = $_POST["unit2"]; if ($buy == "5") { echo $_POST["unit2"]; echo $buy; } else exit("Please use only numbers."); ?> The goal of this is on the first page, with html, you put in the text variable, then in the next page, the php calculates how many units and what type of unit you want to build. "unit2" ends up as not being defined, and i don't know how to work around that. the php seems to need "unit1" and "unit2" to both be defined. I am trying my first steps at making a shop for a php game. If you can imagine that, maybe you will be able to see what I am struggling to accomplish.
  22. my next question would be if any of the people who have done that before would like to talk to me on skype. It could be possibly faster than asking every question in a thread. I know there are tutorials online and such, but I feel the need for a human source. I guess the question may have sounded retarded to some, but I still stand by it.
  23. Hi. I been away from php for a long time. I am an absolute beginner, but I think it's time to learn a few new things. So, one question is, have any of you people made a game with php, or a website? The reason why I want to learn php is so I can eventually make a multiplayer game.
  24. sorry what I meant was recordsets. or rows. I seem to see them as named both of those. But it's like an array to me. ``` <-- and now I know how to make these too. Ok that is it for me. I will continue to experiment and read more tutorial stuffs. Thanks allot everyone.
  25. Ok. Barand's code was exactly what I wanted. The only problem which remains is this strange one: I only know how to make ' , not ` But I need to make allot of ` Holding shift key doesn't work. Anyone know how to solve this mystery?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.