I have the following source code in PhP which, after doing a subtraction, leaves it as it is and does not return the entered result to be its original value:
<?php
// Database configuration parameters
include "../../includes/db_connect2.php";
include "../../includes/db_connect_mysql.php";
//Form Data
$ip = $_SERVER['REMOTE_ADDR'];
$pw = $_POST['pw'];
$certa = $_POST['certa'];
$DP = $_POST['DP'];
$UserID = $_POST['UserID'];
if (isset($_POST['submit']))
{
if (empty($_POST['UserID'])) {
die('You didn\'t specify an Account Name!');
}
$cert = mssql_query ('SELECT * FROM PS_UserData.dbo.Users_Master
WHERE UserID = \'' . $certa . '\' and pw=\'' . $pw . '\' and status = 16
and Verifi in (1,2,3)');
//$active = mssql_fetch_array ($cert);
if(mssql_num_rows($cert)==0)
die ('Disculpe o usted no es parte del Staff o La contraseña o Usuario No son Validos, Por Favor Intente de nuevo.');
// Asigane UserID y UserUID
$recar1 = mssql_query ('
SELECT UserID, UserUID FROM PS_UserData.dbo.Users_Master
WHERE UserID = \'' . $UserID . '\'
');
$active0 = mssql_fetch_array ($recar1);
if(mssql_num_rows($recar1)==0)
die ('El Usuario NO existe.');
echo "<center>";
print"Antes de ejecutar dicha consulta.";
print"
<table border=1 cellpadding=5 cellspacing=0>
<CAPTION>Antes</CAPTION>
<tr>
<td WIDTH=180><font size=2 face=arial color=red><b>UserID</b></td>
<td WIDTH=180><font size=2 face=arial color=red><b>Puntos</b></td>
</tr>
</table>";
$recar2 = mssql_query ('
SELECT UserID, UserUID FROM PS_UserData.dbo.Users_Master
WHERE UserID = \'' . $UserID . '\'
');
$active1 = mssql_fetch_array ($recar2);
$Antes = mysqli_query($conexion,'
SELECT MAX(ID)
ID,
id_usuario,
precio_final
FROM sr_pedidos
WHERE id_usuario = \''.$active1[1].'\'
');
$AntesR = mysqli_fetch_array ($Antes);
print"
<table border=1 cellpadding=5 cellspacing=0>
<tr>
<td WIDTH=180><font size=2 face=arial>".$active1[0]."</td>
<td WIDTH=180><font size=2 face=arial>".$AntesR[2]."</td>
</tr>
</table>";
//De aqui sacaremos el ID de pedidos
$sacra = mysqli_query($conexion,'
SELECT MAX(ID)
ID,
id_usuario,
precio_final
FROM sr_pedidos
WHERE id_usuario = \''.$active0[1].'\'
');
$sacra1 = mysqli_fetch_array ($sacra);
// Aqui resta los Puntos
$scale_Record1 = mysqli_query($conexion,'
UPDATE sr_pedidos
SET precio_final = precio_final - '.$DP.'
WHERE id_usuario = \''.$active0[1].'\'
');
// Aqui NO VERIFICA si es menor que cero
$verifi1 = mysqli_query($conexion,'
SELECT
ID,
id_usuario,
precio_final
FROM sr_pedidos
WHERE id_usuario = \''.$active3[1].'\'
and
precio_final < 0
ORDER by ID ASC
LIMIT 1
');
ERROR no verifica----> IF (mysqli_fetch_array ($verifi1) > 0)
{
por lo tanto aqui no devuelve el resultado en caso que el numero sea negativo--->>> $devol = mysqli_query($conexion,'
UPDATE sr_pedidos
SET precio_final = precio_final + '.$DP.'
WHERE id_usuario = \''.$AntesR[1].'\'
// ');
PRINT "Puntos devueltos por que sobre paso a negativo";
}
//}
else
{
PRINT "Puntos Restados con exito";
}
//}
echo "<center>";
print"Despues de ejecutada dicha consulta.";
print"
<table border=1 cellpadding=5 cellspacing=0>
<CAPTION>Despues</CAPTION>
<tr>
<td WIDTH=180><font size=2 face=arial color=red><b>UserID</b></td>
<td WIDTH=180><font size=2 face=arial color=red><b>Puntos</b></td>
</tr>
</table>";
$recar3 = mssql_query ('
SELECT UserID, UserUID FROM PS_UserData.dbo.Users_Master
WHERE UserID = \'' . $UserID . '\'
');
$active2 = mssql_fetch_array ($recar3);
$despues = mysqli_query($conexion,'
SELECT MAX(ID)
ID,
id_usuario,
precio_final
FROM sr_pedidos
WHERE id_usuario = \''.$active2[1].'\'
');
$despuesr = mysqli_fetch_array ($despues);
print"
<table border=1 cellpadding=5 cellspacing=0>
<tr>
<td WIDTH=180><font size=2 face=arial>".$active2[0]."</td>
<td WIDTH=180><font size=2 face=arial>".$despuesr[2]."</td>
</tr>
</table>";
}
?>
<html>
<head>
<title>A.P. Deleation</title>
</head>
<font face="Trebuchet MS">
<center><body><br /><br />
<b>A.P. Deleation</b>
<form action="<?php
echo $_SERVER['PHP_SELF'];
?>" method="POST">
<table>
<tr><td>Tu UserID de Staff:</td><td><input type="text" placeholder = "UserID o Usuario Staff" name="certa" /></td></tr>
<tr><td>Tu Contraseña de Staff:</td><td><input type="password" type="text" placeholder = "Clave o Usuario Staff" name="pw" /></td></tr>
<tr><td>UserID:</td><td><input type="text" name="UserID"/></td></tr>
<tr><td>Cantidad de AP que le restaras:</td><td><input type="text" name="DP"/></td></tr>
</table>
<p><input type="submit" value="Submit" name="submit" /></p>
</form>
</body></center>
</html>
OK assuming I subtract in final_price by subtracting a number '1' that is, this is Current table
ID_Usuario precio_final
255 1
UPDATE Table SET final_price = final_price - 10
ID_Usuario precio_final
255 -9
What I do not want is that if the number goes to negative this will stay in the table and return its ORIGINAL value remaining in case of the error that does not verify like this:
ID_Usuario precio_final
255 1
What is happening to me now is that I do the subtraction and continues subtracting the negative DOES NOT RETURN ITS ORIGINAL VALUE.