Problem when modifying fields in a table (Not stored)

0

Greetings, I have a problem with the following code, after trying I realized that something is happening with my variables that when I put them I stopped updating the data, I explain:

I have the following code that works perfect for me:

if ($boton == "Modificar"){
	if ($cedula!=""){
		$sql="update datosbasicos set CED_PAC=$cedula, NOM_PAC='$nombre', APE_PAC='$apellido',EDAD_PAC='$edad', HIS_PAC='$nhistoria', DIR_PAC='$direccion', TEL_PAC='$telefono', CEL_PAC='$celular', SEX_PAC ='$sexo' where CED_PAC='$cedula'";
		mysql_query($sql);
		echo "<script>alert('Datos modificados correctamente')</script>";
		echo "<script>window.location='registro.php'</script>";
	}
	else{
		echo "<script>alert('Para poder modificadar debe realizar una busqueda')</script>";
		echo "<script>window.location='registro.php'</script>";
	}
}

Now, I need to modify that code and add the following variables so that I can modify different fields of another table, it would look like this:

if ($boton == "Modificar"){
	if ($cedula!=""){
		$sql="UPDATE datosmedicos SET COD_CONSULTA='$codigo', ALT_PAC= '$altura', PESO_PAC='$peso', FECHA='$fecha', TIPO_CONSULTA='$tipconsulta', SINTOMAS='$sintomas', OBSERV='$observacion', HIS_PAC='$nhistoria', MEDI_PAC='$medicamentos', OPERADO='$operado', ALERGIAS='$alergias' where CED_PAC='$cedula'";
		mysql_query($sql);
		echo "<script>alert('Datos modificados correctamente')</script>";
		echo "<script>window.location='consulta.php'</script>";
	}
	else{
		echo "<script>alert('Para poder modificadar debe realizar una busqueda')</script>";
		echo "<script>window.location='consulta.php'</script>";
	}
}

This code no longer works for me, from the moment I put the first variable it stops working, although it tells me that it has been stored correctly, no change happens.

I do not think it's because I'm not working with MySQLi like they told me once, because then the first code would not work, I checked the database and the fields are correct. Does anyone have an answer?

Thank you very much.

EDIT

I show how I have declared the variables in case someone wants to see:

    <?php  

include('conexion.php');
$boton = $_POST["boton"];
$cedula = $_POST["CED_PAC"];
$nombre = $_POST["NOM_PAC"];
$apellido = $_POST["APE_PAC"];
$edad = $_POST["EDAD_PAC"];
$nhistoria = $_POST["HIS_PAC"];
$direccion = $_POST["DIR_PAC"];
$telefono = $_POST["TEL_PAC"];
$celular = $_POST["CEL_PAC"];
$sexo = $_POST["SEX_PAC"];
$codigo = $_POST["COD_CONSULTA"];
$fecha = $_POST["FECHA"];
$tipconsulta = $_POST["TIPO_CONSULTA"];
$observacion = $_POST["OBSERV"];
$sintomas = $_POST["SINTOMAS"];
$peso = $_POST["PESO_PAC"];
$altura = $_POST["ALT_PAC"];
$operado = $_POST["OPERADO"];
$alergias = $_POST["ALERGIAS"];
$medicamentos = $_POST["MEDI_PAC"];

DATABASE

I have the database in the following way:

    
asked by Pablo Pernia 16.08.2017 в 14:33
source

1 answer

0

Hi Pablo Pernia ,

According to what you indicate, if the code you execute first if you modified the data correctly and the second one does not, the error may be that the new variables that you are sending are defined in your database as integer type data and You are sending it as a string type.

Verify the following:

That the query variable order is equal to the order of variables in your database.    Example: If your database is Cedula (INT), Name (Varchar), Surname (Varchar). Then send in the query UPDATE datosbasicos SET Cedula=$Cedula, Nombre='$Nombre', Apellido='$Apellido' WHERE Cedula=$Cedula.

As you can see in the example I gave you, in this case Cedula is as a whole, then I send it without quotes and First Name and Surname are like Varchar so I send them String type enclosing it in quotes.

To consider:

It is not recommended that a single registration such as the Certificate can be modified, it is advisable to carry out the search by the Identity Card and modify the rest of the data.

    
answered by 16.08.2017 в 16:07