jcjst21 Posted April 30, 2012 Share Posted April 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261844-scripts-not-inserting-data/ Share on other sites More sharing options...
Jessica Posted April 30, 2012 Share Posted April 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261844-scripts-not-inserting-data/#findComment-1341716 Share on other sites More sharing options...
Zephni Posted April 30, 2012 Share Posted April 30, 2012 I think it may be the space (or lack of) inbetween your table name and values set. I usualy use this query style for inserting <?php $query = mysql_query("INSERT INTO table SET field='$this', another_field='$that'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261844-scripts-not-inserting-data/#findComment-1341719 Share on other sites More sharing options...
Jessica Posted April 30, 2012 Share Posted April 30, 2012 You do not need a space between table name and VALUES(), and I've never seen the syntax you're describing. Quote Link to comment https://forums.phpfreaks.com/topic/261844-scripts-not-inserting-data/#findComment-1341782 Share on other sites More sharing options...
Zephni Posted May 3, 2012 Share Posted May 3, 2012 Try it, it works I find it easier because then you don't have to worry about ordering your field names and stuff... Quote Link to comment https://forums.phpfreaks.com/topic/261844-scripts-not-inserting-data/#findComment-1342560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.