Code4.3升級PHP5.3,資料庫像無法寫入

cookie888


Code4.3升級PHP5.3,資料庫好像無法寫入
登入會員如密碼錯他會判斷錯誤

但對的話無法顯示登入頁面
一值停在密碼對話框

我只是古代網頁設計硬改,┌不了解PHP,經過長久努力爬文查詢
好不容易把頁面錯誤都改出來

現在出現疑似無法寫入資料庫

還有這個Warning: Division by zero in 錯誤訊息,

我在這邊有爬文有爬到,但看不懂....

系統給的錯誤訊息列是紅字行

function calculate_credit($amount_order, $amount_cum_order) {
global $order;
$od_amount=0;
$table_cost = preg_split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);
for ($i = 0; $i < count($table_cost); $i+=2) {
if ($amount_cum_order >= $table_cost[$i]) {
$od_pc = $table_cost[$i+1];

$this->od_pc = $od_pc;
[b]
}
}

可否告知要如何修改(不好意思 因為真的不會)



請高手指導,感激不盡((跪~~


cookie888
第2個問題 我標的紅字不見了
無法編輯,更正在這邊


function calculate_credit($amount_order, $amount_cum_order) {
global $order;
$od_amount=0;
$table_cost = preg_split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);
for ($i = 0; $i < count($table_cost); $i+=2) {
if ($amount_cum_order >= $table_cost[$i]) {
$od_pc = $table_cost[$i+1];

$this->od_pc = $od_pc;
[color=Red]$od_pc = 100/$od_pc;[/color]
}
}
cookie888

第2個問題 我標的紅字不見了
無法編輯,更正在這邊

還有資料庫無法寫入(登入會員通通不work)


function calculate_credit($amount_order, $amount_cum_order) {
global $order;
$od_amount=0;
$table_cost = preg_split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);
for ($i = 0; $i < count($table_cost); $i+=2) {
if ($amount_cum_order >= $table_cost[$i]) {
$od_pc = $table_cost[$i+1];

$this->od_pc = $od_pc;
$od_pc = 100/$od_pc; <----系統給的錯誤行
}
}

$od_amount = $amount_order*$od_pc/100;

return $od_amount;
}
彩虹
善用「程式碼標籤」,將程式碼貼在裡面
function calculate_credit($amount_order, $amount_cum_order)
{
    global $order;
    $od_amount = 0;
    $table_cost = preg_split("[:,]", MODULE_LOYALTY_DISCOUNT_TABLE);
    for ($i = 0; $i < count($table_cost); $i += 2) {
        if ($amount_cum_order >= $table_cost[$i]) {
            $od_pc = $table_cost[$i + 1];

            $this->od_pc = $od_pc;
            $od_pc = 100 / $od_pc; // <----系統給的錯誤行
        }
    }

    $od_amount = $amount_order * $od_pc / 100;

    return $od_amount;
}


回歸正題:
1. 第一個問題你只是中文描述,說真的不知道怎麼幫你,有什麼報錯訊息嗎? 何謂疑似???
2. 第二個如題如下:
「Division by zero in ...」
其實警告訊息很明顯,分母不能為 0 (不能除以0的意思,數學老師應該有教唷)
所以你要提前判斷 $od_pc ,如果為0,就不要執行 「100/$od_pc」


彩虹
如果登入是使用AJAX,請使用瀏覽器的開發者工具,檢查一下
有可能只是因為報錯訊息造成無法取得正確的回傳值,所以才卡在登入頁面
總之就是將所有有關登入程式碼都貼上來 (要注意帳號密碼換掉)

(題外話:另外你是前端還是後端? 因為不知道你本身的程度在哪裡,所以如果有聽不懂的地方,可能要想另一個方式來協助你)
cookie888
感謝您的回覆
我的程度只會HTML, PHP的部分都是依產生錯誤訊息上網查詢硬改的
我有爬文看過分母那篇,知道是甚麼意思
但不知道要改哪裡??
不知道可麻煩直接跟我說這段我應該怎麼改嗎?因為真的完全沒有基礎

1	function calculate_credit($amount_order, $amount_cum_order) 
2	{ 
3	    global $order; 
4	    $od_amount = 0; 
5	    $table_cost = preg_split("[:,]", MODULE_LOYALTY_DISCOUNT_TABLE); 
6	    for ($i = 0; $i < count($table_cost); $i += 2) { 
7	        if ($amount_cum_order >= $table_cost[$i]) { 
8	            $od_pc = $table_cost[$i + 1]; 
9	 
10	            $this->od_pc = $od_pc; 
11	            $od_pc = 100 / $od_pc;
12	        } 
13	    } 
14	 
15	    $od_amount = $amount_order * $od_pc / 100; 
16	 
17	    return $od_amount; 
18	} 


另外我所謂的疑似
就是我的網站中
只要有登入的部分
登入帳號\加入購物車\
它可判斷數據是否正確
但都無法加入,或是登入成功
所以我猜想是沒有寫進資料庫
所以才沒出現下一步((因為他指示重新跳回登入頁面,沒有任何報錯,所以就不知從何查起)

我是將osc php4.3 升級5.3發生的錯誤
我有上網查詢好像有提到 php4 跟5連結資料庫的方式不同
但詳情我也看不懂.....


如蒙賜教,真的會非常非常感謝~~

cookie888
這個是login頁面的程式碼


  require('includes/application_top.php');
  
  tep_session_unregister('bonus');

// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled (or the session has not started)
  if ($session_started == false) {
    tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGIN);

  $error = false;
  if (isset($_GET['action']) && ($_GET['action'] == 'process')) {
    $email_address = tep_db_prepare_input($_POST['email_address']);
    $password = tep_db_prepare_input($_POST['password']);

// Check if email exists
$check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id, customer_discount from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
    if (!tep_db_num_rows($check_customer_query)) {
      $error = true;
    } else {
      $check_customer = tep_db_fetch_array($check_customer_query);
// Check that password is good
      if (!tep_validate_password($password, $check_customer['customers_password'])) {
        $error = true;
      } else {
        if (SESSION_RECREATE == 'True') {
          tep_session_recreate();
        }

        $check_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$check_customer['customers_id'] . "' and address_book_id = '" . (int)$check_customer['customers_default_address_id'] . "'");
        $check_country = tep_db_fetch_array($check_country_query);

        $customer_id = $check_customer['customers_id'];
        $customer_default_address_id = $check_customer['customers_default_address_id'];
        $customer_first_name = $check_customer['customers_firstname'];
        $customer_country_id = $check_country['entry_country_id'];
		$customer_discount = $check_customer['customer_discount'];
        $customer_zone_id = $check_country['entry_zone_id'];
        tep_session_register('customer_id');
        tep_session_register('customer_default_address_id');
        tep_session_register('customer_first_name');
        tep_session_register('customer_country_id');
		tep_session_register('customer_discount');
        tep_session_register('customer_zone_id');

        tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$customer_id . "'");

// restore cart contents
        $cart->restore_contents();

        if (sizeof($navigation->snapshot) > 0) {
          $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
          $navigation->clear_snapshot();
          tep_redirect($origin_href);
        } else {
          tep_redirect(tep_href_link(FILENAME_DEFAULT));
        }
      }
    }
  }

  if ($error == true) {
    $messageStack->add('login', TEXT_LOGIN_ERROR);
  }

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_LOGIN, '', 'SSL'));
?>

cookie888
還有購物車的部分,一整天都加不進去,但過了大約1天,突然又可以將商品加入了,但還是無法登入結帳
彩虹
1.分母不能為0,就加入判斷
function calculate_credit($amount_order, $amount_cum_order)
{
    global $order;
    $od_amount = 0;
    $table_cost = preg_split("[:,]", MODULE_LOYALTY_DISCOUNT_TABLE);
    for ($i = 0; $i < count($table_cost); $i += 2) {
        if ($amount_cum_order >= $table_cost[$i]) {
            $od_pc = $table_cost[$i + 1];

            $this->od_pc = $od_pc;
			if ($od_pc > 0) { // 加入判斷 $od_pc > 0 時,才做除法
				$od_pc = 100 / $od_pc;
			}
        }
    }

    $od_amount = $amount_order * $od_pc / 100;

    return $od_amount;
}


2.原來是 osCommerce ,這一套購物模組系統我倒是沒用過
另外你提到 「它可判斷數據是否正確」 所以表示資料庫是可以連接的
所以有可能是其他問題,但是這個要檢查很多地方
例如 session 有沒有啟動等等

有辦法查出你的 osCommerce 版本嗎?
cookie888
非常感謝您提供的第一問題解法?待會立馬來試

osc版本是這個↓
Copyright (c) 2002 osCommerce

session 有沒有啟動←請問是要如何查看??

session檔 內容是這個↓再麻煩您幫忙解惑,感謝~~

<?php
/*
  $Id: sessions.php,v 1.1.1.1 2003/08/14 08:00:15 nickle Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/


  if (STORE_SESSIONS == 'mysql') {
    if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
      $SESS_LIFE = 1440;
    }

    function _sess_open($save_path, $session_name) {
      return true;
    }

    function _sess_close() {
      return true;
    }

    function _sess_read($key) {
       $_POST["value"]_query = tep_db_query("select value from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "' and expiry > '" . time() . "'");
       $_POST["value"] = tep_db_fetch_array( $_POST["value"]_query);

      if (isset( $_POST["value"]['value'])) {
        return  $_POST["value"]['value'];
      }

      return false;
    }

    function _sess_write($key, $val) {
      global $SESS_LIFE;

      $expiry = time() + $SESS_LIFE;
       $_POST["value"] = $val;

      $check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
      $check = tep_db_fetch_array($check_query);

      if ($check['total'] > 0) {
        return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input( $_POST["value"]) . "' where sesskey = '" . tep_db_input($key) . "'");
      } else {
        return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input( $_POST["value"]) . "')");
      }
    }

    function _sess_destroy($key) {
      return tep_db_query("delete from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
    }

    function _sess_gc($maxlifetime) {
      tep_db_query("delete from " . TABLE_SESSIONS . " where expiry < '" . time() . "'");

      return true;
    }

    session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
  }

  function tep_session_start() {
    return session_start();
  }

  function tep_session_register($variable) {
    global $session_started;

    if ($session_started == true) {
		
      return isset($_SESSION[$variable]);
    } else {
      return false;
    }
  }

  function tep_session_is_registered($variable) {
    
	return isset($_SESSION[$variable]);
  }

  function tep_session_unregister($variable) {
    
	unset($_SESSION[$variable]); 
	
  }

  function tep_session_id($sessid = '') {
    if (!empty($sessid)) {
      return session_id($sessid);
    } else {
      return session_id();
    }
  }

  function tep_session_name($name = '') {
    if (!empty($name)) {
      return session_name($name);
    } else {
      return session_name();
    }
  }

  

  function tep_session_destroy() {
    return session_destroy();
  }

  function tep_session_save_path($path = '') {
    if (!empty($path)) {
      return session_save_path($path);
    } else {
      return session_save_path();
    }
  }

  function tep_session_recreate() {
    if (PHP_VERSION >= 4.1) {
      $session_backup = $_SESSION;

      unset($_COOKIE[tep_session_name()]);

      tep_session_destroy();

      if (STORE_SESSIONS == 'mysql') {
        session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
      }

      tep_session_start();

      $_SESSION = $session_backup;
      unset($session_backup);
    }
  }
?>


彩虹
session是猜測的~
實際原因要查很多地方,也有可能是 osCommerce 核心的部分也要更新

目前應該只是發現這些問題,但實際上可能很多地方都不能用~

我另外問一下,後台登入系統是正常的嗎? (管理者介面)
cookie888
後台登入系統也不行,前台所有要寫入的,譬如搜尋,登入會員,加入購物車,全都不行

最有價值解答

彩虹
這樣實在不好處理
1.因PHP對你幾乎沒辦法自行修改
2.我們也無法直接看到實際狀況
3.osCommerce (2002) 很久遠,維護他的不合成本
3.雖然從 php4.3升級到5.3,偏偏 5.3也是很久遠的版本
cookie888
了解,謝謝您撥冗回覆~~~~
回到頂部