0) { $totpr = mysql_fetch_array($r); if (is_null($totpr['tot'])) { $totcreds=0; } else { $totcreds = $totpr['tot']; }}else{ $totcreds = 0;}?> Total Number of CPE Credits on File for current plus last 3 years   0){?> Date Complete Program Sponsor Mode Credits = '". date("Y-m-d") . "'"; //print $q; $r = mysql_query($q); $nr = mysql_num_rows($r); if ($nr>0) { $totpr = mysql_fetch_array($r); if (is_null($totpr['tot'])) { $totcreds=0; } else { $totcreds = $totpr['tot']; } } else { $totcreds = 0; } if ($totcreds >0) { //put in the table $qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, progdelmode, progcreditsearned from cpe_track WHERE username = '" . $username . "' AND YEAR(progdatecomplete) = '". $yn ."' ORDER BY progdatecomplete DESC"; //print $qa; $ra = mysql_query($qa); $nra = mysql_num_rows($ra); if ($nra>0) { WHILE ($pry = mysql_fetch_array($ra)) { ?> " type="radio" value="rid" /> Remove   Total Number of CPE Credits on File for = '". date("Y-m-d", strtotime("-1 years")) . "'"; //print $q; $r = mysql_query($q); $nr = mysql_num_rows($r); if ($nr>0) { $totpr = mysql_fetch_array($r); if (is_null($totpr['tot'])) { $totcreds=0; } else { $totcreds = $totpr['tot']; } } else { $totcreds = 0; } if ($totcreds >0) { $qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, progdelmode, progcreditsearned from cpe_track WHERE username = '" . $username . "' AND YEAR(progdatecomplete) = '". date("Y-m-d", strtotime("-1 years"))."' ORDER BY progdatecomplete DESC"; //print $qa; $ra = mysql_query($qa); $nra = mysql_num_rows($ra); if ($nra>0) { WHILE ($pry = mysql_fetch_array($ra)) { ?> " type="radio" value="rid" /> Remove   Total Number of CPE Credits on File for = '". date("Y-m-d", strtotime("-2 years")) . "'"; //print $q; $r = mysql_query($q); $nr = mysql_num_rows($r); if ($nr>0) { $totpr = mysql_fetch_array($r); if (is_null($totpr['tot'])) { $totcreds=0; } else { $totcreds = $totpr['tot']; } } else { $totcreds = 0; } if ($totcreds >0) { $qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, progdelmode, progcreditsearned from cpe_track WHERE username = '" . $username . "' AND YEAR(progdatecomplete) = '". date("Y-m-d", strtotime("-2 years"))."' ORDER BY progdatecomplete DESC"; //print $qa; $ra = mysql_query($qa); $nra = mysql_num_rows($ra); if ($nra>0) { WHILE ($pry = mysql_fetch_array($ra)) { ?> " type="radio" value="rid" /> Remove   Total Number of CPE Credits on File for = '". date("Y-m-d", strtotime("-3 years")) . "'"; //print $q; $r = mysql_query($q); $nr = mysql_num_rows($r); if ($nr>0) { $totpr = mysql_fetch_array($r); if (is_null($totpr['tot'])) { $totcreds=0; } else { $totcreds = $totpr['tot']; } } else { $totcreds = 0; } if ($totcreds >0) { //put in the table $qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, progdelmode, progcreditsearned from cpe_track WHERE username = '" . $username . "' AND YEAR(progdatecomplete) = '". date("Y-m-d", strtotime("-3 years"))."' ORDER BY progdatecomplete DESC"; //print $qa; $ra = mysql_query($qa); $nra = mysql_num_rows($ra); if ($nra>0) { WHILE ($pry = mysql_fetch_array($ra)) { ?> " type="radio" value="rid" /> Remove   Total Number of CPE Credits on File for       My on submit code is as follows: $value) //Big Al's handy work{ if (substr($value, 0, 3)=="rid") { $qz = "DELETE FROM cpe_track WHERE rid = '" . substr($value, 3, 100) . "'"; $rz = mysql_query($qz); }}?>My issue is this, I cannot delete any items from the listing like I want to...Any help or suggestions would be greatly appreciated.."> Issue with my code? - Forums

Forums

Issue with my code?

dogfishent 02 Dec, 2008
I am having some issues with a form that I have put on a site.
I love Chronoforms but cannot seem to make this work.
I have a form that lists a number of items per individual.
I am using Community Builder on this site and have created a separate table for these items.
I have an include file that I use to create the following table


My include is as follows and is showing fine within the form.
<?php
$my = JFactory::getUser();
$username=$my->username;
$yn= date("Y");
//get the year we are in.
$q="SELECT sum(progcreditsearned) as tot from cpe_track 
WHERE username = '" . $username . "' AND 
YEAR(progdatecomplete) <= '". date("Y-m-d") . "' 
AND
YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-3 years")) . "'";
//print $q;
$r = mysql_query($q);
$nr = mysql_num_rows($r);
if ($nr>0) 
{
	$totpr = mysql_fetch_array($r);
	if (is_null($totpr['tot']))
	{
		$totcreds=0;
	}
	else
	{
		$totcreds = $totpr['tot'];
	}
}
else
{
	$totcreds = 0;
}
?>
<table width="560" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3" bgcolor="#CCCCCC"><strong>Total Number of CPE Credits on File for current plus last 3 years</strong></td>
    <td width="10%" bgcolor="#CCCCCC"><strong> </strong></td>
    <td width="15%" bgcolor="#CCCCCC"><strong><?php print $totcreds; ?></strong></td>
  </tr>
</table>
<br><br>
<?php
if ($totcreds>0)
{
?>

<table width="560" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="15%" bgcolor="#CCCCCC"><strong>Date Complete</strong></td>
			<td width="35%" bgcolor="#CCCCCC"><strong>Program</strong></td>
			<td width="25%" bgcolor="#CCCCCC"><strong>Sponsor</strong></td>
			<td width="10%" bgcolor="#CCCCCC"><strong>Mode</strong></td>
			<td width="15%" bgcolor="#CCCCCC"><strong>Credits</strong></td>
		  </tr>
	<?php
	$q="SELECT sum(progcreditsearned) as tot from cpe_track 
	WHERE username = '" . $username . "' AND 
	YEAR(progdatecomplete) <= '". date("Y-m-d") . "' 
	AND
	YEAR(progdatecomplete) >= '". date("Y-m-d") . "'";
	//print $q;
	$r = mysql_query($q);
	$nr = mysql_num_rows($r);
	if ($nr>0) 
	{
		$totpr = mysql_fetch_array($r);
		if (is_null($totpr['tot']))
		{
			$totcreds=0;
		}
		else
		{
			$totcreds = $totpr['tot'];
		}
	}
	else
	{
		$totcreds = 0;
	}
	if ($totcreds >0)
	{
			//put in the table
		$qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, progdelmode, 
		progcreditsearned from cpe_track 
		WHERE username = '" . $username . "' AND 
		YEAR(progdatecomplete) <= '". $yn . "' 
		AND
		YEAR(progdatecomplete) >= '". $yn ."' ORDER BY progdatecomplete DESC";
		//print $qa;
		$ra = mysql_query($qa);
		$nra = mysql_num_rows($ra);
		if ($nra>0)
		{
			WHILE ($pry = mysql_fetch_array($ra))
			{
			?>
			  <tr>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['dte2']; ?></strong></td>
				<td width="35%" bgcolor="#ffffff"><strong><?php print $pry['progtitle']; ?></strong></td>
				<td width="25%" bgcolor="#ffffff"><strong><?php print $pry['progsponsor']; ?></strong></td>
				<td width="10%" bgcolor="#ffffff"><strong><?php print $pry['progdelmode']; ?></strong></td>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['progcreditsearned']; ?>
				  <input name="rid<?php print $pry['rid']; ?>" type="radio" value="rid<?php print $pry['rid']; ?>" />
				  Remove
				</strong></td>
			  </tr>
			<?php
			}
			?>
			  <tr>
				<td width="15%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td colspan="3" bgcolor="#CCCCCC"><strong>Total Number of CPE Credits on File for <?php print $yn; ?></strong></td>
				<td width="15%" bgcolor="#CCCCCC"><?php print $totcreds; ?></td>
			  </tr>
			  <tr>
				<td colspan="5"><strong><hr /></strong></td>
			  </tr>
			<?php
		}
	}

	//one year back
	//calculate the current year.
	//if there are any there, then create the table.
	$q="SELECT sum(progcreditsearned) as tot from cpe_track 
	WHERE username = '" . $username . "' AND 
	YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-1 years")) . "' 
	AND
	YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-1 years")) . "'";
	//print $q;
	$r = mysql_query($q);
	$nr = mysql_num_rows($r);
	if ($nr>0) 
	{
		$totpr = mysql_fetch_array($r);
		if (is_null($totpr['tot']))
		{
			$totcreds=0;
		}
		else
		{
			$totcreds = $totpr['tot'];
		}
	}
	else
	{
		$totcreds = 0;
	}
	if ($totcreds >0)
	{
		$qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, 
		progdelmode, progcreditsearned from cpe_track 
		WHERE username = '" . $username . "' AND 
		YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-1 years")) . "' 
		AND
		YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-1 years"))."' ORDER BY progdatecomplete DESC";
		//print $qa;
		$ra = mysql_query($qa);
		$nra = mysql_num_rows($ra);
		if ($nra>0)
		{
			WHILE ($pry = mysql_fetch_array($ra))
			{
			?>
			  <tr>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['dte2']; ?></strong></td>
				<td width="35%" bgcolor="#ffffff"><strong><?php print $pry['progtitle']; ?></strong></td>
				<td width="25%" bgcolor="#ffffff"><strong><?php print $pry['progsponsor']; ?></strong></td>
				<td width="10%" bgcolor="#ffffff"><strong><?php print $pry['progdelmode']; ?></strong></td>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['progcreditsearned']; ?>
				  <input name="rid<?php print $pry['rid']; ?>" type="radio" value="rid<?php print $pry['rid']; ?>" />
				  Remove</strong></td>
			  </tr>
			<?php
			}
			?>
			  <tr>
				<td width="15%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td colspan="3" bgcolor="#CCCCCC"><strong>Total Number of CPE Credits on File for <?php print $yn; ?></strong></td>
				<td width="15%" bgcolor="#CCCCCC"><?php print $totcreds; ?></td>
			  </tr>
			  <tr>
				<td colspan="5"><strong><hr /></strong></td>
			  </tr>
			<?php
		}
		?>
		<?php
	}
	//two year back
	//calculate the current year.
	//if there are any there, then create the table.
	$q="SELECT sum(progcreditsearned) as tot from cpe_track 
	WHERE username = '" . $username . "' AND 
	YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-2 years")) . "' 
	AND
	YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-2 years")) . "'";
	//print $q;
	$r = mysql_query($q);
	$nr = mysql_num_rows($r);
	if ($nr>0) 
	{
		$totpr = mysql_fetch_array($r);
		if (is_null($totpr['tot']))
		{
			$totcreds=0;
		}
		else
		{
			$totcreds = $totpr['tot'];
		}
	}
	else
	{
		$totcreds = 0;
	}
	if ($totcreds >0)
	{
		$qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, 
		progdelmode, progcreditsearned from cpe_track 
		WHERE username = '" . $username . "' AND 
		YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-2 years")) . "' 
		AND
		YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-2 years"))."' ORDER BY progdatecomplete DESC";
		//print $qa;
		$ra = mysql_query($qa);
		$nra = mysql_num_rows($ra);
		if ($nra>0)
		{
			WHILE ($pry = mysql_fetch_array($ra))
			{
			?>
			  <tr>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['dte2']; ?></strong></td>
				<td width="35%" bgcolor="#ffffff"><strong><?php print $pry['progtitle']; ?></strong></td>
				<td width="25%" bgcolor="#ffffff"><strong><?php print $pry['progsponsor']; ?></strong></td>
				<td width="10%" bgcolor="#ffffff"><strong><?php print $pry['progdelmode']; ?></strong></td>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['progcreditsearned']; ?>
				  <input name="rid<?php print $pry['rid']; ?>" type="radio" value="rid<?php print $pry['rid']; ?>" />
				  Remove</strong></td>
			  </tr>
			<?php
			}
			?>
			  <tr>
				<td width="15%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td colspan="3" bgcolor="#CCCCCC"><strong>Total Number of CPE Credits on File for <?php print $yn-2; ?></strong></td>
				<td width="15%" bgcolor="#CCCCCC"><?php print $totcreds; ?></td>
			  </tr>
			  <tr>
				<td colspan="5"><strong><hr /></strong></td>
			  </tr>
			<?php
		}
	}
	
	//three year back
	//calculate the current year.
	//if there are any there, then create the table.
	$q="SELECT sum(progcreditsearned) as tot from cpe_track 
	WHERE username = '" . $username . "' AND 
	YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-3 years")) . "' 
	AND
	YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-3 years")) . "'";
	//print $q;
	$r = mysql_query($q);
	$nr = mysql_num_rows($r);
	if ($nr>0) 
	{
		$totpr = mysql_fetch_array($r);
		if (is_null($totpr['tot']))
		{
			$totcreds=0;
		}
		else
		{
			$totcreds = $totpr['tot'];
		}
	}
	else
	{
		$totcreds = 0;
	}
	if ($totcreds >0)
	{
		//put in the table
		$qa = "SELECT rid, date_format(progdatecomplete, '%b %D, %Y') as dte2, progtitle, progsponsor, 
		progdelmode, progcreditsearned from cpe_track 
		WHERE username = '" . $username . "' AND 
		YEAR(progdatecomplete) <= '". date("Y-m-d", strtotime("-3 years")) . "' 
		AND
		YEAR(progdatecomplete) >= '". date("Y-m-d", strtotime("-3 years"))."' ORDER BY progdatecomplete DESC";
		//print $qa;
		$ra = mysql_query($qa);
		$nra = mysql_num_rows($ra);
		if ($nra>0)
		{
			WHILE ($pry = mysql_fetch_array($ra))
			{
			?>
			  <tr>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['dte2']; ?></strong></td>
				<td width="35%" bgcolor="#ffffff"><strong><?php print $pry['progtitle']; ?></strong></td>
				<td width="25%" bgcolor="#ffffff"><strong><?php print $pry['progsponsor']; ?></strong></td>
				<td width="10%" bgcolor="#ffffff"><strong><?php print $pry['progdelmode']; ?></strong></td>
				<td width="15%" bgcolor="#ffffff"><strong><?php print $pry['progcreditsearned']; ?>
				  <input name="rid<?php print $pry['rid']; ?>" type="radio" value="rid<?php print $pry['rid']; ?>" />
				  Remove</strong></td>
			  </tr>
			<?php
			}
			?>
			  <tr>
				<td width="15%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td colspan="3" bgcolor="#CCCCCC"><strong>Total Number of CPE Credits on File for <?php print $yn-3; ?></strong></td>
				<td width="15%" bgcolor="#CCCCCC"><?php print $totcreds; ?></td>
			  </tr>
			  <tr>
				<td colspan="5"><strong><hr /></strong></td>
			  </tr>
			<?php
		}
	}
	?>
			  <tr>
				<td width="15%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td width="35%" bgcolor="#CCCCCC"><strong> </strong></td>
				<td colspan="2" bgcolor="#CCCCCC"><strong> </strong></td>
				<td width="15%" bgcolor="#CCCCCC"><input type="submit" name="Submit" value="Remove Now" /></td>
			  </tr>
</table>

	<?php
}
?>
My on submit code is as follows:
<?php
foreach($_POST as $name => $value) //Big Al's handy work
{   
	if (substr($value, 0, 3)=="rid")
    {
			$qz = "DELETE FROM cpe_track WHERE rid = '" . substr($value, 3, 100) . "'";
			$rz = mysql_query($qz);			   
	}
}
?>
My issue is this, I cannot delete any items from the listing like I want to...
Any help or suggestions would be greatly appreciated..
GreyHead 02 Dec, 2008
Hi dogfishent,

You have around 300 lines of code here and it's not particulary easy to read. I dont' see anything wrong with the chunk that I looked through.

I suggest that you add in some debug code to see what sql is being generated and from that you can usually work out what's going wrong.

Bob
This topic is locked and no more replies can be posted.