Tenaciousmug Posted August 4, 2010 Share Posted August 4, 2010 I think I'm using the wrong method, but GET and POST don't seem to fit in at all. I'm making a random game where they can only play 20 times a day. Once they hit that roll again button, I want a string to go into the database. And then after that, I will pull all those.. whatever I know how to do that part, but I just want to know why the button isn't making it insert all those values into the fields. <?php $dice = rand(1,6); echo "You rolled a<br /><b>{$dice}</b>\n"; $winnings = "500"; if($dice == 6) { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $username = $cxn->real_escape_string($_SESSION['username']); $sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'"; mysqli_query($cxn,$sql); }?> <FORM ACTION="random.php" METHOD="post"> <INPUT TYPE="submit" VALUE="Roll Again! NAME="sixdice"> </FORM> <?php if (@$_POST['sixdice']) { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $userid = "$_SESSION['userid']"; $username = "$_SESSION['username']"; $sql = "INSERT INTO Sixdice (userid,username,rolltime) VALUES ('$userid','$username',NOW())"; $result = mysqli_query($cxn,$sql) or die("Query died: insert"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209840-submit-button-not-going-into-database/ Share on other sites More sharing options...
Tenaciousmug Posted August 4, 2010 Author Share Posted August 4, 2010 Also a simple question that would be helpful on this other part: <?php include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase) or die("Couldn't connect to server"); $today = date("Y-m-d"); $userid = $_SESSION['userid']; $sql = "SELECT userid FROM Sixdice WHERE rolltime='$today'"; $result = mysqli_query($cxn,$sql) or die(mysqli_error($cxn)); $row = mysqli_fetch_array($result); if($row['rolltime'] > 20) { ?> Very simple code. Buuut I want to know how you can SELECT $userid FROM Sixdice WHERE rolltime='$today'"; I want to select the $_SESSION[userid], but how do I type that variable into the string? Quote Link to comment https://forums.phpfreaks.com/topic/209840-submit-button-not-going-into-database/#findComment-1095354 Share on other sites More sharing options...
Tenaciousmug Posted August 4, 2010 Author Share Posted August 4, 2010 IGNORED THIS TOPIC. I FOUND A LOT OF ERRORS! xD i am redoing the whole table for this game and such. I will probably make a new topic. Quote Link to comment https://forums.phpfreaks.com/topic/209840-submit-button-not-going-into-database/#findComment-1095363 Share on other sites More sharing options...
Tenaciousmug Posted August 4, 2010 Author Share Posted August 4, 2010 Wait. Omg I'm so sorry for doing this. Just a random question, how do you make it so when you hit a button, it will update the roll count in the database without actually.. posting something. I know how to add a pet into a database using a form. BUUT just randomly clicking a button and adding that rollcount + 1 into the database. As you can see, I have : <?php if(@$_POST['sixdice']) { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $userid = $_SESSION['userid']; $add = "1"; $sql = "UPDATE Sixdice SET rollcount = rollcount+$add WHERE userid = '$userid'"; mysqli_query($cxn,$sql); } }else{ echo "you have already played this game 20 times"; } ?> I have everything correct, BUT the if(@$_POST['sixdice']) x_x Im just so confused on this. Quote Link to comment https://forums.phpfreaks.com/topic/209840-submit-button-not-going-into-database/#findComment-1095366 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.