Jump to content


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


sometimes works and sometimes not

Recommended Posts

i have a problem with a code. the problem is very weird because this code actually works but sometimes it doesnt. I checked the code for hrs but could not find a problem with it.
The code basicly does some database updates on the recent data. updates a few fields...
The code actually says that it has updated but sometimes when you go check it from the database, it did not!
I'm using MS SQL 2000 on a windows 2003 server, installed 4.4.0.
I'm giving all these info because i started to think that its a database problem since the code sometimes work. Did anyone experienced this kind of problem, pls let me know. thanks


        echo "<table align='center' border='0' cellpadding='6' cellspacing='3'>";
        echo "<td height='406' valign='center' align='center'>";

        $itemCode = $_GET['itemCode'];
        $custID = $_GET['custID'];
        $jobID = $_GET['jobID'];
        $serial = $_GET['serial'];
        $eqid = $_GET['eqid'];
        //$myobno = $_GET["myob"];
        $custname = $_GET["custname"];
        $custref = $_GET["custref"];
        //$pdate = $_GET["purchaseDate"];
        echo $itemCode; echo "<br>";
        echo $jobID;echo "<br>";
        echo $serial;echo "<br>";
        echo $eqid;echo "<br>";
        echo $custname;echo "<br>";
        //$jobInvoiceStatus = $_GET['jobInvoiceStatus'];

        // Query database
        $query = "Update JobEquipment SET jobID='$jobID', jobInvoiceStatus='Not Yet Invoiced', custname='$custname', custreference='$custref', sold='1' where (itemCode = '$itemCode') and (serial = '$serial') and (equipID = '$eqid')";
        $result = mssql_query($query, $link);
        //$row = @mssql_fetch_array($result);

        //if there were no errors ($result  == true or has a value)
        if ($result)
            echo "<h3>Success ! \n";
            echo "<p>Item( $itemCode ) with serial: $serial has been added to the job.";
            echo "<p><a href='serials.php'>To Equipment/Serials Page</a> \n";
            echo "<p><a href='job.php?jobID=$jobID'>Back to Job</a> \n";

        //start of decrease quantity

        if ($jobID!="")
        $querysee = "SELECT * FROM Inventory where (itemCode = '$itemCode')";
            $resultsee = mssql_query($querysee, $link);
            //$rowsee = @mssql_fetch_array($resultsee);
            while ($rowsee = @mssql_fetch_array($resultsee))
                    //    if ($itemCode==$row["itemCode"])
                    //    {    
                            $queryminus = "UPDATE Inventory SET quantity='$quantity' where itemCode='$itemCode'";
                            $resultminus = mssql_query($queryminus, $link);
            // end of decrease quantity
            echo "<h2>Database encountered errors with what was input<br>";
        echo "</td>";
        echo "</table>";


Share this post

Link to post
Share on other sites
If it's working on and of maybe check out $link and make sure it isn't getting mixed up with a different connection if you have more db's on the same server.

Other than that is it completely random when it doesn't work?

Share this post

Link to post
Share on other sites
I don't know what your problem is, but you shouldn't update your database with your variables like that. first off, you should be using $_POST['blah'] instead of $_GET['blah'] and you should be passing your vars with method='post' in your form.

2nd, you should sanitize your variables before using them in queries, with something like this:

$blah = msyql_real_escape_string($_POST['blah']);

a simpler method if you have a lot of variables is to do like this:

foreach($_POST as $key => $var) {
   $$key = mysql_real_escape_string($var);

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.