0

my form has an option where user can choose to fill but should that option be choose then the form will will submit to two tables if not chosen the one table using php/mysql.table being patient and insurance table. Prompt assistance will be appreciated.thanks

$query = "insert into patients (title,patientid,name1, name2, name3, dob, gender, marital, image, address,mobilenumber, emergencynumber,city,position,employername,relationship,insuranceprovider) values ('$thistitle','$thisid','$thisname1','$thisname2','$thisname3','$thisdate','$thisgender','$thismarital','$thisphoto','$thisaddress','$thismobile','$thisemergency','$thiscity','$thisposition','$thisemployername','$thisrelationship','$thisinsuarance')";
$result = mysql_query($query);
echo 'successful';
if($result){
    echo 'successful';
    $sql="insert into insuarance_table set patient_id='$thisid', insuarance_no='$thisinsid',place_of_reg='$thisdistrict',date_expiring='$thisdoe',date_reg='$thisdoi'";
    $sql1=mysql_query($sql);
    if(!$sql1){
        echo 'wrong'.mysql_error();
    }
    }
3
Contributors
8
Replies
66
Views
3 Years
Discussion Span
Last Post by SirMahlon
0

my form has an option where us

should that option be choose then the form will will submit to two tables if not chosen the one table using php/mysql.table

should that option be choose then the form will will submit to two tables if not chosen the one table using php/mysql.table being patient and insurance table

do you have an idea of how to doing this??
you can use checkbox, here is a example:

html code:

<form name="reg_form" method="post" action="">
<input type="hidden" name="form_name" value="reg_form">
<input id="choose" type="checkbox" checked="checked" name="choose_both" />

<input name="patient_name" type="text" placeholder="enter a name"/>

<input name="patient_father_name" type="text" placeholder="patient's father name"/>

<input type="submit" name="register" value="register" />
</form>

now here is the php:

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'reg_form')
{

//now connect to db here, i am using pdo, 
//currently you are using mysql, you should switch to pdo or mysqli. 
//mysql will be no longer supported in near future.
   try
   {
   $pdo = new PDO('mysql:host=localhost;dbname=patient_info', 'username', 'password');
   }
   catch (PDOException $e)
   {
    $output = 'Unable to connect to the database server.';
    echo $output;
    exit();
    }

// the first query

    try
{
    $sql = "INSERT INTO patient_reg_info SET patient_name = :name";
    $s = $pdo->prepare($sql);
    $s->bindValue(':name', $_POST['patient_name']);
    $s->execute();
}
catch (PDOException $e)
{
$error = 'error getting and iserting data';
echo $error;
exit();
}

// the second conditional query

$choose_both = isset($_POST['choose_both']) ? true : false;
if ($choose_both)
{
try
{
    $sql = "INSERT INTO patient_family_info SET patient_father_name = :father_name";
    $s = $pdo->prepare($sql);
    $s->bindValue(':father_name', $_POST['father_name']);
    $s->execute();
}
catch (PDOException $e)
{
$error = 'error getting and iserting data';
echo $error;
exit();
}

$more="and also saved the his dad's name"
}

echo "wow, we have entered the patient info.";  
echo $more;


}

didn't tested out yet, but this should work :) cheers

0

this is what i want to do.I want to save into the insurance table only if the user selects payments mode to be health insurance from the dropdown box.but now even should the user select cash and carry the a record is still added to insurance table though it's sends empty data. something like
insert into patients table(values);
if successful
insert into insurance table where dropdown box = 'health insurance';

0

Okay so let me get this straight, i just read your code, there you added if ($result) so you want the second query to run only if the first one is successful.

The only part i am not getting is you said if the user select some option(whatever checkbox or radio)then the second query should run and create a record in the insurance table, right but where is the php code for that part???

Instead your second query will always execute if the first one is successful. So even if the user does not select the option, it wi always run and insert NULL value.

Can post your html and both php code? It is so confusing.

0
//retrieving form element
    @$thistitle =addslashes($_REQUEST['title']);
    @$thisid =addslashes($_REQUEST['id']);
    @$thisname1 = addslashes($_REQUEST['name1']);
    @$thisname2 = addslashes($_REQUEST['name2']);
    @$thisname3 =addslashes($_REQUEST['name3']);
    @$thisdate = addslashes($_REQUEST['date']);
     @$thisgender = addslashes($_REQUEST['gender']);
       @$thismarital=addslashes($_REQUEST['marital']);
     @$thisphoto=addslashes($_REQUEST['photo']);
     @$thisaddress=addslashes($_REQUEST['address']);
    @$thismobile=addslashes($_REQUEST['mobile']);
     @$thisemergency=addslashes($_REQUEST['emergency']);
     @$thiscity=addslashes($_REQUEST['city']);
        @$thisposition=addslashes($_REQUEST['position']);
    @$thisemployername=addslashes($_REQUEST['employername']);
    @$thisrelationship=addslashes($_REQUEST['relationship']);
    @$thisinsuarance=addslashes($_REQUEST['insurance']);
    @$thisinsid=addslashes($_REQUEST['insid']);
    @$thisdoi=addslashes($_REQUEST['doi']);
    @$thisdoe=addslashes($_REQUEST['doe']);
    @$thisdistrict=addslashes($_REQUEST['district']);
        $query = "insert into patients (title,patientid,name1, name2, name3, dob, gender, marital, image, address,mobilenumber, emergencynumber,city,position,employername,relationship,insuranceprovider) values ('$thistitle','$thisid','$thisname1','$thisname2','$thisname3','$thisdate','$thisgender','$thismarital','$thisphoto','$thisaddress','$thismobile','$thisemergency','$thiscity','$thisposition','$thisemployername','$thisrelationship','$thisinsuarance')";
$result = mysql_query($query);
echo 'successful';
if($result){
    echo 'successful';
    $sql="insert into insuarance_table set patient_id='$thisid', insuarance_no='$thisinsid',place_of_reg='$thisdistrict',date_expiring='$thisdoe',date_reg='$thisdoi'";
    $sql1=mysql_query($sql);
    if(!$sql1){
        echo 'wrong'.mysql_error();
    }
    }
?>

what i really want to do is save into the insurance table if the option national health is selected in the drop downbox

0

You really should not use $_REQUEST, Use $_POST instead.
Where is national health var. There is a lot of variable where you register request data but which one is for national health.

can you post your html form code for this.

0

the health insurance var is the $thisinsurance.so i want do something like
save the second insert query where $thisinsurance = 'National health insurance'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.