Jump to content

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


predator12341

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]
Link to comment
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.
Link to comment
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
Link to comment
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
Link to comment
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.
Link to comment
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)
Link to comment
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?
Link to comment
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
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.