Results 1 to 9 of 9

Thread: Include Error

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Include Error

    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 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.
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Try using include "edit.php" and include "view.php" instead, whereas if you use require it may produce a fatal warning error.
    - Mike

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt View Post
    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
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    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
    Thanks DD, you saved me countless times

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Let me know what happens and if you need any more help.

  7. #7
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    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.
    Thanks DD, you saved me countless times

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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?

  9. #9
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    Thanks DD, you saved me countless times

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •