Jump to content

scripts not inserting data


jcjst21

Recommended Posts

Hello,

I have three scripts below that I was wondering if someone can look at as a second opinion.

 

What they all have in common is they are supposed to append data to some tables in my database.  They match the code on all my other scripts but for some reason these particular scripts will not append the data to the files.

 

This first one...

is supposed to insert the name of the doctor this person uses, and then gets the last ID created and inserts it into another table...no matter what I try, it will not do it.

 

<?php

session_start();
$userid=$_SESSION['userID'];
$firstName=$_SESSION['fname'];
$lastName=$_SESSION['lname'];
$camperID=$_POST['camperID'];
$physicianFName=$_POST['physicianFName'];
$physicianLName=$_POST['physicianLName'];
$physicianSuffix=$_POST['physicianSuffix'];
$practiceName=$_POST['practiceName'];
$physicianAddress1=$_POST['physicianAddress1'];
$physicianAddress2=$_POST['physicianAddress2'];
$physicianAddress3=$_POST['physicianAddress3'];
$physicianCity=$_POST['physicianCity'];
$physicianState=$_POST['physicianState'];
$physicianZip=$_POST['physicianZip'];
$physicianOfficeP=$_POST['physicianOfficeP'];
$physicianOfficeF=$_POST['physicianOfficeF'];
$physicianSpecialty=$_POST['physicianSpecialty'];


echo $camperID. ' ' .$physicianFName. ' ' .$physicianLName;

//htc information and physician

$htcName=$_POST['htcInfo'];
$htcPhysician=$_POST['htcPhysician'];

$con=mysql_connect("xxx.xxx.xxx.xx", "xxx", "xxxx") or die ("cannot connect");
mysql_select_db("testcamp") or die ("cannot select database");

$sql="INSERT INTO Physicians(physicianFName, physicianLName, physicianSuffix, practiceName, physicianAddress1, physicianAddress2, physicianAddress3, physicianCity,
physicianState, physicianZip, physicianOfficeP, physicianOfficeF, physicianSpecialty) VALUES ('$physicianFName', '$physicianLName', '$physicianSuffix', '$physicianAddress1',
'$physicianAddress2', '$physicianAddress3', '$physicianCity', '$physicianState', '$physicianZip', '$physicianOfficeP', '$physicianOfficeF', '$physicianSpecialty')";

$result=mysql_query($sql,$con);
$physicianID=mysql_insert_id();

$sql2="INSERT INTO CamperPhysicianInfo(physicianID, camperID) VALUES ('$physicianID', '$camperID')";
$result2=mysql_query($sql2,$con);

$sql3="INSERT INTO CamperHTCInfo(camperID, htcID) VALUES ('$camperID', '$htcName')";
$result3=mysql_query($sql3,$con);

$sql4="INSERT INTO camperHTCPhysicianInfo(camperID, htcPhysicianID) VALUES ('$camperID', '$htcPhysician')";
$result4=mysql_query($sql4,$con);

?>

 

This next one...is supposed to enter data into the CamperRegistrations tables and also enter data into another table for a questionaire that was completed on the form previous to this page...same thing no matter what I try will not append data.

 

<?php

$question12=$_POST['question12'];
$question12a=$_POST['question12a'];





session_start();
$userid=$_SESSION['userID'];
$firstName=$_SESSION['fname'];
$lastName=$_SESSION['lname'];

$camperID=$_SESSION['camperID'];


$con=mysql_connect("xxx.xxx.xxx.xx", "xxx", "xxx") or die ("cannot connect");
mysql_select_db("testcamp") or die ("cannot select database");

$sql="INSERT INTO Question12(camperID, question12Answer, teaching) VALUES ('$camperID', '$question12', '$question12a')";
$result=mysql_query($sql,$con);

$date=date("Y-m-d");
$defaultStatus=1;

$sql2="INSERT INTO CamperRegistrations(userID, camperID, registrationDate, registrationStatus) VALUES ('$userid', '$camperID', '$date', '$defaultStatus')";
$result2=mysql_query($sql2,$con);

?>

 

and then on this same page with this script...

is it possible to carry session information when using HTML links instead of a submit form?

 

I need the userid to carry to the next page with a link, but it won't do that either...

 

Any help would be appreciated and thanks in advance for looking.

 

~jcjst21

 

Link to comment
Share on other sites

no matter what I try, it will not do it.

...

but it won't do that either...

FYI, This is a very useless way to ask for help. Always describe what DOES happen.

 

As for your code, you're not checking for any errors when querying. Look at the docs for examples. http://us.php.net/mysql_query (#2 is better than #1)

I can see the error in your insert statement that is causing it to fail, but since you're not checking for errors you don't know that it even failed. I will say your descriptive variable names make it quite easy to spot.

 

Last thing, once you get it working, read about sanitizing data.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.