Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Member #
    6698
    This is a form of error handling. I can't seem to get it to work.

    PHP Code:
    <?php
       $path 
    =  $_SERVER['PHP_SELF'];
       
    $path_parts pathinfo($path);
       
    $string $path_parts["basename"];
       
    $exclude ".jpg.php";

       
    $path substr("$string",0,strpos($string,$exclude));
       echo 
    "Image: $path ";

    if(isset(
    $_POST['submit'])) {

    $ip $HTTP_SERVER_VARS["REMOTE_ADDR"];

    $query "SELECT last_ip FROM photographs WHERE name=$path";

    if (
    $query $ip) {
    header("Location: error.php");
    }


    $link mysql_connect('localhost''andrew''1357908642');
    if (!
    $link) {
       die(
    'Not connected : ' mysql_error());
    }

    $db_selected mysql_select_db('andrew_site'$link);

    $message stripslashes(trim($message));
    $message nl2br($message);
    $message htmlentities($message);

    $query "INSERT INTO photos (ip, comment, photo)
    VALUES ('
    $ip', '$message', '$path')";
    mysql_query($query);

    mysql_close();

    echo 
    "Thanks $name your comment has been added";
    }
       
    ?>
    You can see the part that is wrong

    PHP Code:
    if ($query $ip) {
    header("Location: error.php");

    Headers can't be sent after submit has been made.. How can I redirect if it's wrong?

  2.  

  3. #2
    Member Victor's Avatar
    Join Date
    Jul 2004
    Posts
    54
    Member #
    6614
    First: if ($query = $ip) should be if ($query == $ip)
    Second: redirection cant be done after you echoing something in the page. Get rid of echo before header and it will work

  4. #3
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Member #
    6698
    I would prefer to keep that echo, so I can generate everyone the page as dynamic as possible is there any other way?

  5. #4
    Member Victor's Avatar
    Join Date
    Jul 2004
    Posts
    54
    Member #
    6614
    header will not work if the page is not complete empty.
    And what are you trying to get here?
    if ($query = $ip) {
    This is wrong definately.

  6. #5
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Member #
    6698
    Yeah that was fixed. (Was an error I made in typing that in) and header worked fine once I moved the header above the echo opposed to removing it o-O

  7. #6
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    If you include ob_start(); at the beginning, you can use the header function anywhere in the script.

    The ob_start() function turns on the output buffer, which holds back all output, except headers uintil the end of the script.

    Take a look here: http://uk.php.net/manual/en/ref.outcontrol.php


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com