SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: DB issues...

  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DB issues...

    Hello,

    Could someone tell me what's wrong with this page? (It keeps giving DB errors...)
    PHP Code:
    <?php
    $type
    =$_REQUEST["type"];
    $title=$_REQUEST["title"];
    $from=$_REQUEST["from"];
    if(
    $from=="writings"){echo("
    <html>
    <head>
    <title>CyberCory.net: "
    .$title."</title>
    <link rel=\"stylesheet\" href=""\"[url=http://www.cybercory.net/css-bin/styling.css]http://www.cybercory.net/css-bin/styling.css\[/url]" 
    />
    </
    head>
    <
    body>
    <
    div id=\"page\">
    <div id=\"header_image\"><img src=""\"[url=http://www.cybercory.net/jpg-bin/header.jpg]http://www.cybercory.net/jpg-bin/header.jpg\[/url]" 
    /></div>
    <
    div id=\"header_text\">".$title."</div>
    <div id=\"top_info\"><a id=\"link\" href=""\"[url=http://www.cybercory.net/\]http://www.cybercory.net/\">CyberCory.net</a[/url]>: <a id=\"link\" 
    href=""\"[url=http://www.cybercory.net/php-bin/writings.php\]http://www.cybercory.net/php-bin/writings.php\">Writings</a[/url]>: "
    .$title."</div>
    <div id=\"sidebar\">
    <img src=""\"[url=http://www.cybercory.net/jpg-bin/sidebar.jpg]http://www.cybercory.net/jpg-bin/sidebar.jpg\[/url]" 
    />
    </
    div>
    <
    div id=\"navigation_bar\">
    <?php include(\"[url=http://www.cybercory.net/php-bin/includes/navigation_bar.php]http://www.cybercory.net/php-bin/includes/navigation_bar.php\[/url]"
    );?>
    </div>
    <div id=\"content_frame\">
    <?php
    [email=$db_server_connect=@mysql_connect(\]$db_server_connect=@mysql_connect(\"localhost\",\"cybercor_root\[/email]") or die(\"
    <div id=\"bold\">
    I'm sorry, but the database server appears to be offline. Please try again later.
    </div>
    \");
    [email=
    $db_connect=@mysql_select_db(\]$db_connect=@mysql_select_db(\"cybercor_writings\[/email]") or die(\"
    <div id=\"bold\">
    I'm sorry, but the writings database could not be located. Please try again later.
    </div>
    \");
    [email=
    $writings=@mysql_query(\]$writings=@mysql_query(\"select[/email] content from writings where title=$title and type=$type\") or die(\"
    <div id=\"bold\">
    I'm sorry, but the writing you selected ("
    .$title.") could not be located within the database. Please try again later.
    </div>
    \");
    echo(\""
    .$content."\");
    ?>
    <?php include(\"[url=http://www.cybercory.net/php-bin/includes/footer.php]http://www.cybercory.net/php-bin/includes/footer.php\[/url]"
    );?>
    </div>
    </div>
    </body>
    </html>
    ");}
    ?>
    Thanks,
    compuwhiz7

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What database errors?

    Have you put mysql_error() in the die statement for a more detailed error? Have you tried echoing the query?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, oddly enough the DB errors don't actually appear, but neither does the result of the query.

  4. #4
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    With that much HTML, your tend to miss some slashes. IE

    <div id="page\">
    <div id="header_text\">".$title."</div>

    There may be more.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  5. #5
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "@" before the mysql functions suppresses mysql errors. Remove it and you will get some info if queries or connections are failing. Better yet, use mysql_error on every "or die".

    The New Guy is correct in that it looks like your code could use some separation of logic and presentation. It actually isn't the best coding practice in PHP to use variables inside double quotes and the use of mysql functions inside the quotes is confusing the heck out of me... I'm having trouble deciphering where you are going with this.

    One thing I can see... there isn't any mysql_fetch_array or another mysql function to actually retrieve data.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    The "@" before the mysql functions suppresses mysql errors. Remove it and you will get some info if queries or connections are failing. Better yet, use mysql_error on every "or die".

    The New Guy is correct in that it looks like your code could use some separation of logic and presentation. It actually isn't the best coding practice in PHP to use variables inside double quotes and the use of mysql functions inside the quotes is confusing the heck out of me... I'm having trouble deciphering where you are going with this.

    One thing I can see... there isn't any mysql_fetch_array or another mysql function to actually retrieve data.
    Thanks, everyone. I'm still a PHP newbie, and perhaps my ambitions are greater than my capabilities...

  7. #7
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by compuwhiz7
    Thanks, everyone. I'm still a PHP newbie, and perhaps my ambitions are greater than my capabilities...
    Actually, I doubt that. :-)
    I bet that what you want to accomplish is within your reach.

    Suggestion: Try simplifying the page... getting one thing to work at a time. Strip out all the presentation so nothing complicates the file. That can probably help you isolate your problems.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try that... thanks for your support.


Bookmarks

Posting Permissions

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