Not updating database - sudden issue?!


#1

Hi, I am hoping for some help, my website has been running for years with a php code that goes to my sql database and updates the quantities of stock of our products, this suddenly stopped working this week.
It is connecting to the database and is running through to the shopping cart with the correct values, it is just not writing through to the database.
Unfortunately someone built this code for me and i just added it to my html pages, so I have limited knowledge on how to fix it.
I can see that the file that says update stock and i can see in that file the bit thats supposed to update the tables but have no idea where it could be not working?
Any help on this would be great, i think this must be the code where the problem is but who knows!
Thank you
Sam

<? // Get Value from Mals Cart

$mystring = $_REQUEST[‘cart’]; //echo $mystring; $username = $_REQUEST[‘username’]; $id = $_REQUEST[‘id’]; $ip = $_REQUEST[‘ip’]; $order_date = $_REQUEST[‘order_date’]; $method = $_REQUEST[‘method’]; $cart = $_REQUEST[‘cart’]; $discount = $_REQUEST[‘discount’]; $subtotal = $_REQUEST[‘subtotal’]; $shipping = $_REQUEST[‘shipping’]; $tax = $_REQUEST[‘tax’]; $total = $_REQUEST[‘total’]; $shipping_zone = $_REQUEST[‘shipping_zone’]; $inv_name = $_REQUEST[‘inv_name’]; $inv_company = $_REQUEST[‘inv_company’]; $inv_addr1 = $_REQUEST[‘inv_addr1’]; $inv_addr2 = $_REQUEST[‘inv_addr2’]; $inv_state = $_REQUEST[‘inv_state’]; $inv_zip = $_REQUEST[‘inv_zip’]; $inv_country = $_REQUEST[‘inv_country’]; $del_name = $_REQUEST[‘del_name’]; $del_addr1 = $_REQUEST[‘del_addr1’]; $del_addr2 = $_REQUEST[‘del_addr2’]; $del_state = $_REQUEST[‘del_state’]; $del_zip = $_REQUEST[‘del_zip’]; $del_country = $_REQUEST[‘del_country’]; $tel = $_REQUEST[‘tel’]; $fax = $_REQUEST[‘fax’]; $email = $_REQUEST[‘email’]; $message = $_REQUEST[‘message’];

// Connect to Inventory Database
include ($_SERVER[‘DOCUMENT_ROOT’].’/inventory/include/dbconnect.php’); // Split up Mals Value into Arrays $arrayProducts = explode(’~’,$mystring);

// For Each Product, strip out Values and Update Database Stock foreach
($arrayProducts as $v) { $arrayItem = explode(’ : ',$v); $product = $arrayItem[0]; $qty = $arrayItem[1]; $price = $arrayItem[2]; $units = $arrayItem[3]; $code = $arrayItem[4];

// Get Current Qty on Hand
$query = “SELECT * FROM inventory WHERE code = '”.$code."’"; $result = mysql_query($query); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $qtyCurrent = $row[‘qty’]; } // Create a new Qty on Hand $qtyNew = $qtyCurrent - $qty;

// Store New Qty on Hand to Database
$sql = “UPDATE inventory SET qty=$qtyNew WHERE code=’”.$code."’"; $result = mysql_query($sql); } ?>


#2

The code is dangerous and obsolete and has been completely removed from current php versions. It will need to be re-written to current coding standards. Most likely your host upgraded the Php on your server. There has been well over 12 years advance notice that mysql_* code is deprecated and would eventually be removed. That time has arrived.


#3

Thank you so much for responding, that does make perfect sense as I changed to a VPS last week so that has probably updated the code permissions.
I will look into re-writing all the code that’s relevant then, I have been working on the “it’s not broken so don’t touch it” method as I didn’t write that bit and the chap who did is no longer around!
Thank you again
Sam


#4

You will want to use PDO with Prepared Statements. Here is a tutorial to get you going.
https://phpdelusions.net/pdo


#5

Thank you for that link, will crack on :):grinning: