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 13 of 13

Thread: Display problem

  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display problem

    hi all,

    i was done one php connection with apach, mysql i this somthings wrong with it could you pls anyone can help me to figure out what happend to this code
    file name is this db_config.php
    <?php

    $db_host = "localhost";
    $db_user = "php";
    $db_password = "fo";
    $db_name = "babyDB";
    ?>


    ////////////
    file name of this temp_con.php

    <?php
    require ($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
    $connection = @mysql_connect($db_host, $db_php, $db_password);
    echo "connection made";

    ?>

    thanx

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Instead of using "require ($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");" just use:

    PHP Code:
    <?
    include('config/db_config.php');
    ?>
    (Without the <? and the ?> because you already have it.) Or, you could do this:

    PHP Code:
    <?
    $root 
    $_SERVER['DOCUMENT_ROOT']."config/db_config.php";
    include(
    $root);
    ?>
    Last edited by ConnorB; 01-25-2007 at 05:18 AM.

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    It would help if you told us which part is not working.

    There should be no reason to include the Document Root in the include. Unless your hosting does not have a proper include path set up.

    Also, it is generally advised to use <?php instead of <?

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I used "<?" because it was shorter and easier for me to tell what to do with. I only use "<?php" when the file I am writing has some sort of HTML in the content of the file. It's just how I roll.

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi ConnorB,
    what you are gave to me was not working same things still i cant see what the echo hold or no error display just a blank page why is that help me if i change password php file error has to show isn't it but this time it will not i create a database call babyDB; using mysql (using dos commands) so there i create a user call php, put password and host every things working when i am try to login to database using mysql command but when im using Browser it will not display anythings
    Last edited by somiadiscon; 01-26-2007 at 06:41 AM.

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by somiadiscon View Post
    hi ConnorB,
    what you are gave to me was not working same things still i cant see what the echo hold or no error display just a blank page why is that help me if i change password php file error has to show isn't it but this time it will not i create a database call babyDB; using mysql (using dos commands) so there i create a user call php, put password and host every things working when i am try to login to database using mysql command but when im using Browser it will not display anythings
    try speaking english??

    i would use this to connect..

    PHP Code:
    <?php
    // This is an example of config.php
    $dbhost 'localhost';
    $dbuser 'root';
    $dbpass 'password';
    $dbname 'phpcake';
    ?>
    PHP Code:
    <?php
    // This is an example opendb.php
    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql');
    mysql_select_db($dbname);
    ?>
    so when you want to connect, you need this code;
    PHP Code:
    <?php
    include 'config.php';
    include 
    'opendb.php';

    // ... do something like insert or select, etc

    ?>
    But remember to close the connection after you have done something to the database so make another file..

    PHP Code:
    <?php
    // an example of closedb.php
    // it does nothing but closing
    // a mysql database connection

    mysql_close($conn);
    ?>
    and then include it where you need it..

    PHP Code:
    <?php
    include 'config.php';
    include 
    'opendb.php';

    // ... do something like insert or select, etc

    include 'closedb.php';
    ?>
    happy coding

    Jamez.
    Last edited by cookieboi; 01-26-2007 at 08:22 PM. Reason: to help him more...
    woooooo!

    visit my website:
    click here!

  • #7
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi cookieboi,
    i know my english is not good, but you can read right. however now this time i got error msg
    "Fatal error: Call to undefined function mysql_connect() in C:\PHP\uploadtemp\sql.php on line 3"

    could you pls figure out this matter thanx

    somiadiscon

  • #8
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi mate, i cant see any error in it, the only thing that i can see that might be wrong is that on the opendb page, remove the $conn from the beggining so it looks like this,

    PHP Code:
    <?php 
    // This is an example opendb.php 
    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql'); 
    mysql_select_db($dbname); 
    ?> 

    <?php 
    // This is an example opendb.php 
    mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql'); 
    mysql_select_db($dbname); 
    ?>
    and then don't include the closedb.php file.

    Apart from that suggestion i cant see much else wrong with it. you may need to configure your server perhaps?
    Last edited by cookieboi; 01-29-2007 at 05:18 PM. Reason: wrong
    woooooo!

    visit my website:
    click here!

  • #9
    Regular Coder
    Join Date
    Nov 2004
    Location
    Edinburgh, SCO
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey,

    removin $conn won't help the fact that the MySQL functions are not defined. PHP has to be installed with MySQL. Here are some more tips on how to do it: PHP.net. It is also a good source for small code snippets that should always work.

  • #10
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi schotte,
    thank you for your help i am serching now, why the function is not working i know you are right. becoz Mysql and php there should be bridge right may be it don't work porperly isn't it thank you again all of you helping me still i am try to figure out problem

  • #11
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi schotte,
    here mr. i couldn't i don't know why is that but i am not sure whether it is the version i am using. Now i am using apache 2.0.5 and php 5 MySQL 4.x.x so i don't know it was install without any issue MySQL is working when i am try to create a database or delete database using command prompt dos command is working perfect. Thing is now i am install AMP software with all the packeges it has that is working without any problem. why is that

  • #12
    Regular Coder
    Join Date
    Nov 2004
    Location
    Edinburgh, SCO
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So if I understand you correctly, you didn't have MySQL installed?
    Now you got AMP installed and it still does not work?

    If so, have you installed PHP with MySQL support? You can check either the php.ini file or create a file with the following code to check:

    PHP Code:
    <?php
    phpinfo
    ();
    ?>

  • #13
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Schotte,
    i check with this code earlier there i found MySQL is not working if it is working properly, it has to show php info page i know that that is why i want to know kind of what issue i have at the moment, other things is i am using 64bit processor is there is any issue with that process performance
    <?php
    phpinfo();
    ?>


  •  

    Posting Permissions

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