0

I have never dealt with PHP until now and could really use some help. There is several things I need to make happen before it's usable, but will focus on one things right now.

I am getting the following error:

Warning: Missing argument 1 for total_district_bill(), called in C:\xampp\htdocs\mtg\report.php on line 26 and defined in C:\xampp\htdocs\mtg\functions.php on line 38

Notice: Undefined variable: district2 in C:\xampp\htdocs\mtg\functions.php on line 40

FPDF error: Some data has already been output, can't send PDF file

I have already done something similar, but running into issues now for some reason. I need to display the count by a district number who brought their bill. Basically something like this:

$sql = "SELECT COUNT(*) FROM all_records 
        WHERE BI_VOTING_DIST_CD='$district' AND Brought_Bill='YES'";

This is what I got so far:

<?php
//Total count of all members
function total_members() {

$sql = "SELECT COUNT(*) FROM all_records"; 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return '<span class="totals"><b>'.$row['COUNT(*)'].'</b> Members Registered</span><br />';

}

//Total count of all registered members
function total_registered() {

$sql = "SELECT COUNT(*) FROM all_records WHERE Is_Registered='1'"; 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return '<br /><br /><span class="totals"><b>'.$row['COUNT(*)'].'</b>/</span>';

}


//Function to count registered by district
//Pass district number and board member last name
function total_district($district, $name) {

$sql = "SELECT COUNT(*) FROM all_records WHERE BI_VOTING_DIST_CD='$district' AND      Is_Registered='1'"; 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return '<tr><td>'.$district.' - '.$name.'</td><td> <b>'.$row['COUNT(*)'].'</b></td>';

}

//Function to count registered by district who brought bill
function total_district_bill($district2) {

$sql = "SELECT COUNT(*) FROM all_records WHERE BI_VOTING_DIST_CD='$district2' AND  Is_Registered='1'"; 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return '<tr><td>/td><td> <b>'.$row['COUNT(*)'].'</b></td>';

//$sql = "SELECT COUNT(*) FROM all_records WHERE BI_VOTING_DIST_CD='$district' AND  Brought_Bill='YES'"; 
//$result = mysql_query($sql);
//$row = mysql_fetch_array($result);

//return '<tr><td>'.$district.' - '.$name.'</td><td> <b>'.$row['COUNT(*)'].'</b></td>';

}

//Total count of all registered members' meals
function total_Brought_Bill() {

$sql = "SELECT SUM(Brought_Bill) FROM all_records WHERE Is_Registered='1'"; 
$result = mysql_query($sql);
$row = mysql_fetch_row($result);

return '<br /><br /><span class="totals"><b>'.$row['0'].'</b>/</span>';
//return '<span class="totals">Total Who Brought Bill: <b>'.$row[0].'</b></span>';

}


//total count of all notes entered, registered or not.  This is also the indication of how much  work you will have to do the next day :D
function total_notes() {

$sql = "SELECT COUNT(notes) FROM all_records WHERE Is_Registered=1"; 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return '<br /><span class="totals">Total Notes: <b>'.$row['COUNT(notes)'].'</b></span><br />';

}

//return value from coop information DB
function coop_info($column) {
$sql = "SELECT $column FROM coop LIMIT 1"; 
$result = mysql_query($sql) or trigger_error(mysql_error().$sql);
$row = mysql_fetch_array($result);

return $row[$column];
}

function ticketCheck($voucher){
$sql = "SELECT COUNT(*) FROM all_records WHERE voucher='$voucher'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

return $row['COUNT(*)'];
}

//TEST
//function total_Brought_Bill() {

//$sql = "SELECT SUM(Brought_Bill) FROM all_records WHERE Is_Registered='1'"; 
//$result = mysql_query($sql);
//$row = mysql_fetch_row($result);

//return '<br /><br /><span class="totals"><b>'.$row['0'].'</b>/</span>';
//return '<span class="totals">Total Who Brought Bill: <b>'.$row[0].'</b></span>';
//}

?>
Community
  • 1
  • 1
  • Where is the code that calls your functions? – showdev Oct 13 '14 at 20:37
  • 2
    You never wrote PHP yet you managed to write deprecated mysql_* code? Something's not right here.. – icecub Oct 13 '14 at 20:38
  • 2
    @icecub, I guess that's the power of old posts on the internet :) – fejese Oct 13 '14 at 20:46
  • `mysql_*` functions [are deprecated](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), use [mysqli](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/ref.pdo-mysql.php). –  Oct 13 '14 at 20:59
  • Showdev - Not there currently, but can always post the code for the functions tomorrow. – JustinDS Oct 14 '14 at 21:27
  • Icecub - I should of clarified. I am actually working off an existing code base that needed to be tweaked and added to for our use. – JustinDS Oct 14 '14 at 21:28
  • Andre Daniel - Not familiar with mysqli or PDO, but I guess I could always try to pick either or up. As I am not familiar with any of it. – JustinDS Oct 14 '14 at 21:30

1 Answers1

1

Problem:

Warning: Missing argument 1 for total_district_bill(), called in C:\xampp\htdocs\mtg\report.php on line 26 and defined in C:\xampp\htdocs\mtg\functions.php on line 38

Let's break it down:

This means that in report.php on line 26, you called the function total_district_bill without passing any parameters.

like this for example:

line 26: total_district_bill();

But when you defined total_district_bill($district2) in functions.php on line 38 with an argument called $district2

Solution

Pass the required argument to total_district_bill


And use mysqli extensions , mysql extension is deprecated.

mysql is extension deprecated

mysql is extension deprecated

meda
  • 45,103
  • 14
  • 92
  • 122
  • I will have to look into mysqli. I was not aware of this as I am just working off a pre-existing code. As for the solution you posted, how exactly would you pass the required argument to it? – JustinDS Oct 14 '14 at 21:31
  • That I wouldn't know but the field is `BI_VOTING_DIST_CD` name, so you need to get that value and pass it to `total_district_bill()` @JustinDS – meda Oct 14 '14 at 21:40