Log in

View Full Version : Include Error



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.

mburt
02-18-2007, 10:40 PM
Try using include "edit.php" and include "view.php" instead, whereas if you use require it may produce a fatal warning error.

Titan85
02-18-2007, 11:26 PM
Try using include "edit.php" and include "view.php" instead, whereas if you use require it may produce a fatal warning error.Well, it has worked on about 10 other scripts I have made without an issue, but for some reason this one is causing problems

thetestingsite
02-19-2007, 12:39 AM
The code works for me (in the aspect of the include/require section). If I go to test.php?act=edit, it gives me this error:



Fatal error: main() [function.require]: Failed opening required 'edit.php' (include_path='.;C:\php5\pear') in J:\****\****\test.php on line 105


Same with act=view. Can you post a link to your page (or pm it) so that we can take a look to see what's going on with it.

Titan85
02-19-2007, 01:06 AM
The code works for me (in the aspect of the include/require section). If I go to test.php?act=edit, it gives me this error:



Same with act=view. Can you post a link to your page (or pm it) so that we can take a look to see what's going on with it.The script is password protected and for some really odd reason I can't get it to add another user. I am going to rewrite the code and see if it works, if not, I will give you the login info ;)

thetestingsite
02-19-2007, 01:21 AM
Let me know what happens and if you need any more help.

Titan85
02-19-2007, 01:35 AM
Let me know what happens and if you need any more help.I redid it and its no good. I even used the code from a script that is working, but yet it won't work. I still can't seem to get another login to work. I have to take a step back for a bit and come back fresh.

thetestingsite
02-19-2007, 01:37 AM
Have you just tried to make a new page with just an include/require in it just to see if it is something in the script or something on the server?

Titan85
02-20-2007, 05:16 PM
I found the problem, it was that my link to include the edit page was "index.php?act=edit&id=id", but I had the "if($_GET['act'] == "edit")" code on my manage.php page. Simple error that messed everything up. Thanks for all the help testingsite, I really appreciate it