[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.

Hi thepokemon. Welcome to the forums. :slight_smile:

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.

Also, you might want to read Common PHP Problems, as this problem is covered in that thread; you have a WPSE.

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
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(0, strlen($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;



}




?>

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.

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.