Jump to content
xisto Community
Sign in to follow this  
leiaah

2 Mysql Operations Cause Delay?

Recommended Posts

I'm doing an Inventory system using PHP and MySQL. It's almost done now but I've been having a problem with this particular code. This is a function that does two things. It updates a table with edited values and then inserts values to another table. It's working fine except that the status bar of my browser indicates that the page (with this function) is still loading when in fact the function has been terminated and it did its job already (I've checked the dbase) and there's no command after calling the function. Could the delay be because I have two mysql operations here? Or is something I missed in the code? I hope this post is understood. :rolleyes: Thanks.

function edit(){ $id = $_GET['id'];
$PID = $_GET['pid'];
$orig = $_GET['orig'];
$beg_qty = $_GET['beg_qty'];
$supplier = $_GET['supplier'];
$pur_price =$_GET['pur_price'];
$sel_price = $_GET['sel_price'];
$date_pur = $_GET['date_pur'];
$exp = $_GET['exp'];

@ $db = mysql_pconnect('localhost', 'xx', 'xx');
mysql_select_db('avh');

if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

$query = "update Item_In_Stock set Date_Purchased='".$date_pur."', Expiration='".$exp."', Beginning_qty=".$beg_qty.",Supplier_ID='".$supplier."' where purchase_ID='".$PID."'";
$result = mysql_query($query) or die(mysql_error());
if($orig!=$sel_price){
$qry = "insert into Item_Price(Purchase_ID,Price,Price_date) values (".$PID.", ".$sel_price.",'".$date."')";
$res = mysql_query($query) or die(mysql_error());
}
}


Share this post


Link to post
Share on other sites

Using mysql operations twice shouldn't do anything to the page loading. It could be the browser not disconnecting from the server? try to use "exit;" at the end of your code. If it doesn't do anything then don't worry about it. At least your code is working.

Just for an example

<?php // All of your code exit; // Halts your code so it doesn't keep doing stuff.?>

Edited by Yarrgh (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.