Php file control problem (there is-there isn't)

Discussion in 'PHP' started by erkin0007, May 6, 2013.

  1. #1
    hi this codes are not working
    i have got 2 files and one datebase its name is "haber" i am from Turkey :)
    -index.php
    -connect.php
    file path:
    haber/index.php
    haber/system/connect.php

    this is connect.php
    <?php
        $host='localhost';
        $user='root';
        $pass='';
        $data='haber';//Veritabanı adı
        //baglan
        $connx=mysql_connect($host,$user,$pass);
        if($connx){
            $dbConn=mysql_select_db($data,$connx) or die (mysql_error());
         
         
            $language=mysql_query("SET CHARACHTER SET    utf8"));
                }
        else{
     
        die(mysql_query());
        }
     
     
     
    ?>
    PHP:
    And this is index.php
    <?php
     
        $connectFile="haber/system/connect.php";
        if(file_exists($connectFile)){
     
        require $connectFile;
        }
        else{
     
            echo"error";
        }
    ?>
    PHP:
     
    erkin0007, May 6, 2013 IP
  2. gvre

    gvre Member

    Messages:
    35
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    33
    #2
    Not related to your problem but mysql extension is deprecated. Use pdo(my suggestion) or mysqli.
     
    Last edited: May 6, 2013
    gvre, May 6, 2013 IP
    deathshadow likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Since you're using relative paths, and you're already in the "haber" folder, you have to drop it from the path.

    
    $connectFile="system/connect.php";
    
    PHP:
     
    nico_swd, May 6, 2013 IP
    deathshadow likes this.
  4. wren11

    wren11 Active Member

    Messages:
    89
    Likes Received:
    10
    Best Answers:
    3
    Trophy Points:
    53
    #4
    $connectFile="../haber/system/connect.php";
    Code (markup):
     
    wren11, May 6, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Spot on... generally speaking the more 'path' you try to use or any 'up-tree linking' (aka ../) you 'have' to use just means overthinking your directory structure. In this case everything is relative to where the index.php is run from, making it -- as nico_swd's answer shows, VERY simple.

    Also, listen to gvre -- they've been telling us for EIGHT YEARS to stop using mysql_ functions, and have FINALLY added giant red warning boxes to the manual pages saying same!
     
    deathshadow, May 7, 2013 IP
  6. gvre

    gvre Member

    Messages:
    35
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    33
    #6
    Besides the simplicity of not using up-tree linking, as deathshadow mentioned, adding '../haber' in the path adds a little overhead because of an extra stat call.
     
    gvre, May 7, 2013 IP
  7. erkin0007

    erkin0007 Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Parse error: syntax error, unexpected ')' in C:\AppServ\www\haber\system\connect.php on line 12
    help me please
     
    erkin0007, May 7, 2013 IP
  8. wren11

    wren11 Active Member

    Messages:
    89
    Likes Received:
    10
    Best Answers:
    3
    Trophy Points:
    53
    #8

    you have an extra ) at the end of line 12.
     
    wren11, May 7, 2013 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #9
    $language=mysql_query("SET CHARACHTER SET utf8"));

    one more ) than you open.
    Also might help if you spelled CHARACTER properly.
     
    deathshadow, May 7, 2013 IP