Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get this to work--POST/ GET variable

Status
Not open for further replies.

elentz

Technical User
Jan 9, 2007
81
US
I have a php script sending a single variable within the URL to the next page. it looks something like this ..///statementpdf.php?accountid=4103 If I create a PHP script statementpdf.php with echo $_get ['accountid'}; and run the first script I get the correct result on the page. When I assign a variable to this $_get it doesn't work with my queries in my code. Here's my code:
Code:
<?php
define('FPDF_FONTPATH','font/');
require('mysql_table.php');
$myvar= $_GET['accountid'];


class PDF extends PDF_MySQL_Table


{
function Header()
{
        //Title
        $this->SetFont('Arial','',18);
        $this->Cell(0,50,'Account Statement',0,1,'C');   //the second number in the Cell(x,yy,) is the vertical position of the line
        $this->Ln(10);
        //Ensure table header is output
        parent::Header();
}
}

//Connect to database
mysql_connect('localhost','xxxx','xxxxx');
mysql_select_db('vtigercrm50');

//***********Get Billing Info **************
$sql = "SELECT
        vtiger_account.accountname,
        vtiger_accountbillads.accountaddressid,
        vtiger_accountbillads.bill_street,
        vtiger_accountbillads.bill_city,
        vtiger_accountbillads.bill_state,
        vtiger_accountbillads.bill_code,
        vtiger_account.phone,
        vtiger_account.fax
        FROM
        vtiger_account
        Inner Join vtiger_accountbillads ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
        WHERE
        vtiger_account.accountid = '$myvar'";


$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
$customername =$row['accountname'];
$fax=$row['fax'];
$address=$row['bill_street'];
$city=$row['bill_city'];
$state=$row['bill_state'];
$code=$row['bill_code'];
$phone=$row['phone'];
//*************Close *******************
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
$pdf->Image('cqilogo.png',5,4,50);
$pdf->SetFont('Times','B',12);
$pdf->Cell(1,-55,'Customer :');
$pdf->SetFont('Times','',10);
$pdf->Cell(1,-45,$customername);
$pdf->Cell(-1,-38,$address);
$pdf->Cell(30,-31,$city,",");
$pdf->Cell(8,-31,$state);
$pdf->Cell(-40,-31,$code);
$prop=array('HeaderColor'=>array(255,150,100),
                       // 'color1'=>array(210,245,255),
                       // 'color2'=>array(255,255,210),
                        'padding'=>2);

 //********************Outstanding Balance Query*********************
 
$dataquery = "SELECT SUM(total) As balance
        FROM vtiger_invoice Where accountid = '$myvar' and invoicestatus Not Like "Paid"";
$result=mysql_query($dataquery);
$rowdata=mysql_fetch_row($result);
$Balance=$rowdata[0];
$bal = Number_Format ($Balance,2);
//*************************30 Days or less******************************************
$dataquery2 = "SELECT SUM(total) As over30
         FROM vtiger_invoice Where invoicedate >=Date_sub(Curdate(),interval 30 Day) and accountid = '$myvar' and invoicestatus Not Like "Paid"";
$result=mysql_query($dataquery2);
$rowdata=mysql_fetch_row($result);
$over30days=$rowdata[0];
$over30 = Number_Format ($over30days,2);
//********************************************************************

//**********************************Last 60 Days********************************
$dataquery3 = "SELECT SUM(total) As over60
        FROM vtiger_invoice Where invoicedate >=Date_sub(Curdate(),interval 60 Day) and accountid = '$myvar' and invoicestatus Not Like "Paid"";
$result=mysql_query($dataquery3);
$rowdata=mysql_fetch_row($result);
$over60days=$rowdata[0];
$over60 = Number_Format ($over60days,2);

 //*********************************************************************************




$pdf->Table("SELECT
        vtiger_invoice.invoice_no,
        vtiger_invoice.invoicestatus,
        FORMAT(vtiger_invoice.total,2)AS Total,
        DATE_FORMAT(vtiger_invoice.invoicedate,%m/%d/%Y\) AS InvDate,
        DATE_FORMAT(vtiger_invoicecf.cf_674,%m/%d/%Y\) AS Paid
        FROM
        vtiger_invoice
        Inner Join vtiger_invoicecf ON vtiger_invoicecf.invoiceid = vtiger_invoice.invoiceid
        WHERE
        vtiger_invoice.accountid = '$myvar'
        ORDER BY
        vtiger_invoice.accountid ASC",$prop);


$pdf->SetFont('Times','',10);
$pdf->Cell(30,10,'Outstanding Balance:$');
$pdf->Cell(20,10,$bal,0,0,R);
$pdf->Cell(20,10,'Less Than 30 Days:$');
$pdf->Cell(20,10,$over30,0,0,R);
$pdf->Cell(25,10,'Less Than 60 Days:$');
$pdf->Cell(20,10,$over60,0,0,R);
$pdf->Cell(20,10,'Please Pay Now: $');
$pdf->Cell(20,10,$paynow,0,0,R);

$pdf->Output();
?>

When this page is opened I get nothing but a blank page. I have several queries and if I manually enter an accountid instead of the $myvar in all of them the page loads fine. Would anyone care to comment on where I went wrong here?

Thanks Alot!
 
make sure that you have error_reporting and error_display turned on in php.ini or that you add these lines at the start of your script

Code:
ini_set('display_errors', true);
error_reporting(E_ALL);

also every time you call a mysql function like _query _select_db and _connect you should test the result and, if false, check the output of mysql_error().

you should also conditionalise your myvar assignment

Code:
$myvar = empty($_GET['accountid']) ? 'somedefaultvalue' : trim($_GET['accountid']);
 
I inserted your first code into the script and still got a blank screen when I tried it.

I also put in your code to conditionalize the variable with no luck.

any other thoughts?
 
you probably have an earlier error that the debugging code can't pick up. change the error_reporting and error_display settings in php.ini and restart the webserver.

i assume also that you have added the mysql_error language to each mysql_* call as said above?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top