I have my database created, in it a table with the fields, ID, VALUE, VALUE2, TIME, I have my PHP file that I enter the values (VALUE AND VALUE2), which is this:
<?php
$conexion = mysql_connect("localhost", "usuarioservidor", "1234");
mysql_select_db("bdservidor",$conexion);
mysql_query("INSERT INTOtablaservidor(valor,valor2) VALUES ('" . $_GET['valor'] . "','" . $_GET['valor2'] . "')", $conexion);
?>
perfect all right there, I inserted the data correctly, I assigned the ID and TIME, the question is as follows, when I enter only one data for example be VALOR
or VALOR2
, the other data assigns me a 0
, how can I do so that the other value stays the previous one, and configure in the options so that I put a NULL
, but it does not work for me, because I am extracting information from that database with this code:
<?php
$dbhost = 'localhost';
$dbuser = 'usuarioservidor';
$dbpass = '1234';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT ID, VALOR, VALOR2, TIEMPO FROM tablaservidor ORDER BY id DESC limit 1' ;
mysql_select_db('bdservidor');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM)) {
echo
" id={$row[0]} \n ".
"valor={$row[1]} \n ".
"valor2={$row[2]} \n ".
"tiempo={$row[3]} \n ".
"";
}
mysql_free_result($retval);
//echo " Datos leidos de la base de datos MYSQL\n";
mysql_close($conn);
?>'
when I extract the values and only assign a value to VALUE and not to VALOR2
shows me this:
I need the other data to keep the last value even if I assign a single value to any of the 2, is that I'm turning on some LEDs by this I do not need to be assigned neither NULL
, nor 0, I need to I keep the last value even though I only give you one piece of information, I appreciate it if someone can help me.