Dear List -

I wish to accomplish the following with prepared statements:

FYI -

The Database:

mysql> describe Intake3;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| Site   | varchar(6)  | NO   | PRI |         |       |
| MedRec | int(6)      | NO   | PRI | NULL    |       |
| Fname  | varchar(15) | YES  |     | NULL    |       |
| Lname  | varchar(30) | YES  |     | NULL    |       |
| Phone  | varchar(30) | YES  |     | NULL    |       |
| Height | int(4)      | YES  |     | NULL    |       |
| Sex    | char(7)     | YES  |     | NULL    |       |
| Hx     | text        | YES  |     | NULL    |       |
| Bday   | date        | YES  |     | NULL    |       |
| Age    | int(3)      | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+

The connection to the database was successful

The variables:

$fptr1 = fopen("/home/ethan/PHP/HRecnumSite", "r+");
fscanf($fptr1,"%d %s",$MedRec, $Site);

$_POST['MedRec'] = $MedRec;
$_POST['Site'] = $Site;
$fname = $_POST['Fname'];
$lname = $_POST['Lname'];
$phone = $_POST['Phone'];
$hgt   = $_POST['Height'];
$sx    = $_POST['Sex'];
$hx    = $_POST['Hx'];
$bday  = $_POST['Bday'];
$age   = $_POST['Age'];
if($sx==1)$_POST['Sex'] = 'F';
if($sx==0)$_POST['Sex'] = 'M';

Statement to convert:

$sql1 = "INSERT INTO Intake3(Site, MedRec, Fname, Lname, Phone, Height, Sex, Hx, Bday, Age) VALUES('$Site', $MedRec, '$fname', '$lname', '$phone', $hgt, '$sx', '$hx', '$bday', '$age')";

My attempt [which failed]

  $stmt = mysqli_stmt_init($cxn);
if($stmt = mysqli_stmt_prepare($stmt, "INSERT INTO Intake3 (Site, MedRec, Fname, Lname, Phone, Height, Sex, Hx, Bday, Age) VALUES(?,?,?,?,?,?,?,?,?,?")!=0)
    {
    print_r($stmt);
mysqli_stmt_bind_param($stmt, 'sisssisssi', $Site, $MedRec, $fname, $lname, $phone, $hgt, $sx, $hx, $bday, $age);
    mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $Site, $MedRec, $fname, $lname, $phone, $hgt, $sx, $hx, $bday, $age);
    echo $stmt;
    mysqli_stmt_fetch($stmt);
    mysqli_stmt_close($stmt);
    }
     else
         echo "Ouch";

Regrettably, all I see on the monitor is "ouch"!!

Help and advice, please.

Ethan Rosenberg





--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to