|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
MySQL Insert Problem
I'm having a very strange problem when submitting data from a PHP form into a MySQL database. You can enter the data in, and it it will act like it has submitted the data to the database, but there is no trace of it. You then re-enter the data into the form and submit it again and it will write it to the database, but the auto increment number has moved on 2 - almost as if it has written and then deleted the previous submission. There is no delete statement in any of the code. The database is on a Unix box and the user access's the database via Citrix.
|
|
#2
|
||||
|
||||
|
I suggest putting an or die() command on your mysql_query.
There's a chance your query is failing. Having not seen the code, it's hard to tell. For example: $result = mysql_query($sql) or die("MySQL Error ".mysql_errno().": ".mysql_error()."<br>\nThe query was: ".$sql); How many queries does your action have? Only the one insert query? |
|
#3
|
|||
|
|||
|
There is only one action - here's the code it uses:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ClientDetails")) { $insertSQL = sprintf("INSERT INTO clientdetails (FirstName, Surname, DOB, Gender, Address1, Address2, Address3, PostCode, PhoneNumber, MobileNumber, FirstLanguage, DisabilitiesNeeds, EthnicGroup, SourchOfContact, DateOfContact, ContactMade, AgreeToAssessed, CurrentLegalStatus, SentenceLength, Offence1, MainDrug, CurrentTreatment, Treatment, Medication, Prescriber, PrescriberAdd1, PrescriberAdd2, PrescriberPCode, PrescriberTel, PrescriberFax, ContactMadeDetails, LegalStatusDetails, Offence1OtherDetails, OtherDrugDetails, DIRRef, WorkersTel, DateToCC, WorkersName, WorkersLocation, Offence2, Offence2OtherDetails, IntroductionMadeDetails, YesReason, NoReason, YesNoDetails, RefMadeBy, SPOCRecDt, CurLoc, ReleaseDt, DIRStatus, XFer, OtherArea, ExitReason, EXCDate, AssCompDt, FIAccepted, FIRefuseReason, FIRefuseOther, CPDone, CPDoneDt, CDRPArea, OtherUsedDrugs, PPO, HarmMin, BasicSkills, HousingNeeds, `247SPOC`, FTEmpTrain, EpisodeNo, PrisonRelDtd, FINeeded, IntoTreatDt, MainAgency, OthAgency, BasicSkillsRef) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['FirstName'], "text"), GetSQLValueString($_POST['Surname'], "text"), GetSQLValueString($_POST['DOBFlip'], "date"), GetSQLValueString($_POST['Gender'], "text"), GetSQLValueString($_POST['Address1'], "text"), GetSQLValueString($_POST['Address2'], "text"), GetSQLValueString($_POST['Address3'], "text"), GetSQLValueString($_POST['PostCode'], "text"), GetSQLValueString($_POST['PhoneNo'], "text"), GetSQLValueString($_POST['MobileNo'], "text"), GetSQLValueString($_POST['Language'], "text"), GetSQLValueString($_POST['SpecialNeeds'], "text"), GetSQLValueString($_POST['Ethnicity'], "text"), GetSQLValueString($_POST['Introduction'], "text"), GetSQLValueString($_POST['IntContactDateFlip'], "date"), GetSQLValueString($_POST['Contact'], "text"), GetSQLValueString($_POST['AssessAgree'], "text"), GetSQLValueString($_POST['LegalStatus'], "text"), GetSQLValueString($_POST['SentLength'], "text"), GetSQLValueString($_POST['Offence1'], "text"), GetSQLValueString($_POST['Drug'], "text"), GetSQLValueString($_POST['CurrentTreatment'], "text"), GetSQLValueString($_POST['Treatment'], "text"), GetSQLValueString($_POST['Medication'], "text"), GetSQLValueString($_POST['Prescriber'], "text"), GetSQLValueString($_POST['PrescriberAdd1'], "text"), GetSQLValueString($_POST['PrescriberAdd2'], "text"), GetSQLValueString($_POST['PrescriberPCode'], "text"), GetSQLValueString($_POST['PrescriberTel'], "text"), GetSQLValueString($_POST['PrescriberFax'], "text"), GetSQLValueString($_POST['ContactDetails'], "text"), GetSQLValueString($_POST['LegalStatusOther'], "text"), GetSQLValueString($_POST['Offence1OtherDetails'], "text"), GetSQLValueString($_POST['OtherDrug'], "text"), GetSQLValueString($_POST['DIRRef'], "text"), GetSQLValueString($_POST['WorkersTel'], "text"), GetSQLValueString($_POST['DateToCCFlip'], "date"), GetSQLValueString($_POST['WorkersName'], "text"), GetSQLValueString($_POST['WorkersLocation'], "text"), GetSQLValueString($_POST['Offence2'], "text"), GetSQLValueString($_POST['Offence2OtherDetails'], "text"), GetSQLValueString($_POST['IntOtherDetails'], "text"), GetSQLValueString($_POST['YesReason'], "text"), GetSQLValueString($_POST['NoReason'], "text"), GetSQLValueString($_POST['AgreeYNDetails'], "text"), GetSQLValueString($_POST['RefMadeBy'], "text"), GetSQLValueString($_POST['SPOCRecDtFlip'], "date"), GetSQLValueString($_POST['CurLoc'], "text"), GetSQLValueString($_POST['ReleaseDtFlip'], "date"), GetSQLValueString($_POST['DIRStatus'], "int"), GetSQLValueString($_POST['XFer'], "int"), GetSQLValueString($_POST['OtherArea'], "text"), GetSQLValueString($_POST['ExitReason'], "int"), GetSQLValueString($_POST['EXCDateFlip'], "date"), GetSQLValueString($_POST['AssCompDtFlip'], "date"), GetSQLValueString($_POST['FIAccepted'], "int"), GetSQLValueString($_POST['FIRefusalReason'], "int"), GetSQLValueString($_POST['FIRefuseOther'], "text"), GetSQLValueString($_POST['CPDone'], "int"), GetSQLValueString($_POST['CPCompDtFlip'], "date"), GetSQLValueString($_POST['CDRPArea'], "int"), GetSQLValueString($_POST['OtherUsedDrugs'], "text"), GetSQLValueString($_POST['PPO'], "int"), GetSQLValueString($_POST['HarmMin'], "int"), GetSQLValueString($_POST['BasicSkills'], "int"), GetSQLValueString($_POST['HousingNeeds'], "int"), GetSQLValueString($_POST['247SPOC'], "int"), GetSQLValueString($_POST['FTEmpTrain'], "int"), GetSQLValueString($_POST['EpisodeNo'], "int"), GetSQLValueString($_POST['PrisonRelDateFlip'], "text"), GetSQLValueString($_POST['FINeeded'], "int"), GetSQLValueString($_POST['IntoTreatDtFlip'], "text"), GetSQLValueString($_POST['MainAgency'], "int"), GetSQLValueString($_POST['OthAgency'], "text"), GetSQLValueString($_POST['BasicSkillsRef'], "int")); mysql_select_db($database_dip, $dip); $Result1 = mysql_query($insertSQL, $dip) or die(mysql_error()); //echo $insertSQL; } I can't see anything wrong with it - I'm beginning to think the problem is more network related than a MySQL / PHP issue...... |
|
#4
|
|||
|
|||
|
That is some huge query mate...I'd do the below... I assume you have a decent form setup that sends the values...
PHP Code:
table = is of course the table you are insterting stuff to columns1 ,2 ,3 = the columns in the table $value1, 2, 3 = is the variable you set by $_POST['whatever'] You can of course insert stuff via the query without $value1, 2, 3... the it looks something like this: PHP Code:
But personally I like to have the option of formatting stuff before inserting stuff into the database so I use $value1 = {$_POST['formFieldName1']}...might need to strip and format the text before inserting it.. The above doesn't use variables to run the query..it just stuffs the database directly. You can, as you already have, use $insertSQL etc and then run the query by mysql_query.. but I see no reason to complicate it. |
|
#5
|
|||
|
|||
|
Quote:
Hang on, Citrix doesn't send any data at all... Citrix only sends "images" of what is happening. Unless the website and database is located/runned on the same server you won't get it to work..ever..I think... hmm.... we use Citrix at the office here... but everything is inside the same network.. hmm... I might have jumped the gun here in my answer but I'll leave it standing anyways as it might get you a little further down the road to success. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > MySQL Insert Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|