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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Supplied argument error, not sure if PHP post or MySQL post

Status
Not open for further replies.

tyrannus

MIS
Apr 6, 2006
115
US
I am new to PHP programming and have inherited a program that hasn't been touched in over 9 months so I have no real direction with it. I have an HTML form that asks basic info, enter start and end date, enter amounts less than and greater than.... What the problem is, when I enter the dates and leave the amount fields blank everything works fine.. if I enter an amount say less than 200 and greater than 100. I get this error: Warning: Supplied argument is not a valid MySQL result resource in /usr/home/chaven/public_html/rpt600a.php on line 119.
Any and ALL help will be greatly appreciated..
Here is the code for the page that gets this error:

<?php
require 'include.php';
check_login($user_name, $password, $user, $security);

$zstart=tosqldate($startdate);
$zstop=tosqldate($stopdate);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Gift Detail Report</title>
<script language="JavaScript">
function printit()
{
rptprint=window.open("rpt600b.php?zstart=<? echo $zstart; ?>&zstop=<? echo $zstop; ?>&constituency=<? echo $constituency; ?>&campaign=<? echo $campaign; ?>&appeal=<? echo $appeal; ?>&greaterthan=<? echo $greaterthan; ?>&lessthan=<? echo $lessthan; ?>", "rptprint", "scrollbars=no,width=700,height=1000")
}
</script>
</head>


<?
printbodytag();
printtop($user,$HTTP_SERVER_VARS['PHP_SELF']);
?>
<div align="center">
<font size="+2">Christian Haven, Inc.</font><br>
<em>Gift Detail Report from <? echo tostddate($zstart); ?> to <? echo tostddate($zstop); ?></em><br>
<input type="button" onclick="printit()" name="close" value="Print">

<hr width="600">
</div>

<?


$zzorder = 'c.lname,c.fname,g.post_date';
$zsearch="";
$zsearch1="";
$zzin="";

if ($campaign>0)
{
$zsearch=$zsearch." and g.campaign='$campaign'";
}

if ($appeal>0)
{
$zsearch=$zsearch." and g.appeal='$appeal'";
}

if ($acct_code>0)
{
$zsearch=$zsearch." and g.acct_code='$acct_code'";
}

if ($greaterthan <> "")
{
$zsearch1=$zsearch1." total >= '$greaterthan'";
}

if ($lessthan <> "")
{
if ($greaterthan == "")
{
$zsearch1=$zsearch1." total <= '$lessthan'";
} else {
$zsearch1=$zsearch1." and total <= '$lessthan'";
}
}

if ($zcon>0)
{
$zsearch=$zsearch." and c.con_id='$zcon'";
}
elseif ($constituency>0)
{
$zsearch=$zsearch." and (constituency0='$constituency' or constituency1='$constituency' or constituency2='$constituency' or constituency3='$constituency' or constituency4='$constituency' or constituency5='$constituency' or constituency6='$constituency' or constituency7='$constituency' or constituency8='$constituency' or constituency9='$constituency')";
}

if ($zsearch1 <> "")
{
$qs = "select c.con_id,sum(g.amount) as total from gift as g,constituent as c,sup_acct_code as sa where g.post_date<='$zstop' and g.post_date>='$zstart' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id $zsearch group by c.con_id having ($zsearch1)";
$q = mysql_query($qs);
while ($row=mysql_fetch_array($q))
{
if ($zzin == "")
{
$zzin = "'$row[0]'";
} else {
$zzin = $zzin.",'$row[0]'";
}
}
}

if ($zzin == "")
{
$qs = "select c.lname,c.fname,g.post_date,g.typegift,sa.acct_code,g.amount,c.addr1,c.addr2,c.city,s.state,c.zip,g.campaign,c.phone0,c.ptype0,ap.appeal from gift as g,constituent as c,sup_acct_code as sa,sup_state as s,sup_appeal as ap where g.typegift=1 and g.appeal=ap.appeal_id and c.state=s.state_id and g.post_date<='$zstop' and g.post_date>='$zstart' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id $zsearch order by ".$zzorder;
} else {
$qs = "select c.lname,c.fname,g.post_date,g.typegift,sa.acct_code,g.amount,c.addr1,c.addr2,c.city,s.state,c.zip,g.campaign,c.phone0,c.ptype0,ap.appeal from gift as g,constituent as c,sup_acct_code as sa,sup_state as s,sup_appeal as ap where g.typegift=1 and g.appeal=ap.appeal_id c.state=s.state_id and g.post_date<='$zstop' and g.post_date>='$zstart' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id $zsearch and c.con_id ($zzin) order by ".$zzorder;
}
$q = mysql_query($qs);
?>
<table align="center" width="600">
<tr>
<td><strong>Constituent</strong></td>
<td><strong>Date</strong></td>
<td><strong>Account</strong></td>
<td><strong>Campaign</strong></td>
<td><strong>Appeal</strong></td>
<td><strong>Amount</strong></td>
</tr>

<?
echo(" <tr><td colspan='6'><hr></td></tr>\n");
$last='~~';
$zi = 0;
$ctotal=0;
while($row=mysql_fetch_array($q))
{
if (strlen($row[1])>0)
{
$name="$row[0], $row[1]";
} else {
$name="$row[0]";
}
if ($last <> $name)
{
if ($zi < 5 and $zi > 0)
{
if ($zi < 3)
{
echo(" <tr><td>$addr1</td><td></td><td></td><td></td><td></td><td></td></tr>\n");
}
if ($zi < 4)
{
if ($addr2 <> "")
{
echo(" <tr><td>$addr2</td><td></td><td></td><td></td><td></td><td></td></tr>\n");
} else {
echo(" <tr><td>$city, $state $zip<br>$phone0</td><td></td><td></td><td></td><td></td><td></td></tr>\n");
}
}
if ($zi < 5)
{
if ($addr2 <> "")
{
echo(" <tr><td>$city, $state $zip<br>$phone0</td><td></td><td></td><td></td><td></td><td></td></tr>\n");
}
}
}
if ($zi > 0)
{
$zzctotal=number_format($ctotal,2);
echo(" <tr><td></td><td></td><td></td></td><td><td><b>Constituent Total:</b></td><td align='right'><b>$zzctotal</b></td></tr>\n");
echo(" <tr><td colspan='6'><hr></td></tr>\n");
}
$zi = 1;
$ctotal=0;
$last = $name;
}
$date=tostddate($row[2]);
$acct_code=$row[3];
$amount=$row[4];
$campaign=$row['campaign'];
echo(" <tr>\n");
if ($zi == 1)
{
echo(" <td><b>$name</b></td>\n");
} elseif ($zi == 2) {
echo(" <td>$addr1</td>\n");
} elseif ($zi == 3) {
if ($addr2<>"")
{
echo(" <td>$addr2</td>\n");
} else {
echo(" <td>$city, $state $zip</td>\n");
}
} elseif ($zi == 4) {
if ($addr2<>"")
{
echo(" <td>$city, $state $zip</td>\n");
} else {
echo(" <td></td>\n");
}
} else {
echo(" <td></td>\n");
}
echo(" <td>$date</td>\n");
echo(" <td>$acct_code</td>\n");
$qsqs="select campaign from sup_campaign where campaign_id='$campaign'";
$qqqq = mysql_db_query($db, $qsqs, $connection);
$rrtt = mysql_fetch_array($qqqq);
echo(" <td>$rrtt[0]</td>\n");
echo(" <td>".$row['appeal']."</td>\n");
echo(" <td align=right>$amount</td>\n");
$ctotal=$ctotal+$amount;
echo(" </tr>\n");
$zi++;
$addr1=$row['addr1'];
$addr2=$row['addr2'];
$city=$row['city'];
$state=$row['state'];
$zip=$row['zip'];
$phone0=$row[11];
}
$zzctotal=number_format($ctotal,2);
if ($zi < 5 and $zi > 0)
{
if ($zi < 3)
{
echo(" <tr><td>$addr1</td><td></td><td></td><td></td><td></td></tr>\n");
}
if ($zi < 4)
{
if ($addr2 <> "")
{
echo(" <tr><td>$addr2</td><td></td><td></td><td></td><td></td></tr>\n");
} else {
echo(" <tr><td>$city, $state $zip<br>$phone0</td><td></td><td></td><td></td><td></td></tr>\n");
}
}
if ($zi < 5)
{
if ($addr2 <> "")
{
echo(" <tr><td>$city, $state $zip<br>$phone0</td><td></td><td></td><td></td><td></td></tr>\n");
}
}
}
echo(" <tr><td></td><td></td><td></td><td><b>Constituent Total:</b></td><td align='right'><b>$zzctotal</b></td></tr>\n");
echo(" <tr><td colspan='6'><hr></td></tr>\n");

if ($zzin == "")
{
$qs = "select count(*),sum(g.amount) from gift as g,constituent as c,sup_acct_code as sa where g.post_date<='$zstop' and g.post_date>='$zstart' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id $zsearch";
} else {
$qs = "select count(*),sum(g.amount) from gift as g,constituent as c,sup_acct_code as sa where g.post_date<='$zstop' and g.post_date>='$zstart' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id $zsearch and c.con_id in ($zzin)";
}
$q = mysql_query($qs);
$row=mysql_fetch_array($q);
echo(" <tr>\n");
echo(" <td><strong>$row[0] Gifts counted</strong></td>\n");
echo(" <td></td>\n");
echo(" <td></td>\n");
echo(" <td></td>\n");
echo(" <td><strong>Total</strong></td>\n");
echo(" <td align=right><strong>$row[1]</strong></td>\n");
echo(" </tr>\n");
?>

</table>
<div align="center">
<?
if ($prevmenu<>"")
{
echo ("<div align='center'><a href='menu.php?menu=$prevmenu'>Return to previous Menu</a></div>");
}
?>
</div>
</body>
</html>
 
i suspect you have a sql error that you are not trapping.
change this line
Code:
$q = mysql_query($qs);
to
Code:
$q = mysql_query($qs) or die(mysql_error());
 
Right before "$q = mysql_query($qs);" try inserting "echo $qs" to see what the query looks like.
 
Ok tried jpadie's idea and got this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('2','3','4','5','11','12','15','16','17','18','19','20','21','

that sequence of numbers comes from the ($zzin) in the sql syntax.
 
This is after lgarner's post:

select c.lname,c.fname,g.post_date,g.typegift,sa.acct_code,g.amount,c.addr1,c.addr2,c.city,s.state,c.zip,g.campaign,c.phone0,c.ptype0,ap.appeal from gift as g,constituent as c,sup_acct_code as sa,sup_state as s,sup_appeal as ap where g.typegift=1 and g.appeal=ap.appeal_id and c.state=s.state_id and g.post_date<='' and g.post_date>='' and g.acct_code=sa.acct_code_id and g.con_id=c.con_id and c.con_id ('2','3','4','5','11','12','15','16','17','18','19','20','21','24','25','28','29','30','31','33','36','37','38','41','43','44','46','47','49','50','51','52','53','54','55','56','58','59','60','64','65','67','69','71','72','74','75','77','79','85','86','87','90','91','95','96','98','101','103','104','105','107','108','109','111','115','117','118','119','120','122','124','126','127','128','130','131','132','134','135','138','139','141','143','146','147','148','149','150','151','152','154','155','156','158','162','164','166','167','170','171','172','173','174','175','177','178','179','180','181','183','184','185','187','188','190','191','192','193','194','196','199','202','203','205','206','207','208','209','210','211','212','214','215','216','218','219','220','222','226','227','228','229','230','231','233','234','239','241','243','246','248','249','250','251','252','255','258','259','260','261','262','265','266','269','270','271','272','273','277','278','280','281','283','285','286','287','288','289','290','292','293','296','298','300','301','302','303','304','305','306','308','309','310','313','314','315','316','318','320','321','322','324','325','328','329','332','333','334','336','338','340','341','342','343','344','346','347','350','351','352','353','355','356','357','358','360','361','362','365','366','368','369','370','372','377','382','383','384','386','387','389','390','393','394','397','399','400','401','402','404','408','409','410','414','417','419','422','423','425','426','430','431','433','434','436','439','440','441','442','443','444','445','446','447','448','449','451','452','453','456','457','462','465','468','469','472','474','477','479','480','481','482','483','484','485','487','488','493','495','496','497','499','500','501','502','503','504','505','507','508','514','516','521','524','526','528','529','530','532','533','534','535','537','538','539','541','543','544','547','548','549','551','554','556','557','558','559','560','561','562','563','564','566','567','568','571','572','573','574','577','579','581','582','583','584','585','586','587','589','592','594','595','596','597','599','603','604','606','607','610','611','614','615','616','617','619','620','621','622','623','624','628','630','631','632','633','635','636','637','638','640','641','642','644','645','647','648','649','650','651','653','655','656','658','659','660','661','662','664','665','666','667','668','669','670','671','672','673','676','677','678','680','685','686','688','690','691','694','695','696','697','698','699','700','701','702','703','704','705','706','707','708','709','712','713','716','718','719','720','721','722','723','724','726','728','729','732','734','735','737','738','739','741','743','744','746','747','748','750','751','753','754','755','758','760','762','763','764','765','766','767','768','769','770','771','773','774','775','776','777','779','781','782','783','784','785','786','787','788','790','791','792','793','794','795','796','797','798','799','801','803','804','805','806','807','809','810','811','812','813','814','815','816','817','819','820','821','822','823','824','825','826','827','828','829','831','833','834','836','837','838','839','840','841','842','843','844','846','847','848','849','850','851','852','853','854','855','856','857','858','859','862','863','864','865','867','868','869','871','872','873','874','875','876','878','879','880','881','882','883','885','887','888','889','890','891','892','893','894','895','896','898','899','900','901','902','903','904','905','907','908','909','910','911','913','914','916','917','918','919','923','924','927','928','929','931','932','934','938','939','940','941','943','944','945','946','947','948','951','952','953','954','955','956','958','959','961','962','963','964','967','968','969','971','972','973','974','975','976','978','980','981','982','983','984','985','986','987','988','989','990','991','993','994','996','997','998','1002','1003','1004','1006','1007','1008','1009','1010','1011','1012','1015','1017','1018','1019','1020','1021','1023','1024','1025','1026','1027','1031','1032','1033','1034','1035','1036','1037','1039','1041','1042','1044','1045','1047','1048','1049','1051','1052','1054','1055','1427','1592','1593','1605','1608','1609','1611','1613','1614','1619','1621','1632','1634','1638','1640','1643','1644','1645','1646','1647','1650','1652','1655','1657','1658','1671','1681','1684','1687','1689','1701','1704','1710','1789','2529','2542','2550','2573','2579','2580','2585','2593','2753','2861','2879','2882','2887','2913','2915','2959','2994','2999','3000','3001','3002','3145','3280','3369','3389','3395','3406','3416','3417','3430','3437','3445','3450','3455','3465','3479','3487','3498','3501','3506','3510','3526','3532','3533','3534','3542','3543','3562','3608','3620','3622','4755') order by c.lname,c.fname,g.post_date
 
wow there really needs to be an option to edit your posts... Sorry bout how this looks right now
 
Yep.

You've got an error in this part:

c.con_id ('2','3','4

There has to be some word or punctuation in there.



Should this read:

c.con_id in ('2','3','4

?



Want the best answers? Ask the best questions! TANSTAAFL!
 
It probably should read like that, let me try it..
 
well ... there's your problem in black and white (and widescreen).

there is no comparison before the brackets. i suspect you are missing an " in "
 
That took care of it. Thanks y'all.. I am still so new to this that it is hard for me to pick up on things like that.. Many Many thanks..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top