【问题标题】:Not Able to access MySQL data through php function无法通过php函数访问MySQL数据
【发布时间】:2017-11-04 16:30:28
【问题描述】:

我在clients.php中添加了客户端,如下截图所示:

更新:如果我从 manange_sale 页面添加新客户,列表很快就会出现!

当我尝试通过此功能在另一个页面中访问它们时:

function get_client_info($client_id, $term) { 
        global $db;
        $query = "SELECT * from clients WHERE client_id='".$client_id."'";
        $result = $db->query($query) or die($db->error);
        $row = $result->fetch_array();
        return $row[$term];
    }

它只是没有在该页面上显示任何客户列表:

请帮我解决这个问题。 注意:相同的脚本在在线主机上运行良好,但在 localhost 中导致问题。

客户端类的其余部分:

<?php
//Notes Class

class Client {
    public $full_name;
    public $business_title;
    public $mobile;
    public $phone;
    public $address;
    public $city;
    public $state;
    public $zipcode;
    public $country;
    public $email;
    public $price_level;
    public $notes;

    function get_client_info($client_id, $term) { 
        global $db;
        $query = "SELECT * from clients WHERE client_id='".$client_id."'";
        $result = $db->query($query) or die($db->error);
        $row = $result->fetch_array();
        return $row[$term];
    }//get user email ends here.

    function add_client($full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) {
        global $db;
        $query = "SELECT * from clients WHERE full_name='".$full_name."' AND store_id='".$_SESSION['store_id']."'";
        $result = $db->query($query) or die($db->error);
        $num_rows = $result->num_rows;

        if($num_rows > 0) { 
            return 'A client with same name already exists.';
        } else { 
            $query = "INSERT into clients(client_id, full_name, business_title, mobile, phone, address, city, state, zipcode, country, email, price_level, notes, store_id)
                VALUES(NULL, '".$full_name."', '".$business_title."', '".$mobile."', '".$phone."', '".$address."', '".$city."', '".$state."', '".$zipcode."', '".$country."', '".$email."', '".$price_level."', '".$notes."', '".$_SESSION['store_id']."')
            ";
            $result = $db->query($query) or die($db->error);
            $_SESSION['cn_id'] = $db->insert_id;
            return 'Client added successfuly.';
        }
    }//add warehouse ends here.

    function set_client($client_id) { 
        global $db;
        $query = 'SELECT * from clients WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
        $result = $db->query($query) or die($db->error);
        $row = $result->fetch_array();
        extract($row);
        $this->full_name = $full_name;
        $this->business_title = $business_title;
        $this->mobile = $mobile;
        $this->phone = $phone;
        $this->address = $address;
        $this->city = $city;
        $this->state = $state;
        $this->zipcode = $zipcode;
        $this->country = $country;
        $this->email = $email;
        $this->price_level = $price_level;
        $this->notes = $notes;
    }//Set Warehouse ends here..

    function update_client($client_id, $full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) { 
        global $db;
        $query = 'UPDATE clients SET
                  full_name = "'.$full_name.'",
                  business_title = "'.$business_title.'",
                  mobile = "'.$mobile.'",
                  phone = "'.$phone.'",
                  address = "'.$address.'",
                  city = "'.$city.'",
                  state = "'.$state.'",
                  zipcode = "'.$zipcode.'",
                  country = "'.$country.'",
                  email = "'.$email.'",
                  price_level = "'.$price_level.'",
                  notes = "'.$notes.'"
                   WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
        $result = $db->query($query) or die($db->error);
        return 'Client updated Successfuly!';
    }//update user level ends here. 

    function list_clients() {
        global $db;
        $query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
        $result = $db->query($query) or die($db->error);
        $content = '';
        $count = 0;
        while($row = $result->fetch_array()) { 
            extract($row);
            $count++;
            if($count%2 == 0) { 
                $class = 'even';
            } else { 
                $class = 'odd';
            }
            $content .= '<tr class="'.$class.'">';
            $content .= '<td>';
            $content .= $client_id;
            $content .= '</td><td>';
            $content .= $full_name;
            $content .= '</td><td>';
            $content .= $business_title;
            $content .= '</td><td>';
            $content .= $mobile;
            $content .= '</td><td>';
            $content .= $phone;
            $content .= '</td><td>';
            $content .= $address.' '.$city.' '.$state.' '.$zipcode.' '.$country;
            $content .= '</td><td>';
            $content .= $email;
            $content .= '</td><td>';
            $content .= $price_level;
            $content .= '</td><td>';
            $content .= currency_format($this->get_client_balance($client_id));
            $content .= '</td>';
            if(partial_access('admin')) {
            $content .= '<td><form method="post" name="edit" action="manage_client.php">';
            $content .= '<input type="hidden" name="edit_client" value="'.$client_id.'">';
            $content .= '<input type="submit" class="btn btn-default btn-sm" value="Edit">';
            $content .= '</form>';
            $content .= '</td><td>';
            $content .= '<form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
            $content .= '<input type="hidden" name="delete_client" value="'.$client_id.'">';
            $content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
            $content .= '</form>';
            $content .= '</td>';
            }
            $content .= '</tr>';
            unset($class);
        }//loop ends here.  
    echo $content;
    }//list_notes ends here.

    function delete_client($client_id) { 
        global $db;
        $query = "SELECT * FROM customer_log WHERE client_id='".$client_id."'";
        $result = $db->query($query) or die($db->error);
        $num_rows = $result->num_rows;

        if($num_rows > 0) { 
            return 'Please delete sale invoices, receivings, return invoices, return payments for related client first.';
        } else { 
            $query = "DELETE FROM clients WHERE client_id='".$client_id."'";
            $result = $db->query($query) or die($db->error);
            return 'Client deleted successfuly!';
        }
    }//delete client ends here.

    function client_options($client_id) {
        global $db;
        $query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
        $result = $db->query($query) or die($db->error);
        $options = '';
        if($client_id != '') { 
            while($row = $result->fetch_array()) { 
                if($client_id == $row['client_id']) {
                $options .= '<option selected="selected" value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
                } else { 
                $options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
                }
            }
        } else { 
            while($row = $result->fetch_array()) { 
                $options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
            }
        }
        return $options;


    }//vendor options ends here.

    function add_log($datetime, $client_id, $transaction_type, $type_table_id) {
        global $db;
        $query = "INSERT into customer_log(customer_log_id, datetime, client_id, transaction_type, type_table_id, store_id) VALUES(NULL, '".$datetime."', '".$client_id."', '".$transaction_type."', '".$type_table_id."', '".$_SESSION['store_id']."')";   
        $result = $db->query($query) or die($db->error);
        return $db->insert_id;
    }//add log ends here.

    function add_receiving($date, $method, $ref_no, $memo, $amount, $client_id) { 
        global $db;
        $query = "INSERT into receivings(receiving_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
        $result = $db->query($query) or die($db->error);
        return $db->insert_id;
    }//add_payment ends here.

    function add_return_payment($date, $method, $ref_no, $memo, $amount, $client_id) { 
        global $db;
        $query = "INSERT into sale_return_payment(return_payment_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
        $result = $db->query($query) or die($db->error);
        return $db->insert_id;
    }//add_payment ends here.


    function get_client_balance($client_id) { 
        global $db;

        $creditQuery = "SELECt * from creditors WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
        $creditResult = $db->query($creditQuery) or die($db->error);
        $receiveable = 0;

        while($creditRow = $creditResult->fetch_array()) {
            $receiveable += $creditRow['receiveable'];
            if($creditRow['receiveable'] == 0) { 
                $receiveable -= $creditRow['received']; 
            }
        }

        $receivingQuery = "SELECt * from receivings WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
        $receivingResult = $db->query($receivingQuery) or die($db->error);

        while($recevingRow = $receivingResult->fetch_array()) {
            $receiveable -= $recevingRow['amount'];
        }

        $sale_return_payment = "SELECt * from sale_return_payment WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
        $sale_payment_result = $db->query($sale_return_payment) or die($db->error);

        while($sale_return_row = $sale_payment_result->fetch_array()) { 
            $receiveable -= $sale_return_row['amount'];
        }

        return $receiveable;
    }//get vendor balance ends here.

    function list_receivings() {
        global $db;
        $query = 'SELECT * from receivings WHERE store_id="'.$_SESSION['store_id'].'" ORDER by receiving_id DESC';
        $result = $db->query($query) or die($db->error);
        $content = '';

        while($row = $result->fetch_array()) { 
            extract($row);

            $datetime = strtotime($datetime);
            $date = date('d-M-Y', $datetime);

            $client = $this->get_client_info($client_id, 'full_name');

            $user = new Users;
            $agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');

            $content .= '<tr><td>';
            $content .= $receiving_id;
            $content .= '</td><td>';
            $content .= $date;
            $content .= '</td><td>';
            $content .= $method;
            $content .= '</td><td>';
            $content .= $ref_no;
            $content .= '</td><td>';
            $content .= $agent;
            $content .= '</td><td>';
            $content .= $client;
            $content .= '</td><td>';
            $content .= $memo;
            $content .= '</td><td>';
            $content .= $amount;
            $content .= '</td>';
            if(partial_access('admin')) { 
                $content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
                $content .= '<input type="hidden" name="delete_receiving" value="'.$receiving_id.'">';
                $content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
                $content .= '</form>';
                $content .= '</td>'; }
                $content .= '</tr>';
            unset($class);
        }//loop ends here.  
    echo $content;
    }//list_notes ends here.

    function delete_receiving($receiving_id) {
        global $db;

        $query = "DELETE from receivings WHERE receiving_id='".$receiving_id."'";
        $result = $db->query($query) or die($db->error);

        $query = "DELETE from customer_log WHERE transaction_type='Sale Receiving' AND type_table_id='".$receiving_id."'";
        $result = $db->query($query) or die($db->error);

        $query = "DELETE from customer_log WHERE transaction_type='Receiving' AND type_table_id='".$receiving_id."'";
        $result = $db->query($query) or die($db->error);

        return 'Receiving deleted Successfuly.';    
    }//delete_purchase return receiving.

    function list_return_payments() {
        global $db;
        $query = 'SELECT * from sale_return_payment WHERE store_id="'.$_SESSION['store_id'].'" ORDER by return_payment_id DESC';
        $result = $db->query($query) or die($db->error);
        $content = '';

        while($row = $result->fetch_array()) { 
            extract($row);

            $datetime = strtotime($datetime);
            $date = date('d-M-Y', $datetime);

            $client = $this->get_client_info($client_id, 'full_name');

            $user = new Users;
            $agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');

            $content .= '<tr><td>';
            $content .= $return_payment_id;
            $content .= '</td><td>';
            $content .= $date;
            $content .= '</td><td>';
            $content .= $method;
            $content .= '</td><td>';
            $content .= $ref_no;
            $content .= '</td><td>';
            $content .= $agent;
            $content .= '</td><td>';
            $content .= $client;
            $content .= '</td><td>';
            $content .= $memo;
            $content .= '</td><td>';
            $content .= $amount;
            $content .= '</td>';
            if(partial_access('admin')) { 
                $content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
                $content .= '<input type="hidden" name="delete_sale_return_payment" value="'.$return_payment_id.'">';
                $content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
                $content .= '</form>';
                $content .= '</td>'; }
                $content .= '</tr>';
        }//loop ends here.  
    echo $content;
    }//list_notes ends here.

    function delete_sale_return_payment($return_payment_id) {
        global $db;

        $query = "DELETE from sale_return_payment WHERE return_payment_id='".$return_payment_id."'";
        $result = $db->query($query) or die($db->error);

        $query = "DELETE from customer_log WHERE transaction_type='Sale Return Refund' AND type_table_id='".$return_payment_id."'";
        $result = $db->query($query) or die($db->error);
        return 'Return Payment deleted Successfuly.';   
    }//delete_purchase return receiving.

    function clear_creditors($amount, $client_id){
        global $db;

        $query = "SELECT * FROM creditors WHERE client_id='".$client_id."' ORDER by credit_id ASC";
        $result = $db->query($query) or die($db->error);

        while($row = $result->fetch_array()) {
            extract($row);
            if($receiveable == 0 || $receiveable == $received || $amount == 0) { 
                //do nothing.
            } else { 
                if($received == 0) {
                    if($amount < $receiveable) { 
                        $receive = $amount;
                    } else { 
                        $receive = $receiveable;
                    }
                    $query_up = "UPDATE creditors SET
                        received = '".$receive."'
                        WHERE credit_id='".$credit_id."'
                        ";
                    $amount -= $receive;    
                } else if($received != 0) { 
                    $difference = $receiveable-$received;
                    if($amount < $difference) { 
                        $receive = $amount+$received;
                    } else { 
                        $receive = $difference+$received;
                    }
                    $query_up = "UPDATE creditors SET
                        received = '".$receive."'
                        WHERE credit_id='".$credit_id."'
                        ";
                    $amount -= $difference; 
                }
                $result_up = $db->query($query_up) or die($db->error);
            }//main if ends here.
        }//main loop ends.
    }//debts clear ends here.--

    function customers_balance_summary() { 
        global $db;

        $query = "SELECT * FROM clients WHERE store_id='".$_SESSION['store_id']."' ORDER by full_name ASC";
        $result = $db->query($query) or die($db->error);
        $content = '';
        $grand_total = 0;
        while($row = $result->fetch_array()) { 
            extract($row);
            //getting balance.
            $balance = $this->get_client_balance($client_id);
            $grand_total += $balance;

            $content .= '<tr><td>';
            $content .= $full_name;
            $content .= '</td><td>';
            $content .= $business_title;
            $content .= '</td><td align="right">';
            $content .= currency_format($grand_total);
            $content .= '</td></tr>';
        }   
            $new_store = new Store;
            $currency = $new_store->get_store_info($_SESSION['store_id'], 'currency');
            $content .= '<tr><th colspan="2" align="right">Grand Total</th><th align="right">'.$currency.' '.currency_format($grand_total).'</tH></tr>';
        echo $content;
    }//customers balance summary ends here.

    function customer_ledger_summary($client) {
        global $db;

        $query = "SELECT * from customer_log WHERE client_id='".$client."' ORDER by customer_log_id ASC";
        $result = $db->query($query) or die($db->error);
        $balance = 0;
        $content = '';
        $balance = 0;
        while($row = $result->fetch_array()) {
            extract($row);

            $datetime = strtotime($datetime);
            $date = date('d-M-Y', $datetime);

            $content .= '<tr><td>';
            $content .= $transaction_type;
            $content .= '</td><td>';
            $content .= $date;
            $content .= '</td><td>';
            $content .= $type_table_id;
            $content .= '</td><td>';

            if($transaction_type == 'Sale Invoice' || $transaction_type == 'Cash Sale') { 
                //Invoice Details.
                $sale_query = "SELECT * from sales WHERE sale_id='".$type_table_id."'";
                $sale_result = $db->query($sale_query) or die($db->error);

                while($sale_row = $sale_result->fetch_array()) {
                    $content .= $sale_row['memo'];
                    $content .= '</td><td>';
                }

                $sale_detail_query = "SELECT * from sale_detail WHERE sale_id='".$type_table_id."'";
                $sale_detail_result = $db->query($sale_detail_query) or die($db->error);
                $invoice_total = 0;
                while($sale_detail_row = $sale_detail_result->fetch_array()) { 
                    $credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
                    $credit_result = $db->query($credit_query) or die($db->error);

                    while($credit_row = $credit_result->fetch_array()) { 
                        $invoice_total += $credit_row['receiveable'];
                    }
                }
                $balance = $invoice_total+$balance;

                $content .= currency_format($invoice_total);
                $content .= '</td><td>';
                $content .= currency_format($balance);
                $content .= '</td></tr>';

            } else if($transaction_type == 'Sale Receiving' || $transaction_type == 'Receiving') { 
                //Cash receivign.
                $receiving_query = "SELECT * from receivings WHERE receiving_id='".$type_table_id."'";
                $receiving_result = $db->query($receiving_query) or die($db->error);
                while($receiving_row = $receiving_result->fetch_array()) { 
                    $content .= $receiving_row['memo'];
                    $content .= '</td><td>';

                    $balance = $balance-$receiving_row['amount'];
                    $content .= '('.currency_format($receiving_row['amount']).')';
                    $content .= '</td><td>';
                    $content .= currency_format($balance);
                    $content .= '</td></tr>';
                }
            } else if($transaction_type == 'Invoice Return' || $transaction_type == 'Sale Return') { 
                //sale return invoice.
                $sale_query = "SELECT * from sale_returns WHERE sale_rt_id='".$type_table_id."'";
                $sale_result = $db->query($sale_query) or die($db->error);

                while($sale_row = $sale_result->fetch_array()) {
                    $content .= $sale_row['memo'];
                    $content .= '</td><td>';
                }

                $sale_detail_query = "SELECT * from sale_return_detail WHERE sale_rt_id='".$type_table_id."'";
                $sale_detail_result = $db->query($sale_detail_query) or die($db->error);
                $invoice_total = 0;
                while($sale_detail_row = $sale_detail_result->fetch_array()) { 
                    $credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
                    $credit_result = $db->query($credit_query) or die($db->error);

                    while($credit_row = $credit_result->fetch_array()) { 
                        $invoice_total += $credit_row['received'];
                    }
                }
                $balance = $balance-$invoice_total;

                $content .= '('.currency_format($invoice_total).')';
                $content .= '</td><td>';
                $content .= currency_format($balance);
                $content .= '</td></tr>';


            } else if($transaction_type == 'Sale Return Refund') { 
                //sale Return Payment.
                $receiving_query = "SELECT * from sale_return_payment WHERE return_payment_id='".$type_table_id."'";
                $receiving_result = $db->query($receiving_query) or die($db->error);
                while($receiving_row = $receiving_result->fetch_array()) { 
                    $content .= $receiving_row['memo'];
                    $content .= '</td><td>';

                    $balance = $balance+$receiving_row['amount'];
                    $content .= currency_format($receiving_row['amount']);
                    $content .= '</td><td>';
                    $content .= currency_format($balance);
                    $content .= '</td></tr>';
                }
            }

        }//main loop ends here.
        echo $content;
    }//customer ledger summary ends here.
}//class ends here.

使用此类函数的显示屏幕代码: `

<?php
  include('system_load.php');
  //This loads system.
  //user Authentication.
  authenticate_user('subscriber');
  //creating company object.

  if(partial_access('admin') || $store_access->have_module_access('sales')) {} else { 
    HEADER('LOCATION: store.php?message=products');
  }

  if(!isset($_SESSION['store_id']) || $_SESSION['store_id'] == '') { 
    HEADER('LOCATION: stores.php?message=1');
  } //select company redirect ends here.


  if(isset($_POST['edit_purchase'])){ $page_title = 'Edit Sale'; } else { $page_title = 'Add Sale';}; //You can edit this to change your page title.
  require_once("includes/header.php"); //including header file.
?>

<?php if(isset($_GET['sale_id'])) { ?>
  <script type="text/javascript">
    window.open('reports/view_sale_invoice.php?sale_id=<?php echo $_GET['sale_id']; ?>', '_blank'); 
  </script>
<?php } ?>
                  <?php
          //display message if exist.
            if(isset($_GET['message']) && $_GET['message'] != '') { 
              echo '<div class="alert alert-success">';
              echo $_GET['message'];
              echo '</div>';
            }
            if(isset($message) && $message != '') { 
              echo '<div class="alert alert-success">';
              echo $message;
              echo '</div>';
            }
          ?>
<style type="text/css">
textarea:hover, textarea:focus, #items td.total-value textarea:hover, #items td.total-value textarea:focus, .delme:hover { background-color:#EEFF88; }

#items input[type=text] {width:60px;border:0px;}
.delete-wpr { position: relative; }
.delme { display: block; color: #000; text-decoration: none; position: absolute; background: #EEEEEE; font-weight: bold; padding: 0px 3px; border: 1px solid; top: -6px; left: -22px; font-family: Verdana; font-size: 12px; }
</style>

<script type="text/javascript">
jQuery(function($) {
  $('form[data-async]').on('submit', function(event) {

    var $form = $(this);
    var $target = $($form.attr('data-target'));

    $.ajax({
      type: $form.attr('method'),
      url: 'includes/otherprocesses.php',
      data: $form.serialize(),
      dataType: 'json',

    success: function(response) {
      var message = response.message;
      var client_options = response.client_options;
      var client_id = response.client_id;

      $('#client_id').html(client_options);
      $("#client_id").select2().select2('val', client_id);
      $('#success_message').html('<div class="alert alert-success">'+message+'</div>');
    }
  });
  event.preventDefault();
});
});
</script>

<!-- Add new vendor modal starts here. -->
<div class="modal fade" id="addnewclient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Add new client</h4>
      </div>

         <div class="modal-body">
         <form data-async data-target="#addnewclient" method="POST" enctype="multipart/form-data" role="form">
         <div id="success_message"></div>
            <table style="width:100%;">
                  <tr>
                      <td>
                    <div class="form-group">
                          <label class="control-label">Full Name*</label>
                            <input type="text" class="form-control" name="full_name" placeholder="Client full name" value="" required="required" />
                      </div>
                          </td>
                            <td>
                      <div class="form-group">
                          <label class="control-label">Business Title</label>

                        <input type="hidden" name="add_client" value="1" />
                         <input type="submit" id="submit" class="btn btn-primary" value="Add client">
                      </form>   
                              </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<!--add new vendor modal ends here.-->


<form action="includes/process_sale.php" method="post">
      <div class="row">              
        <div class="col-sm-5">
        <table border="0" cellpadding="5">
          <tr>
              <td width="110">Date</td>
                <td width="300"><input type="text" name="date" class="form-control datepick" readonly="readonly" value="<?php echo date('Y-m-d'); ?>" /></td>
            </tr>
            <tr>
              <td>Custom Inv#</td>
                <td><input type="text" placeholder="Custom Invoice number" name="custom_inv_no" class="form-control" /></td>
            </tr>

            <tr>
              <td>Memo</td>
                <td><textarea placeholder="Memo" name="memo" class="form-control"></textarea></td>
            </tr>

            <tr>
              <th>Select Client</th>
                <td>
                  <select name="client_id" id="client_id" class="autofill" style="width:100%">
                      <option value="">Select Client by full name or mobile</option>
                      <?
                      =$client->client_options($client->client_id); 
                      ?>  
                    </select> 
                </td>
            </tr>

            <tr>
              <td>&nbsp;</td>
                <td><a class="btn btn-default btn-xs" data-toggle="modal" href="#addnewclient">Add new Client</a></td>
            </tr>

        </table>
       </div><!--left-side-form ends here.-->
<script type="text/javascript">
function update_total() { 
  var grand_total = 0;

  i = 1;  
  $('.total').each(function(i) {
        var total = $(this).html();

    total = parseFloat(total);

    grand_total = total+grand_total;
    });
  $('#grand_total').html(grand_total.toFixed(2));

}//Update total function ends here.


<?php
  require_once("includes/footer.php");
?>

【问题讨论】:

  • 调试 $db。很可能您没有在该脚本文件中创建数据库连接的代码。
  • 正如我上面提到的,该脚本是完整的并且可以在在线主机上完美运行。数据库连接功能齐全,您可以看到第一张图片。请 +1 我的帖子,以便有人可以回答。谢谢
  • 复制服务器数据库到你的本地主机...
  • 其他数据库脚本是否在此本地设置上工作?如果没有,您是否检查了本地 phpinfo 以验证正确加载了 mysql 扩展?那台电脑是否运行任何阻止mysql端口的防火墙程序?是否有任何错误信息显示?请更具体以获得更准确的答案
  • @SyedEkramUddinEmon 所有其他脚本都运行顺利,但这个特定字段除外。我首先确保我所有的扩展都工作正常。我正在添加此代码的其余部分以帮助您识别问题。谢谢。

标签: php mysql localhost wamp


【解决方案1】:

本地主机使用什么平台?在线linux服务器和本地Windows机器?当它在本地主机上运行时,您是否收到警告、通知或排序?甚至是致命的?

<?
                  =$client->client_options($client->client_id); 
                  ?>

这看起来很奇怪。为什么是“=”?

【讨论】:

  • 当它是这样时,它在选择客户端字段下方给出了错误:=$client->client_options($client->client_id);?> 我检查了 Phpcodechecker 上的 sn-p 并它没有给出任何错误。此外,我正在使用带有 PHP 版本的 wamp 服务器。 5.6,它确实给了我任何错误。唯一可能发生冲突的是我必须为 SQL 本地主机分配一个端口 8080,因为微软正在使用端口 80。尽管您关于此代码的方法是正确的。请进一步挖掘。
  • 您还必须做的是,在 Location 标头之后使用退出。 secure.php.net/manual/en/function.header.php 。如果你有需要缓存的内容,那么你应该通过 ob_start 和类似的函数来做到这一点。
【解决方案2】:

好的,我终于想通了如何通过上面提供的提示使其工作。实际上这种语法在这种情况下不起作用:

<?=$client->client_options($client->client_id);?>

解决办法是:

<?php echo $client->client_options($client->client_id); ?>  

感谢大家的集思广益。

【讨论】:

    猜你喜欢
    • 2010-10-19
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    相关资源
    最近更新 更多