Jump to content


sometimes works and sometimes not

  • Please log in to reply
2 replies to this topic

#1 NorthWind

  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 June 2006 - 08:18 AM

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>";

#2 joquius

  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 12 June 2006 - 01:16 PM

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?

#3 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 12 June 2006 - 02:22 PM

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);

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users