SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help] Page not displaying at all, when php code connects to MySQL Database

    I have no idea what's wrong. I need personal help, I have next to 0 experience with PHP or MySQL. If someone could help me over skype or Teamviewer I'd be very grateful.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Hi thepokemon. Welcome to the forums.

    This is a forum where you can post some code, or maybe a link, and ask a question. If you'd rather get some personal help, it might be better to consult a service provider in your area.

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Also, you might want to read Common PHP Problems, as this problem is covered in that thread; you have a WPSE.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While access the php in the server I face error as shown below

    root@ [/home/microsof/public_html/generate]# php index.php

    Notice: Undefined index: REMOTE_ADDR in /home/microsof/public_html/getcodes/functions.php on line 92

    This is all the code in my functions.php file.
    PHP Code:
    <?php
    error_reporting
    (E_ALL); 
    ini_set('display_errors',1);
    function 
    getRandomString($length) {
        
    $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        
    $string '';

        for (
    $i 0$i $length$i++) {
            
    $string .= $characters[mt_rand(0strlen($characters) - 1)];
        }

        return 
    $string;
    }

    function 
    new_ref()
    {
    $userip=$_SERVER['REMOTE_ADDR'];
    $query="SELECT * FROM cookie_ref_ips WHERE IP_address='$userip'";
    $exe=mysql_query($query);
    $num=mysql_num_rows($exe) or die(mysql_error());
    if (
    $num==0)
    {
    $refval=getRandomString(10);

    $query="SELECT * FROM cookie_ref_ips WHERE REF_val='$refval'";
    $exe=mysql_query($query);
    $num=mysql_num_rows($exe) or die(mysql_error());
    if(
    $num==0)
    {
    $query="INSERT INTO cookie_ref_ips(IP_address,REF_val) values('$userip','$refval')";
    mysql_query($query);
    $query="INSERT INTO cookie_ref(REF_hits,ip,REF_val) values('0','$userip','$refval')";
    mysql_query($query);
    }
    }
    $query="INSERT INTO cookie_ref(IP_address,REF_val) values('$userip','$refval')";

    }

    function 
    dbConnect() {
        
    // update this to your db details
        
    mysql_connect('localhost''microsof_user''cupcake123')or die(mysql_error());
        
    mysql_select_db('microsof_database')or die(mysql_error());
    }
        
    function 
    get_link()
    {
    $userip=$_SERVER['REMOTE_ADDR'];
    $query="SELECT * FROM cookie_ref_ips WHERE IP_address='$userip'";
    $exe=mysql_query($query);
    $exe2=mysql_fetch_array($exe) or die(mysql_error());
    $referal=$exe2['REF_val'];

    return 
    $referal;
    }    

    function 
    update_hits()
    {


    if(isset(
    $_GET['ref']))
    {
    $ip=$_SERVER['REMOTE_ADDR'];


    $ref=$_GET['ref'];


    $query="SELECT * FROM cookie_ref WHERE REF_val='$ref'";
    $exe=mysql_query($query);
    $result=mysql_fetch_array($exe);
    $Oip=$result['ip'];
    $hit_temp=$result['REF_hits'];
    $hit_temp++;


    if(
    $ip!=$Oip)
    {


    $query="UPDATE  cookie_ref set REF_hits='$hit_temp' WHERE REF_val='$ref'";
    mysql_query($query);
    }


    }

    }

    function 
    count_hits()
    {
    $userip=$_SERVER['REMOTE_ADDR'];
    $query="SELECT * FROM cookie_ref WHERE ip='$userip'";
    $exe=mysql_query($query);
    $result=mysql_fetch_array($exe) or die(mysql_error());

    $count=$result['REF_hits'];

    return 
    $count;



    }




    ?>

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Is that script being run through the command line?

    The error indicates that $_SERVER['REMOTE_ADDR'] does not exist.

    $_SERVER['REMOTE_ADDR'] will not exist when running outside of a web request context such as via the command line.

    By the way unless you changed the db authentication credentials those are out there now for the whole world to see. With a little more information I could now drop your entire database fyi. Not that I would do that :\ just saying…
    The only code I hate more than my own is everyone else's.

  6. #6
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    Is that script being run through the command line?

    The error indicates that $_SERVER['REMOTE_ADDR'] does not exist.

    $_SERVER['REMOTE_ADDR'] will not exist when running outside of a web request context such as via the command line.

    By the way unless you changed the db authentication credentials those are out there now for the whole world to see. With a little more information I could now drop your entire database fyi. Not that I would do that :\ just saying…
    The value of remote_addr is my current IP address.

    Not sure what's wrong.

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    When you execute the file on the command line, there is no REMOTE_ADDR. When you use a web browser to access it, there is one.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •