PHP/mysql problem

Hi need some urgent help!!

I have a php form that is not saving the information to the database, sometimes it does and sometimes it doesnt . I have the assumption the problem must be user error but I really have no idea, hope somebody can help me out. The form is part of an electronic medical record the following is the code:

[php]

<?php include_once("../../globals.php"); include_once("$srcdir/api.inc"); include_once("$srcdir/forms.inc"); $prov = $_SESSION['authUserID']; $enc = $_SESSION['encounter']; $pid = $_SESSION['pid']; $date = date('Y/m/d h:i:s a'); $fr = $_POST['fr']; $fc = $_POST['fc']; $tas = $_POST['tas']; $tad = $_POST['tad']; $temp = $_POST['temp']; $gluc = $_POST['gluc']; $sat = $_POST['sat']; $pad = $_POST['padecimiento']; $ant = $_POST['antecedentes']; $exp = $_POST['exploracion']; $grupo = $_POST['grupo1']; $code = $_POST['code']; $diag = $_POST['diagnostico']; $man = $_POST['manejo']; $act = "1"; $table_name = "form_notaC"; if ($encounter == "") $encounter = date("Ymd"); mysql_query("INSERT INTO form_notaC (pid,date,provider,encounter,fr,fc,tas,tad,temp,gluc,sat,padecimiento,antecedentes,exploracion,code,grupo1,diagnostico,manejo,activity) VALUES ('$pid', '$date','$prov', '$enc',$fr','$fc','$tas','$tad','$temp','$gluc','$sat','$pad','$ant','$exp','$code','$grupo','$diag','$man','$act')"); $id =mysql_insert_id(); addForm($encounter, "Nota de Consulta", $id, "notaC", $pid, $userauthorized); formHeader("Redirecting...."); formJump(); ?>

[/php]

I just want to say one thing…

It’s hardly ever user error, it’s usually poorly written code.

Do you get any error messages?

Thanks for answering, and no I don’t get any error message, you are right it must be bad coding, I know very little PHP from tutorials, I just cant make the form save to MySQL. y notice that I can replicate the action if I add a ’ to the textarea so I added MySQL_escape_string hopefully it will solve my problem, any tips you can offer on debugging?

mysql_real_string_escape() should take care of it otherwise you can try addslashes().

You can also try adding or die() to your sql statement like so…
[php]
$sql = mysql_query(“SELECT * FROM something”) or die("Error: " . mysql_error());
[/php]

That should return an error (if any) and give the relative position of the error occurence

Thanks again my friend I appreciate your help. :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service