2
I tried to make a code here, but it didn’t go very well... they know to inform 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>
<?
}
?>
What error appears?
– Fleuquer Lima
The mistake starts when I read
mysql
in the code. And not givingecho
in thePHP_SELF
.– Leonardo
There is no error... Actually no action is taking place when I click the button!
– Eduardo Henrique
@Eduardohenrique, I have a PDO class on github. Feel free to use. https://github.com/LucaoA/connectionPDO/blob/master/Connection.php
– LucaoA
For the record, if you want to send it to the same page, just omit the action. BUT, I don’t think it’s bad if you specify the address, because although it’s not a very common thing to happen, explain the URL, avoid "clickjacking" if someone calls your form in
iframe
. As @Magichat said, to access PHP_SELF is used$_SERVER["PHP_SELF"]
– Bacco