mySQL + PHP database update problem
Moderator: General Moderators
mySQL + PHP database update problem
Hi,
I'm inserting data into a mySQL db using normal mysq_query() and mysql_fetch_assoc() funcitons in php. Then when I try and view the updated data, it shows the old data and not the updated data. But if I connect to phpmyAdmin, is shows the latest data.
Not sure if this has something to do with the connection persistance or whether I must mysql_close() every query everytime... I've tried it but had no luck yet.
Cheers
I'm inserting data into a mySQL db using normal mysq_query() and mysql_fetch_assoc() funcitons in php. Then when I try and view the updated data, it shows the old data and not the updated data. But if I connect to phpmyAdmin, is shows the latest data.
Not sure if this has something to do with the connection persistance or whether I must mysql_close() every query everytime... I've tried it but had no luck yet.
Cheers
Here is the code...
The claims.php page is basically an HTML page that just queries the db for that data again and displays it. Not updated as I said, but in phpmyadmin it is correct...
Code: Select all
<?php
//Connection statement
require_once('../Connections/ThuraPHP.php');
//Aditional Functions
require_once('../includes/functions.inc.php');
session_start();
// Define post fields into simple variables
$clStatus = $_POST['clStatus'];
$clCapture = $_POST['clCapture'];
$clFileNr = $_POST['clFileNr'];
$clClaimType = $_POST['clClaimType'];
$clPolicyNR = $_POST['clPolicyNR'];
$clInsured = $_POST['clInsured'];
$clInsuredCell = $_POST['clInsuredCell'];
$clInsuredContact = $_POST['clInsuredContact'];
$clInsuredTelH = $_POST['clInsuredTelH'];
$clInsuredTelW = $_POST['clInsuredTelW'];
$clDateRep = $_POST['clDateRep'];
$clDateOfLoss = $_POST['clDateOfLoss'];
$clSapd = $_POST['clSapd'];
$clSapdRef = $_POST['clSapdRef'];
$clDescription = $_POST['clDescription'];
$clClaimAmount = $_POST['clClaimAmount'];
$clInsComp = $_POST['clInsComp'];
$clInsClaimNr = $_POST['clInsClaimNr'];
$clBSGContact = $_POST['clBSGContact'];
$clBSGTel = $_POST['clBSGTel'];
$clBSGFax = $_POST['clBSGFax'];
$clAssesContact = $_POST['clAssesContact'];
$clAssesTel = $_POST['clAssesTel'];
$clAssesFax = $_POST['clAssesFax'];
$clBroker = $_POST['clBroker'];
$clBrokerTel = $_POST['clBrokerTel'];
$clBrokerFax = $_POST['clBrokerFax'];
$clRecovery = $_POST['clRecovery'];
$clEVG = $_POST['clEVG'];
$clDateAdmin = $_POST['clDateAdmin'];
$clAction = $_POST['clAction'];
$clExcess = $_POST['clExcess'];
$clSetAmount = $_POST['clSetAmount'];
$clBeneficiary = $_POST['clBeneficiary'];
$clDateRes = $_POST['clDateRes'];
$clNotes = $_POST['clNotes'];
$clClientSurname = $_POST['clClientSurname'];
$clClientID = $_POST['clClientID'];
$clClientInitials = $_POST['clClientInitials'];
$clThuraClaimNr = $_POST['clThuraClaimNr'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$clStatus = mysql_escape_string($clStatus);
$clCapture = mysql_escape_string($clCapture);
$clFileNr = mysql_escape_string($clFileNr);
$clClaimType = mysql_escape_string($clClaimType);
$clPolicyNR = mysql_escape_string($clPolicyNR);
$clInsured = mysql_escape_string($clInsured);
$clInsuredCell = mysql_escape_string($clInsuredCell);
$clInsuredContact = mysql_escape_string($clInsuredContact);
$clInsuredTelH = mysql_escape_string($clInsuredTelH);
$clInsuredTelW = mysql_escape_string($clInsuredTelW);
$clDateRep = mysql_escape_string($clDateRep);
$clDateOfLoss = mysql_escape_string($clDateOfLoss);
$clSapd = mysql_escape_string($clSapd);
$clSapdRef = mysql_escape_string($clSapdRef);
$clDescription = mysql_escape_string($clDescription);
$clClaimAmount = mysql_escape_string($clClaimAmount);
$clInsComp = mysql_escape_string($clInsComp);
$clInsClaimNr = mysql_escape_string($clInsClaimNr);
$clBSGContact = mysql_escape_string($clBSGContact);
$clBSGTel = mysql_escape_string($clBSGTel);
$clBSGFax = mysql_escape_string($clBSGFax);
$clAssesContact = mysql_escape_string($clAssesContact);
$clAssesTel = mysql_escape_string($clAssesTel);
$clAssesFax = mysql_escape_string($clAssesFax);
$clBroker = mysql_escape_string($clBroker);
$clBrokerTel = mysql_escape_string($clBrokerTel);
$clBrokerFax = mysql_escape_string($clBrokerFax);
$clRecovery = mysql_escape_string($clRecovery);
$clEVG = mysql_escape_string($clEVG);
$clDateAdmin = mysql_escape_string($clDateAdmin);
$clAction = mysql_escape_string($clAction);
$clExcess = mysql_escape_string($clExcess);
$clSetAmount = mysql_escape_string($clSetAmount);
$clBeneficiary = mysql_escape_string($clBeneficiary);
$clDateRes = mysql_escape_string($clDateRes);
$clNotes = mysql_escape_string($clNotes);
$clClientSurname = mysql_escape_string($clClientSurname);
$clClientID = mysql_escape_string($clClientID);
$clClientInitials = mysql_escape_string($clClientInitials);
$clThuraClaimNr = mysql_escape_string($clThuraClaimNr);
// Enter info into the Database.
$sql_insert = "UPDATE claims SET clStatus= '$clStatus' ,clCapture = '$clCapture', clFileNr = '$clFileNr', clClaimType= '$clClaimType',
clPolicyNR= '$clPolicyNR', clInsured = '$clInsured', clInsuredCell= '$clInsuredCell', clInsuredContact= '$clInsuredContact',
clInsuredTelH= '$clInsuredTelH', clInsuredTelW= '$clInsuredTelW', clDateRep = '$clDateRep', clDateOfLoss= '$clDateOfLoss',
clSapd = '$clSapd', clSapdRef= '$clSapdRef', clDescription= '$clDescription', clClaimAmount= '$clClaimAmount',
clInsComp = '$clInsComp', clInsClaimNr= '$clInsClaimNr', clBSGContact = '$clBSGContact', clBSGTel = '$clBSGTel',
clBSGFax = '$clBSGFax', clAssesContact= '$clAssesContact', clAssesTel= '$clAssesTel', clAssesFax= '$clAssesFax',
clBroker= '$clBroker', clBrokerTel = '$clBrokerTel', clBrokerFax= '$clBrokerFax', clRecovery= '$clRecovery',
clEVG = '$clEVG', clDateAdmin= '$clDateAdmin', clAction = '$clAction', clExcess = '$clExcess', clSetAmount= '$clSetAmount',
clBeneficiary= '$clBeneficiary', clDateRes= '$clDateRes', clNotes = '$clNotes', clClientSurname = '$clClientSurname',
clClientID = '$clClientID', clClientInitials = '$clClientInitials' WHERE clThuraClaimNr = '$clThuraClaimNr'";
$sql = mysql_query($sql_insert) or die(mysql_error());
//echo $sql_insert;
//exit;
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
include '../ClaimsAmmendClaim.php';
} else {
echo 'Account created successfully.';
header("Location: ../Claims.php");
}
?>I am not sure about your problem but these 3 lines will cut about 80 lines out of your code..
Code: Select all
<?php
foreach($_POST as $var=>$val){
$$var = mysql_escape_string($val);
}
?>Not sure how that is working for you unless you are using output buffering, by default it will throw an error (headers already sent).echo 'Account created successfully.';
header("Location: ../Claims.php");
If it's updating in the database ok (you see it updated via phpmyadmin) but not on your page that queries the database, then that can only be down to caching or some strange logic (ie it's not fetching the info you think it is).
This is what the code looks like at the top of the page displaying the data. It is before the html tags...
Code: Select all
<?php
<?php session_start();
header("Cache-control: private");
//echo print_r($_SESSION);
//echo print_r($_POST);
$get_id = $_POST['IDNumber'];
$get_policy_nr = $_POST['PolicyNr'];
?>
<?php
//Connection statement
require_once('Connections/ThuraPHP.php');
//Aditional Functions
require_once('includes/functions.inc.php');
$form_action = "Admin/register_create_claim.php";
// begin Recordset
$query_ClientSearch = sprintf("SELECT * FROM Thura.client where IDNumber = '%s'",$get_id);
$ClientSearch = mysql_query($query_ClientSearch) or die(mysql_error());
$totalRows_ClientSearch = mysql_num_rows($ClientSearch);
$data = mysql_fetch_assoc($ClientSearch);
// end Recordset
// begin Recordset
$query_ClaimNr = sprintf("SELECT clThuraClaimNr FROM Thura.claims ORDER BY clThuraClaimNr DESC LIMIT 1");
$ClaimNr = mysql_query($query_ClaimNr) or die(mysql_error());
$totalRows_ClaimNr = mysql_num_rows($ClaimNr);
$claim_nr = mysql_fetch_assoc($ClaimNr);
// end Recordset
// begin Recordset
// Nie polis spesifiek....
//$query_PolicySearch = sprintf("SELECT * FROM Thura.policies where ClientID = '%s'",$get_id);
// Polis spesifiek .....
$query_PolicySearch = sprintf("SELECT * FROM Thura.policies where PolicyNr = '%s'",$get_policy_nr);
$PolicySearch = mysql_query($query_PolicySearch) or die(mysql_error());
$totalRows_PolicySearch = mysql_num_rows($PolicySearch);
$policy_data = mysql_fetch_assoc($PolicySearch);
// end Recordset
?>
<?php
$query_status = "SELECT status FROM thura_status";
$query_consultant = "SELECT cons_name FROM thura_consultant ORDER BY cons_name ASC";
$query_inscomp = "SELECT comp_name FROM thura_inscomp ORDER BY comp_name ASC";
$query_broker = "SELECT broker_name FROM thura_broker ORDER BY broker_name ASC";
$query_claim_type = "SELECT ClaimType FROM thura_claim_type ORDER BY ClaimType ASC";
$result_status = mysql_query($query_status);
$result_consultant = mysql_query($query_consultant);
$result_inscomp = mysql_query($query_inscomp);
$result_broker = mysql_query($query_broker);
$result_claim_type = mysql_query($query_claim_type);
?>
?>