Update table attribute, via Form? php $ PHP_SELF?

2

I tried to make a code here, but it did not work very well ... can you tell me where the error is?

<?
     if(isset($_POST['reseta_wl'])) {
        $dbhost = '127.0.0.1';
        $dbuser = 'root';
        $dbpass = '';

        $conn = mysql_connect($dbhost, $dbuser, $dbpass);

        if(! $conn ) {
           die('Could not connect: ' . mysql_error());
        }

        $id = $_SESSION['s_usuario'];

        $sql = "UPDATE game ". "SET credito = 30 ". 
           "WHERE id = $id" ;
        mysql_select_db('gbwc');
        $retval = mysql_query( $sql, $conn );

        if(! $retval ) {
           die('Could not update data: ' . mysql_error());
        }
        echo "Updated data successfully\n";

        mysql_close($conn);
     } else {
        ?>
          <form method="post" action="<?php $_PHP_SELF ?>">
           <input type="button" name="reseta_wl" value="Resetar">
          </form>
        <?
     }
  ?>
    
asked by anonymous 18.06.2016 / 15:50

2 answers

1

As stated by the commentators, mysql functions should be replaced by mysqli functions.

Regarding your code error alone is not an exit function.

Change to action=" <?php echo $_SERVER['PHP_SELF'];?> "

for more details go to:

link

and link

You help yourself and make a comeback.

    
18.06.2016 / 18:41
0

I came up with this result ...

<?
 if(isset($_POST['reseta_wl'])) {
    $id = $_SESSION['s_usuario'];
    $result = mysql_query("select * from game where id = '$id'");
    $usr = mysql_fetch_array($result);
    $coin = $usr['credito'];
    $sql = "UPDATE game SET credito = $coin-20 WHERE id = '$id'";
    if(mysql_query($sql, $link)){
       echo "Atualizado com sucesso.";
    } else{
       echo "Not able to execute $sql.";
    }


    mysql_close($link);
 } else {
    ?>
      <form method="post" action="">
       <input type="submit" name="reseta_wl" value="Resetar">
      </form>
    <?
 }?>

But the select I'm trying to give to the table is not working, since the math operation is not being performed. Does anyone know where I'm going wrong?

    
18.06.2016 / 21:20