Hi people,
I created a script that makes a table and got the update, but if the wrong user inserise it should show the error:
echo “
O seu pedido foi recusado, o utilizador não existe na DataBase.”;
But only just shows that the request was successful even when wrong.
I think it is but I’m not sure:
if(verificarUser($user) == True)
This is my code:
[php]<?php
require("common.php");
global $host, $dbname, $username, $password, $options;
$user = $_POST['username'];
$credits = $_POST['credit_amount'];
if(verificarUser($user) == True)
{
$dbh = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
$sql = "UPDATE users SET credits = '{$credits}' WHERE username = '{$user}'";
$count = $dbh->exec($sql);
echo "<br /><font color='green'>O pedido foi realizado com sucesso na conta <b>$user</b> com <b>$credits creditos</b>.</font>";
$dbh = null;
}
else
{
echo "<br /><font color='red'>O seu pedido foi recusado, o utilizador não existe na DataBase.</font>";
}
function verificarUser($username)
{
global $host, $dbname, $username, $password, $options;
//connect database
$dbh = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
$procurarUser = $dbh->prepare("SELECT * FROM users");
$procurarUser->execute(array('username' => $username));
//save results
$procurarUser->execute();
//search
$checkUser = $procurarUser->fetchAll();
$dbh = null; //close db
if(count($checkUser) > 0)
{
return True;
}
else
{
return False;
}
}
?>[/php]