Fatal error: Using $this when not in object context in C:\xampp\htdocs\sum.php on line 52 -
<?php echo '<body style="background-color:046c33">'; echo '<body style="background-color:orange">'; mysql_connect("127.0.0.1", "root", "") or die(mysql_error()); mysql_select_db("customers") or die(mysql_error()); ?> <html> <head> <title>search</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="post" > <table border="0" cellpadding="0" cellspacing="0"> <tr>enter nic number <td><input type="text" name="query" id="text" /> </td> <td><input type="submit" name="submit" id="search" value="search" /></td> </tr> </table> </form> <?php if(isset($_post['submit'])) { $query = $_post['query']; $min_length = 1; if(strlen($query) >= $min_length) { $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); echo "<table border='0' width='' align='center' cellpadding='1' cellspacing='1'>"; echo "<tr align='center' bgcolor='62e15e'> <td height='35px' width='150px'>name</td> <td>nic number</td><td>gvs ac/num</td><td>due date</td><td>amnt</td><td>due</td> <td>due balance</td><td>paymnet month</td><td>amount</td><td>interst</td><td bgcolor=red colspan=0>short</td><td>other chrg</td> <td>delay chrg</td><td>advance</td><td>total dedec</td><td>balance</td></tr>"; $raw_results =
mysql_query("select * pay_detec (
nic_num
'%".$query."%') or (cust_name
'%".$query."%')");$data = $this->db->query($sql)->result_array(); $totals = array(); if(mysql_num_rows($raw_results) > 0) { while($results = mysql_fetch_array($raw_results)) { foreach ($data $item){ $totals[$item['cust_name']] = isset($totals[$item['cust_name']]) ? $totals[$item['cust_name']] + $item['payment'] : $item['payment']; } foreach ($totals $payment => $val){ echo $payment.': '.$val; echo "\n\n"; }
echo "<tr align='center' bgcolor='fbe946'> <td height='25px'>".$results['cust_name']."</td> <td>".$results['nic_num']."</td><td>".$results['acc_num']."</td><td>".$results['due_date']."</td> <td>".$results['loan']."</td><td>".$results['due_months']."</td> <td>".$results['blanc_due']."</td><td>".$results['month_pay']."</td> <td>".$results['payment']."</td><td>".$results['intrst']."<td bgcolor=red colspan=0>".$results['short']."</td><td>".$results['othr_chrg']."</td><td>".$results['delay_chrg']."</td><td>".$results['advnc']."</td><td>".$results['ttl']."</td><td>".$results['blanc2']."</td></tr>" ; } } else{ echo "<tr align='center' bgcolor='#6c0000'> <td colspan='2' height='25px'>no results</td><tr>"; echo "</table>"; } } else{ echo "minimum length ".$min_length; } } echo "<a href='index.html'>home page</a>"; ?> </body> </html>
i suggest stop using mysql_ functions , start using pdo. in case line $data = $this->db->query($sql)->result_array();
doesn't make sense.
this piece of code wrong , should changed:
$raw_results = mysql_query("select * pay_detec (nic_num '%".$query."%') or (cust_name '%".$query."%')"); $data = $this->db->query($sql)->result_array(); $totals = array(); if(mysql_num_rows($raw_results) > 0) {
it should this:
$raw_results = mysql_query("select * pay_detec (nic_num '%".$query."%') or (cust_name '%".$query."%')"); $data = mysql_num_rows($raw_results); if(count($data) > 0) {
note not tested, hope guide in right direction. please have @ pdo tutorials since code absolutely not safe.