PHP Help
Results 1 to 4 of 4

Thread: PHP Help

  1. #1
    Banned
    Join Date
    Apr 2003
    Posts
    51

    PHP Help

    Ok, well this is kinda complicated, but hopefully i can explain it right...

    I have a page called "edit.php". Inside edit.php it'll have a submit button which will go to "page.php?id=edit.php?function=preview". Inside page.php, they'll be this coding...

    PHP Code:
    <?php
    $data 
    'data.html';
    if(
    $id == "edit.php?function=preview") { $data "$id"; }
    ?>

    ...

    <?php include ("$data"); ?>
    So, if id equals "edit.php?function=preview", then whatever will show up in edit.php when you do ?function=preview should be what's in edit.php....

    PHP Code:
    if ($function == "preview")
    {
        
    $i=0;
        while (
    $i <= count($template))
        {
            
    $cn "newcontent"."$i";
            
    $newcontent[$i]  = $_POST["$cn"];
            
    $i++;        
        }
        
        
    $i=0;
        
    $string=$mid.$table1.$newurl[$i].$table2.$newname[$i].$table3.$newcontent[$i].$table4;
        
    $i++;

        while (
    $i count($template))
        {
            
    $stringy $mid.$table1.$newurl[$i].$table2.$newname[$i].$table3.$newcontent[$i].$table4;
            
    $string $string $stringy
            
    $i++;
        }

        print 
    "$string";
        exit();

    which will be placed before all the coding. Now, i've done where the form action is to another page, and page.php includes it sucessfully, but i'm trying to cut down on the amount of pages, so i tried query strings. The error i get is this...


    Warning: main(edit.php?function=preview): failed to open stream: No such file or directory in /home/virtual/site95/fst/var/www/html/cms/page.php on line 99

    Warning: main(): Failed opening 'edit.php?function=preview' for inclusion (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site95/fst/var/www/html/cms/page.php on line 99
    The error is pointing to the line that has "<?php include ("$data"); ?> ". I'm really not sure what's up, can someone help?

  2. #2
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    You can't include a file in PHP and add a query string to it.

    Examples:

    include('page.php'); // works fine
    include('page.php?edit=preview&finished=true'); // will NOT work

    You'd be better off either redirecting to the page or submitting a form (both methods will work with a query string).
    Paul Waring - Web site design and development.

  3. #3
    look for deltarra. im pretty sure that he uses some advanced php. sorry i cant l-l3LP personally...

  4. #4
    Webius Designerous Indiginous
    Join Date
    Mar 2002
    Location
    South Florida
    Posts
    1,123
    I don't know if you figured this out yet or not, but what I would do is this.

    Instead of doing an include for the function, I would make the include a function.


    Code:
    function when_id_is_for_preview()
    
    {
    
    if ($function == "preview")
    {
        $i=0;
        while ($i <= count($template))
        {
            $cn = "newcontent"."$i";
            $newcontent[$i]  = $_POST["$cn"];
            $i++;        
        }
        
        $i=0;
        $string=$mid.$table1.$newurl[$i].$table2.$newname[$i].$table3.$newcontent[$i].$table4;
        $i++;
    
        while ($i < count($template))
        {
            $stringy = $mid.$table1.$newurl[$i].$table2.$newname[$i].$table3.$newcontent[$i].$table4;
            $string = $string . $stringy; 
            $i++;
        }
    
        print "$string";
        exit();
    }
    
    }

    Put that into a common include or a functions include, and call it instead of doing an include.

    So...


    Code:
    <?php
    $data = 'data.html';
    if($id == "edit.php?function=preview") 
    { 
    
    when_id_is_for_preview();
     }
    ?>
    
    ...
    
    <?php include ("$data"); ?>

Posting Permissions

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