Titan85
02-18-2007, 10:34 PM
Hello, I am having an issue getting my script to include a file if it finds a certain action specified ($_GET['act'] == "whatever"). I have used this many times before but for some reason this one is not working and I can't figure out why. I am sure it is something stupid, but just can't find it. Here is the code:
<?php
// If no action is selected
if(!$_GET['act']) {
// Get coupons
$sql = "SELECT * FROM `coupons` ORDER BY id DESC";
$qry = mysql_query($sql) or die ('Error Getting Coupons! <br />' .mysql_error());
$count = mysql_num_rows($qry);
// If no results
if($count < 1) {
echo '
There are no coupons at this time.
';
}
// Get words
if($count == 1) {
$are = "is";
$coupon = "coupon";
} else {
$are = "are";
$coupon = "coupons";
}
// If there are results
if($count >= 1) {
// Tell how many coupons
echo "
There $are <i>$count</i> current $coupon.
";
// Row colors
$counter = 1;
$color = "#EEEEEE";
// Start Table
echo '
<!-- Coupon Management Table -->
<form method="post" action="">
<table width="100%">
<tr>
<td class="table"><b>ID</b></td>
<td class="table"><b>Name</b></td>
<td class="table"><b>Date</b></td>
<td class="table"><b>Delete</b></td>
<td class="table"><b>Edit</b></td>
</tr>';
// For each coupon found
while($c = mysql_fetch_array($qry)) {
echo '
<tr style="background-color: '.$color.'">
<td class="table">'.$c['id'].'</td>
<td class="table"><a href="?act=view&id='.$c['id'].'">'.$c['title'].'</a></td>
<td class="table">'.$c['date'].'</td>
<td class="table"><input type="checkbox" name="checkbox[]" value="'.$c['id'].'" /></td>
<td class="table"><a href="?act=edit&id='.$c['id'].'"><img src="../images/edit.png" border="0" alt="" /></a></td>
</tr>';
// Get row color
++$counter;
if($color == "#EEEEEE") {
$color = "#CCCCCC";
} else {
$color = "#EEEEEE";
}
}
// End table/form and echo submit button
echo '
<tr>
<td colspan="5"><div align="right"><input type="submit" name="delete" value="Delete Selected" /></div></td>
</tr>
</table>
</form>
<!-- /Coupon Management Table -->';
}
}
// If delete was hit
if($delete) {
for($i=0;$i<$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM `coupons` WHERE id = '$del_id'";
$result1 = mysql_query($sql) or die ('Error Deleting Coupons! <br />' .mysql_error());
}
}
// If delete worked
if($result1) {
echo '
<meta http-equiv="refresh" content="2;URL=index.php" />
';
echo 'The selected coupons have been deleted.
';
}
// If edit was hit
if($_GET['act'] == "edit") {
require('edit.php');
}
// If view was hit
if($_GET['act'] == "view") {
require('view.php');
}
?> Even if I delete the file I say to include, I do not get the "does not exist" error that I should, so it is definitely just not including it. The url does indeed have index.php?act=whatever in it. Hope someone sees the problem, thanks.
<?php
// If no action is selected
if(!$_GET['act']) {
// Get coupons
$sql = "SELECT * FROM `coupons` ORDER BY id DESC";
$qry = mysql_query($sql) or die ('Error Getting Coupons! <br />' .mysql_error());
$count = mysql_num_rows($qry);
// If no results
if($count < 1) {
echo '
There are no coupons at this time.
';
}
// Get words
if($count == 1) {
$are = "is";
$coupon = "coupon";
} else {
$are = "are";
$coupon = "coupons";
}
// If there are results
if($count >= 1) {
// Tell how many coupons
echo "
There $are <i>$count</i> current $coupon.
";
// Row colors
$counter = 1;
$color = "#EEEEEE";
// Start Table
echo '
<!-- Coupon Management Table -->
<form method="post" action="">
<table width="100%">
<tr>
<td class="table"><b>ID</b></td>
<td class="table"><b>Name</b></td>
<td class="table"><b>Date</b></td>
<td class="table"><b>Delete</b></td>
<td class="table"><b>Edit</b></td>
</tr>';
// For each coupon found
while($c = mysql_fetch_array($qry)) {
echo '
<tr style="background-color: '.$color.'">
<td class="table">'.$c['id'].'</td>
<td class="table"><a href="?act=view&id='.$c['id'].'">'.$c['title'].'</a></td>
<td class="table">'.$c['date'].'</td>
<td class="table"><input type="checkbox" name="checkbox[]" value="'.$c['id'].'" /></td>
<td class="table"><a href="?act=edit&id='.$c['id'].'"><img src="../images/edit.png" border="0" alt="" /></a></td>
</tr>';
// Get row color
++$counter;
if($color == "#EEEEEE") {
$color = "#CCCCCC";
} else {
$color = "#EEEEEE";
}
}
// End table/form and echo submit button
echo '
<tr>
<td colspan="5"><div align="right"><input type="submit" name="delete" value="Delete Selected" /></div></td>
</tr>
</table>
</form>
<!-- /Coupon Management Table -->';
}
}
// If delete was hit
if($delete) {
for($i=0;$i<$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM `coupons` WHERE id = '$del_id'";
$result1 = mysql_query($sql) or die ('Error Deleting Coupons! <br />' .mysql_error());
}
}
// If delete worked
if($result1) {
echo '
<meta http-equiv="refresh" content="2;URL=index.php" />
';
echo 'The selected coupons have been deleted.
';
}
// If edit was hit
if($_GET['act'] == "edit") {
require('edit.php');
}
// If view was hit
if($_GET['act'] == "view") {
require('view.php');
}
?> Even if I delete the file I say to include, I do not get the "does not exist" error that I should, so it is definitely just not including it. The url does indeed have index.php?act=whatever in it. Hope someone sees the problem, thanks.