Jump to content

Submit button not going into database?


Tenaciousmug

Recommended Posts

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");
      }
?>

Link to comment
https://forums.phpfreaks.com/topic/209840-submit-button-not-going-into-database/
Share on other sites

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.