Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts

    Cool A redirect problem with PHP5?

    Ok I have this script that works perfectly on my other host (PHP4) but after I switched to another host (PHP5) my page seems to stop redirecting.

    Here is my code:
    PHP Code:
    <?php
    mysql_connect
    ("localhost""******""*******") or die(mysql_error());
    mysql_select_db("*****") or die(mysql_error());
    $customerid="1"//it's part of a system but now it's just static
    $cart="1";  //it's part of a system but now it's just static
    if (!empty($_GET['action'])){ $action $_GET['action']; }

    if (
    $action=="notes"){
    if (!empty(
    $_POST['cart'])){ $cart $_POST['cart']; } else { $cart="1"; }
    if (!empty(
    $_POST['jobname'])){ $jobname $_POST['jobname']; }
    if (!empty(
    $_POST['add'])){ $add $_POST['add']; }
    if (!empty(
    $_POST['city'])){ $city $_POST['city']; }
    if (!empty(
    $_POST['state'])){ $state $_POST['state']; }
    if (!empty(
    $_POST['zip'])){ $zip $_POST['zip']; }
    if (!empty(
    $_POST['tel'])){ $tel $_POST['tel']; }
    if (!empty(
    $_POST['email'])){ $email $_POST['email']; }
    if (!empty(
    $_POST['status'])){ $status $_POST['status']; }
    if (!empty(
    $_POST['memo'])){ $memo $_POST['memo']; }

    $query "SELECT * FROM notes WHERE CUSTOMERID = '".$customerid."' AND CART = '".$cart."' AND `ORDERID`='0'";
    $sql mysql_query($query) or die(mysql_error());
    $count mysql_num_rows($sql);

    if (
    $count == 0) {
    $query "INSERT INTO `notes` ( `CUSTOMERID` , `CART` , `JOBNAME` , `TEL` , `ADDRESS` , `CITY`, `STATE`, `ZIP`, `EMAIL`, `STATUS`, `MEMO`) VALUES ('".$customerid."', '".$cart."', '".$jobname."', '".$tel."', '".$add."', '".$city."', '".$state."', '".$zip."', '".$email."', '".$status."', '".$memo."')";
    $sql mysql_query($query) or die(mysql_error());
    }
    else {
    $query "UPDATE `notes` SET `JOBNAME` = '".$jobname."',`TEL` = '".$tel."', `ADDRESS` = '".$add."', `CITY` = '".$city."', `STATE` = '".$state."', `ZIP` = '".$zip."', `EMAIL` = '".$email."', `STATUS` = '".$status."', `MEMO` = '".$memo."'  WHERE `CUSTOMERID` = '".$customerid."' AND `CART` = '".$cart."' AND `ORDERID`='0'";
    $sql mysql_query($query) or die(mysql_error());
    }

    header"Location: index.html" ) ;

    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title></title>
    </head>

    <body>
    <form action="notes.php?action=notes" method="post">
    <input name="cart" type="hidden" value="<?php echo $cart?>" />
    <?php
    $query 
    "SELECT * FROM notes WHERE CUSTOMERID = '".$customerid."' AND CART = '".$cart."' AND ORDERID = '0' LIMIT 1";
    $sql mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_row($sql)) {
    $jobname $row[3];
    $tel $row[4];
    $add $row[5];
    $city $row[6];
    $state $row[7];
    $zip $row[8];
    $email $row[9];
    $status $row[10];
    $memo $row[11];
    }
    ?>
    <table style="text-align:left">
    <tr>
    <td colspan="2">Jobname:<br /><input name="jobname" type="text" size="40" value="<?php echo $jobname;?>" /></td>
    <td colspan="1">Phone:<br /> <input name="tel" type="text" size="25" value="<?php echo $tel;?>" /></td>
    </tr><tr>
    <td colspan="3">Address:<br /> <input name="add" type="text" size="70" value="<?php echo $add;?>" /></td>
    </tr><tr>
    <td>City: <br /><input name="city" type="text" size="30" value="<?php echo $city;?>" /></td>
    <td>State: <br /><input name="state" type="text" size="10" value="<?php echo $state;?>" /></td>
    <td>Zip: <br /><input name="zip" type="text" size="20" value="<?php echo $zip;?>" /></td>
    </tr><tr>
    <td colspan="2">Email: <br /><input name="email" type="text" size="40" value="<?php echo $email;?>" /></td>
    <td colspan="1">Status: <br />
    <select name="status">
        <option value="Estimated" <?php if(!empty($status) && $status=="Estimated"){echo "selected";} ?>>Estimated</option>
        <option value="Pending" <?php if(!empty($status) && $status=="Pending"){echo "selected";} ?>>Pending</option>
        <option value="Paid" <?php if(!empty($status) && $status=="Paid"){echo "selected";} ?>>Paid</option>
    </select>
    </td>
    </tr><tr>
    <td colspan="3">Memo: <br /><textarea name="memo" cols="20" rows="10"><?php echo $memo;?></textarea></td>
    </tr><tr>
    <td></td>
    <td ><input name="cart<?php echo $cart?>" type="submit" value="Update Job Info" /></td>
    <td></td>
    </tr>
    </table>
    </form>
    </body>

    </html>
    The page shows up as blank after I press submit and it stays at the same page!
    Is header not allowed to be inside an if statement in PHP5?
    If a create a very simple page it redirects:
    PHP Code:
    <?php
    header
    ('Location: index.php' );
    ?>
    Thank you!
    Last edited by sea4me; 03-04-2009 at 05:10 AM. Reason: it's not resolved yet

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    add this on the top of your page and see what's happend:
    PHP Code:
    ini_set('display_errors',1);
    error_reporting(E_ALL); 
    Edit: and check the { and } pair to match

    best regards
    Last edited by oesxyl; 03-03-2009 at 05:45 AM.

  • #3
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Just a random idea since you don't seem to be using any deprecated functions try removing the white space around your header function.
    Before:
    PHP Code:
    header"Location: index.html" ) ; 
    After:
    PHP Code:
    header("Location: index.html"); 

  • #4
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    It works now after I removed the whitespaces!!!

    Thank you!

  • #5
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    I guess random ideas are very helpful

  • #6
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    WOW fixed in less than an hour!

    that's a record!

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    Also if you cant find the white space or simply cant be bothered to look i ALWAYS stick
    PHP Code:
    exit; 
    straight underneath the header function.

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Off topic:
    PHP Code:
    if ($action=="notes"){
    if (!empty(
    $_POST['cart'])){ $cart $_POST['cart']; } else { $cart="1"; }
    if (!empty(
    $_POST['jobname'])){ $jobname $_POST['jobname']; }
    if (!empty(
    $_POST['add'])){ $add $_POST['add']; }
    if (!empty(
    $_POST['city'])){ $city $_POST['city']; }
    if (!empty(
    $_POST['state'])){ $state $_POST['state']; }
    if (!empty(
    $_POST['zip'])){ $zip $_POST['zip']; }
    if (!empty(
    $_POST['tel'])){ $tel $_POST['tel']; }
    if (!empty(
    $_POST['email'])){ $email $_POST['email']; }
    if (!empty(
    $_POST['status'])){ $status $_POST['status']; }
    if (!empty(
    $_POST['memo'])){ $memo $_POST['memo']; } 
    is equivalent to

    PHP Code:
    foreach($_POST as $key=>$value){
    if(!empty(
    $value))
      $
    $key=$value;

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Back on topic. I'm surprised you haven't been a victim of mysql injection yet. You do nothing in your code to prevent mysql injection. I suggest you read this: http://www.tizag.com/mysqlTutorial/m...-injection.php
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    I do have codes to prevent mySQL injection, it's just not posted to save room

  • #11
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Ok the problem is back on my other page....

    It shows up as blank....

    PHP Code:
    <?php if (LoggedIn() == false) { header("Location: index.php?page=my"); exit(); } ?>
    anything wrong with this code? It worked fine in my last host (PHP4)

  • #12
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Did you follow oesxyl's post above?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #13
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Nevermind may last problem, it was solved by adding this to the top:

    PHP Code:
    <?php
    ob_start
    ();
    ?>
    output_buffering was turned off on the server, putting this code at the start of the page fixed it

  • #14
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Quote Originally Posted by abduraooft View Post
    Off topic: is equivalent to

    PHP Code:
    foreach($_POST as $key=>$value){
    if(!empty(
    $value))
      $
    $key=$value;

    Just at a curiosity, would this affect the response and processing time?

  • #15
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by sea4me View Post
    Just at a curiosity, would this affect the response and processing time?
    Of course, system would take some extra resource/time to process a loop/function. After all, machine code is always faster than any other formats
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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