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.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2012
    Location
    Edinburgh
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    An error in my PHP

    Hi, I'm getting this error when I press an action button on my page and I'm not sure on how to solve it



    This is the code from that page:
    PHP Code:
    <?php
    require_once "../include/config.php";
    require_once 
    "../include/ShortUrl.php";

    if (
    $_SERVER["REQUEST_METHOD"] != "POST" || empty($_POST["url"])) {
        
    header("Location: shorten.html");
        exit;


    try {
        
    $pdo = new PDO(DB_PDODRIVER ":host=" DB_HOST ";dbname=" DB_DATABASE,
            
    DB_USERNAMEDB_PASSWORD);
    }
    catch (
    PDOException $e) {
        
    header("Location: error.html");
        exit;
    }

    $shortUrl = new ShortUrl($pdo);
    try {
        
    $code $shortUrl->urlToShortCode($_POST["url"]);
    }
    catch (
    Exception $e) {
        
    header("Location: error.html");
        exit;
    }
    $url SHORTURL_PREFIX $code;

    echo <<<ENDHTML
    <html>
     <head>
      <title>URL Shortener</title>
     </head>
     <body>
      <p><strong>Short URL:</strong> <a href="$url">$url</a></p>
     </body>
    </html>
    ENDHTML;

  • #2
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    It means the file path you have written for that require_once statement is wrong.

    Because you are calling that file within your submit.php script, you need to make your file paths relative to the submit.php file.

    Kind regards,

    Lc.

  • #3
    New Coder
    Join Date
    Oct 2012
    Location
    Edinburgh
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Got it. Thanks
    Last edited by tarasmuz; 02-10-2013 at 12:15 PM. Reason: Got it

  • #4
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    How are you getting on with it?

    Just got back online today so let us know if you sorted it and if not, give us a description of how you have your structure set up and we may be able to give you the correct code in order for your code to work.

    Kind regards,

    Lc.


  •  

    Posting Permissions

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