Please take a look at my code!!! I beg you help!!

Discussion in 'PHP' started by DeeDeee, Sep 13, 2007.

  1. #1
    First off, hello DigitalPoint Community!

    Now, down to business. Ok, so I managed to create my own site now. The problem is, for example, if a customer buys something, he receives a tracking number.
    Then he can insert the tracking number to see the status of his transaction.

    What I want to do is the following. I want when he press track, even if he didn't enter nothing, or a wrong track number, to avoid the display of the 404 page not found. I would like to show, when generally wrong track number, a similar page like... error, the tracking number is wrong or something like this.

    Do you think guys you can help? Because I create the tracking numbers with dreamweaver, and they are .html

    Do I need a php script or something like this? Please shed some light please, I m totally lost and I don't like this with a blank page

    What I have is this

    <script language="JavaScript">function PasswordLogin()
    { document.location.href = document.formlogin.trackingnr.value + ".html";
    return false;
    }
    function CheckEnter(event)
    {
    var NS4 = (document.layers) ? true : false;
    var code = 0;
    if (NS4)
    code = event.which;
    else
    code = event.keyCode;
    if (code==13)
    { PasswordLogin();
    event.returnValue = false;
    }
    }</script><br>
    
    
    ////then here some htlm and then/////
    
    
    <input name="trackingnr" id="trackingnr" onkeypress="CheckEnter(event)" size="29" type="text"> <input name="button" onclick="PasswordLogin()" value="Lookup" type="button">
    Code (markup):

    So I would like, something like, if false, to return a page with a customize error or something....

    It's not difficult, but I couldn't find what I want, because simply I don't know what is called....

    So I am uploading the traking number myself, like FFFGS23.html
    and if the customer types it wrong, or simply press submit without filling anything in the space, it comes the 404 Error. AND I DON"T want that to happen.

    I detalied it, hope I can get some help tho and I don't know what suits me better javascript or php here... :eek:
     
    DeeDeee, Sep 13, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Problem solved here.

    http://www.programmingtalk.com/showthread.php?p=129664

    EDIT:

    Always PHP, you could do something like:
    
    <?php
    
    $filename = strtoupper(basename($_POST['trackingnr'])) . '.html';
    
    if (file_exists($filename))
    {
        header('Location: ' . $filename);
        exit();
    }
    else
    {
        echo 'Invalid tracking number.';
    }
    
    ?>
    
    PHP:
     
    nico_swd, Sep 13, 2007 IP
  3. DeeDeee

    DeeDeee Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks again Nico. I'm working on it, hope it will solve. Btw yo soy de Alicante! :p

    Just trying to understand why it gives me the error when the GOOD tracking number is inserted, and not when a bad one.
     
    DeeDeee, Sep 13, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I replied to your thread on PT.

    Hehe, yo soy de Peñiscola. No estas muy lejos. :p
     
    nico_swd, Sep 13, 2007 IP
  5. DeeDeee

    DeeDeee Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Problem solved, Thread closed. For me this code is priceless Nico! Thank you again! :)

    Profoundly indebt!
     
    DeeDeee, Sep 13, 2007 IP