Jump to content

Writing Data into a MySQL database


riavanheerden

Recommended Posts

Hi

 

I am still new to PHP and I got stuck when I wanted to write my values in to my database - i would really appreciate help.

 

I need to update three database tables - jos_vm_orders, jos_vm_order_item, jos_vm_order_history

 

this is the code that i am using ...

 

    $m_4 = $_POST["m_4"];

    $m_5 = $_POST["m_5"];

    $m_6 = $_POST["m_6"];

   

    $m_4Text = "user_id: ";

    $m_5Text = "order_number: ";

    $m_6Text = "order_id: ";

   

$db = new ps_DB;

$timestamp = time() + ($mosConfig_offset*60*60);

$mysqlDatetime = date("Y-m-d G:i:s",$timestamp);

 

$q = "UPDATE #__{vm}_orders SET";

$q .= " order_status='C' ";

$q .= ", mdate='" . $timestamp . "' ";

$q .= "WHERE order_id='$m_6'";

$db->query($q);

 

// Update the Order History.

$q = "INSERT INTO #__{vm}_order_history ";

$q .= "(order_id,order_status_code,date_added,customer_notified,comments) VALUES (";

$q .= "'$m_6', 'C', '$mysqlDatetime', '0', '".$db->getEscaped( stripslashes($d['order_comment']) )."')";

$db->query($q);

 

// Update the Order Items' status

$q = "SELECT order_item_id FROM #__{vm}_order_item WHERE order_id=".$d['order_id'];

$db->query($q);

$dbu = new ps_DB;

while ($db->next_record()) {

$item_id = $db->f("order_item_id");

$q  = "UPDATE #__{vm}_order_item SET order_status='C'"

. "\n, mdate='" . $timestamp . "' "

. "\n WHERE order_item_id=".$item_id;

$dbu->query( $q );

}

 

What am i doing wrong

 

Thank you for your help

 

Kind Regards

Ria

Link to comment
https://forums.phpfreaks.com/topic/98700-writing-data-into-a-mysql-database/
Share on other sites

what error are you getting? are you connecting properly to your database? i use this statement to connect to mine:

 

 

<?php
//Connect to mysql server
$link = mysql_connect("ip_address","username","password");
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("database_name");
if(!$db) {
	die("Unable to select database");
             }
?>

Archived

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

×
×
  • 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.