Jump to content

Archived

This topic is now archived and is closed to further replies.

predator12341

records multiplying in mysql table but the script should not be running

Recommended Posts

Hi people. right i am getting a very very wierd things happening i have this code

$SQL3="INSERT INTO UpdateInfo (FaultID, UserWhoUpdated, TimeUpdated, DateUpdated) VALUES('$ID', '$LoggedInUser', '$TimeNow ', '$TodayDate')";
$Result3=mysql_query($SQL3);

This code is to insert a record into UpdateInfo when a record is updated. what happens is i update it and it goes in fine but when i look at the table 18 seconds later another record appears in there even though it should not and i am the only person who has access to the table and program. the fault id for the new record added is also wierd to as it is something like 1872 and i only have 14 records i can edit. so please any help would be great the rest of the code is below

[code]
<?
        $CompName = $_POST['CompanyName'];
        $CompAddress = $_POST['CompanyAddress'];
        $CompPhone = $_POST['CompanyPhone'];
        $CompContact = $_POST['CompanyContact'];
        $CompEmail = $_POST['CompanyEmail'];
        $SystemMakeModel = $_POST['SystemMakeModel'];
        $FaultDec = $_POST['FaultDec'];
        $MaintenanceType = $_POST['MaintenanceType'];
        $FaultStatus = $_POST['FaultStatus'];
        $FaultImportance = $_POST['FaultImportance'];
        $FaultComplete = $_POST['FaultCompleted'];
        $FaultFix = $_POST['FaultFix'];
        $TodayDate = date("d-m-Y H:i:s");
        $TimeNow = date("H:i:s");
        $Revisit=$_POST['Revisit'];
if($FaultComplete == "1")
{
    $DateComplete = date("Y-m-d");
}else
{
    $DateComplete = NULL;
}
    $ID = $_GET['ID'];
    $LoggedInUser = $_SESSION['User'];
        include"db_config.php";
    $Connect = mysql_connect($DBHost, $DBUser,$DBPass) or die("MySQL Connection Failed!");
    $DBConnect = mysql_select_db($DBDatabase,$Connect) or die("MySQL Database Connection Failed!");

$SQL3="INSERT INTO UpdateInfo (FaultID, UserWhoUpdated, TimeUpdated, DateUpdated) VALUES('$ID', '$LoggedInUser', '$TimeNow ', '$TodayDate')";
    $Result3=mysql_query($SQL3);
    
    $SQL="UPDATE FaultLog SET CompanyName = '$CompName', CompanyAddress = '$CompAddress', CompanyPhoneNo = '$CompPhone', CompanyContact = '$CompContact', CompanyEmail = '$CompEmail', SystemMakeModel = '$SystemMakeModel', FaultDescription = '$FaultDec', MaintenanceType = '$MaintenanceType', FaultStatus = '$FaultStatus', FaultImportance = '$FaultImportance', DateFinished = '$DateComplete', FaultCompleted = '$FaultComplete', FaultFix = '$FaultFix', LastUpdated = '$TodayDate' WHERE ID='$ID'"; //this is the SQL statement that updates the record
    $result=mysql_query($SQL) or die("Update of the record could not be done UD1 Failed.");//this is the line that carrys out the update.
    
$SQL2 ="SELECT * FROM FaultLog WHERE ID='$ID'";
$Result2 = mysql_query($SQL2);
while($row = mysql_fetch_assoc($Result2))
{
    $VisitBooked=$row["VisitBookedFor"];
}

if($FaultComplete != "1" and $FaultStatus == "3")
{
if($VisitBooked == NULL or $VisitBooked == "" )
{
echo "<script Language=Javascript> alert( 'You are now being re-directed to book the fault into the calendar. The fault you need to book the visit for is fault ID ".$ID."') </script> ";
echo "<script type='text/javascript'>location.href='../Calendar.php?ID=".$ID."'</script>";
}
    else
{
echo "<img class='company' src='../Images/Main/CompanyLogo.gif'>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<div align='center'>";
echo "<b class='subheader'>You have successfully updated fault ".$ID.". You will now be transfered to the main page in 5 seconds.</b>";
echo "<meta http-equiv='refresh' content='5;url=../body.php'>"; //redirects you to main page after 5 seconds
echo "</div>";
}
//transfer to the calendar with a message of please book in track number ## to a date that an engineer will visit the site.
}
else
{
echo "<img class='company' src='../Images/Main/CompanyLogo.gif'>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<div align='center'>";
echo "<b class='subheader'>You have successfully updated fault ".$ID.". You will now be transfered to the main page in 5 seconds.</b>";
echo "<meta http-equiv='refresh' content='5;url=../body.php'>"; //redirects you to main page after 5 seconds
echo "</div>";
//transfer to main page after 5 seconds
}
mysql_close($Connect);
?>
[/code]

Share this post


Link to post
Share on other sites
Could you give me a mysql export thing of your table structure and content (if its not secret) and i'll run a few tests on my server for you and see if i can come up with anything.

Would like to help, but i dont have time to try and create the table from scratch.

Share this post


Link to post
Share on other sites
i am also getting another problem where i update a record (using the same script above) and after like 1 minute the first few fields in the table for that record get wiped and nothing is in them i just dont no what is going on and it has just happened since that insert to the UpdateInfo was added (well i believe it was anyway)
regards
Pred

Share this post


Link to post
Share on other sites
one quick thing... the FaultID is $_GET[ID].... so the faultID should be set as whatever ID is in the URL.

Share this post


Link to post
Share on other sites
yea sure wise give us a sec and i will

hmm crap how do i get the export in mysql using phpadmin i am trying it but it is comming out wrong (and yea i no it comes from the url dude and it works fine it is just that random records are added and the script should not even be running it is really wierd

Share this post


Link to post
Share on other sites
depends on the version of phpmyadmin. I've got completely different one at work to the one i have at home lol

Share this post


Link to post
Share on other sites
hmm crap could you possibly just make it cos i cant find it sorry man there is 4 fields

FaultID varchar(255)
UserWhoUpdated varchar(40)
TimeUpdated varchar(8)
DateUpdated varchar(12)

Share this post


Link to post
Share on other sites
No problem.

Could you give me the code for the html form that submits the data across to this page please.

Share this post


Link to post
Share on other sites
yea sure here is the code

[code]
<?
session_start();
if(@$_SESSION['Auth'] != "Yes")
        {    
            echo "<script type='text/javascript'>location.href='index.htm'</script>";
        }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
b.header
{
    font-size:20px;
    font-family:Georgia, "Times New Roman", Times, serif;
}
b.subheader
{
    color:#666666;
    font:Geneva, Arial, Helvetica, sans-serif;
    font-size:14px;
}
img.company
{
    float:right;
    z-index: -1;
}
</style>
</head>

<body>
<img class="company" src="Images/Main/CompanyLogo.gif">
<br />
<br />
<br />
<?
$ID=$_GET['ID']; //gets the value sent through the web page browser (the tracking id that was searched on the previous page)

    include "Scripts/db_config.php";
$Connect = mysql_connect($DBHost, $DBUser,$DBPass) or die("MySQL Connection Failed!");
$DBConnect = mysql_select_db($DBDatabase,$Connect) or die("MySQL Database Connection Failed!");

$SQL="SELECT * FROM FaultLog WHERE ID='$ID'";
$Result=mysql_query($SQL);

while($row = mysql_fetch_assoc($Result))
{//the below sets the variables to each field of a particular record that the user searched.
    $CompName = $row["CompanyName"];
    $CompAddress = $row["CompanyAddress"];
    $CompPhone = $row["CompanyPhoneNo"];
    $CompContact = $row["CompanyContact"];
    $CompEmail = $row["CompanyEmail"];
    $SystemMakeModel = $row["SystemMakeModel"];
    $FaultDec = $row["FaultDescription"];
    $MaintenanceType = $row["MaintenanceType"];
    $FaultStatus = $row["FaultStatus"];
    $FaultImportance = $row["FaultImportance"];
    $DateBooked = $row["DateBooked"];
    $FaultCompleted = $row["FaultCompleted"];
    $FaultEnteredBy = $row["FaultEnteredBy"];
    $FaultFix = $row["FaultFix"];
    $VisitBookedFor = $row["VisitBookedFor"];
    $LastUpdated = $row["LastUpdated"];
    $Revisit = $row["RevisitRequired"];
}
?>

<div align="center">
<b class="header">Edit Fault</b>
<br />
<br />
<form method="post" action= <? echo"'Scripts/UpdateFault.php'";?> >
<table width="800" border="0">
    <tr>
        <td width="300" valign="top">
            <b class="subheader">Customer Information</b>
                <br />
            Company Name:<br /> <input type="text" name="CompanyName" value="<? echo $CompName;?>"/>
                <br />
            Company Address:<br /> <textarea name="CompanyAddress"><? echo $CompAddress; ?></textarea>
            <br />
            Company Phone Number:<br /><input type="text" name="CompanyPhone" value="<? echo $CompPhone;?>" />
                <br />
            Company Contact:<br /><input type="text" name="CompanyContact" value="<? echo $CompContact;?>" />
                <br />
            Company Email:<br /><input type="text" name="CompanyEmail" value="<? echo $CompEmail;?>"/>        </td>
        <td width="300" valign="top">
            <b class="subheader">System and Fault Information</b>
                <br />
            System Make and Model:<br /><input type="text" name="SystemMakeModel" value="<? echo $SystemMakeModel;?>"/>
                <br />
            Fault Description:<br /><textarea name="FaultDec"><? echo $FaultDec;?></textarea>
                <br />
            Maintenance Type:<br  />  <select name="MaintenanceType">
              <option value="1"<?php if($MaintenanceType=="1") echo "selected";?>>None</option>
              <option value="2"<?php if($MaintenanceType=="2") echo "selected";?>>Bronze</option>
              <option value="3"<?php if($MaintenanceType=="3") echo "selected";?>>Silver</option>
              <option value="4"<?php if($MaintenanceType=="4") echo "selected";?>>Gold</option>                        
            </select>
                <br />
            Fault Status:<br />
            <select name="FaultStatus">
              <option value="1"<?php if($FaultStatus=="1") echo "selected";?>>Tech database lookup</option>
              <option value="2"<?php if($FaultStatus=="2") echo "selected";?>>Engineer investigates</option>
              <option value="3"<?php if($FaultStatus=="3") echo "selected";?>>Engineer booked for site visit</option>
              <option value="4"<?php if($FaultStatus=="4") echo "selected";?>>Escilated to manufacturer</option>
            </select>
            <br />
            Fault Importance:<br  />  <select name="FaultImportance">
              <option value="1"<?php if($FaultImportance=="1") echo "selected";?>>Low</option>
              <option value="2"<?php if($FaultImportance=="2") echo "selected";?>>Normal</option>
              <option value="3"<?php if($FaultImportance=="3") echo "selected";?>>High</option>
              <option value="4"<?php if($FaultImportance=="4") echo "selected";?>>Urgent</option>                        
            </select>
        </td>
        <td width="300" valign="top">
                <b class="subheader">Fault Information </b>
            <br />

                Fault Fix Information:<br />
                <textarea name="FaultFix" title="Place details of how the fault is progressing in here. For example'Called BT and they are carrying out a line test'"><? echo $FaultFix;?></textarea>
            <br />    
            Revisit Required:<br />
            <select name="Revisit">
              <option value="0"<?php if($Revisit=="0") echo "selected";?>>No</option>
              <option value="1"<?php if($Revisit=="1") echo "selected";?>>Yes</option>    
            </select>
            <br />
            Fault Completed:<br  />  <select name="FaultCompleted">
              <option value="0"<?php if($FaultCompleted=="0") echo "selected";?>>No</option>
              <option value="1"<?php if($FaultCompleted=="1") echo "selected";?>>Yes</option>                    
            </select>
            <br />
            <br />

            <? if($VisitBookedFor == "")
            {
                echo "This fault has not been booked for an engineer to visit site";
            }
            else
            {
                echo "This fault has been booked for an engineer to visit the site on the: ".$VisitBookedFor .". <br> <br> To View the job sheet for this fault click <a href='JobSheet.php?ID=".$ID."'>here</a>";
            }
             ?>
            
            
        </td>
    </tr>
    <tr>
    <td colspan="3" align="center">
    <input type="submit" name="SaveFault" value="Update Fault" />
    </td>
    </tr>
</table>
</form>
<br />
<b class="subheader">The person who booked this fault was:</b> <? echo $FaultEnteredBy; ?>
&nbsp;&nbsp;
&nbsp;&nbsp;
<b class="subheader">The date this fault was booked on was the:</b> <? echo date("d-m-Y",strtotime($DateBooked));  ?>
<br /><br />
<b class="subheader">The fault ticket tracking number for this fault is:</b> <? echo $ID; ?>
<? $_SESSION['ID']=$ID; ?>
&nbsp;&nbsp;
&nbsp;&nbsp;
<?
    if($LastUpdated != "" or $LastUpdated !=NULL)
        {
            echo "<b class='subheader'>This fault was last updated on the:</b> " . $LastUpdated;
            echo "<br>";
            echo "<br>";
        }
?>
</div>
</body>
</html>

[/code]


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]i am also getting another problem where i update a record (using the same script above) and after like 1 minute the first few fields in the table for that record get wiped and nothing is in them i just dont no what is going on and it has just happened since that insert to the UpdateInfo was added (well i believe it was anyway)
regards
Pred[/quote]

hmm the above problem appears to have been sorted out by taking off the not null property i gave to the field so i am hoping it has corrected the issue for that at least.

Share this post


Link to post
Share on other sites

wISE THE OTHER ISSUE IS NOT FIXED THOUGH I JUST DONT NO WHAT IS GOING ON THERE SO IF YOU CAN SEE IF YOU CAN WORK THAT OUT IT WOULD BE A GREAT HELP.

AND BTW THANKS FOR THE HELP YOU HAVE GIVEN SO FAR IT IS GOOD THERE ARE PPL LIKE YOU WHO RESPOND FAST TO POST'S

(sorry bout caps)

Share this post


Link to post
Share on other sites
How many "Faults" are there in the faults table?

In phpmyadmin if you select that table, and then select the "operations" link at the top, it will give you a page which tells you what the next auto-increment value is. Is this a number close to the seemingly random number you got from the mysterious entry into the other table?

Share this post


Link to post
Share on other sites
na it is no where near it the next number should be like 15 or 16 (i just found out i got MySQLMan: View Table FaultLog
not php admin sorry )


righte dude i think i have fixed it it seems to be workin fine so i hope it is sorted thanks for the help man i really apprechiate it

Share this post


Link to post
Share on other sites

×

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.