Jump to content

Error?


Timma

Recommended Posts

Whenever I try to access this "page" or script it keeps returning the error:

Parse error: syntax error, unexpected T_VARIABLE in C:\WEB_SERVER\www\site\index.php on line 5

 

And here is my code (Config is just some variables for database and that, I also don't have a password for the database if that's the problem as it is a local sever):

<?php
include('config.php')

// connect to the mysql server 
$con = mysql_connect($server, $db_user, $db_pass) 
or die ("Could not connect to mysql because ".mysql_error()); 

// select the database 
mysql_select_db($database) 
or die ("Could not select database because ".mysql_error()); 

function userIP()
{
//This returns the True IP of the client calling the requested page
// Checks to see if HTTP_X_FORWARDED_FOR
// has a value then the client is operating via a proxy
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
  {
 $userIP = $_SERVER['REMOTE_ADDR'];
  }
  // return the IP we've figured out:
  return $userIP;
}

function thank() {
$sql = "INSERT INTO $table ip VALUES '".userIP()."';"
mysql_query($sql);
}

function checkip(){
$match = "select id from $table where ip = '".userIP()."';"; 
$qry = mysql_query($match) 
or die ("Could not match data because ".mysql_error()); 
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
return false;
} else { 
return true;
}
}

if (!checkip()) {
echo '<a href="'.thank().'"> Thanks ME </a>';
} else {
echo 'I\'m sorry, you have already thanked me.'
}
echo '<font size="10">$thanks</font>';
?>

Link to comment
https://forums.phpfreaks.com/topic/44905-error/
Share on other sites

$con = mysql_connect($server, $db_user, $db_pass)  <--- end with a ';'

 

same for mysql_select_db($database)

 

it should be mysql_select_db($database);

 

Don't forget using the ; after each line. Except when you create a function you dont have to, or other things like if and else etc

 

Full-Demon

Link to comment
https://forums.phpfreaks.com/topic/44905-error/#findComment-218017
Share on other sites

Never mind about that right now, I'll read up some things, shouldn't be that hard.

 

I'm getting a new error with my code now:

Could not match data because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ip = '127.0.0.1'' at line 2

 

<?php
include('config.php');

// connect to the mysql server 
$con = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); 

// select the database 
mysql_select_db($database) or die ("Could not select database because ".mysql_error()); 

function userIP()
{
//This returns the True IP of the client calling the requested page
// Checks to see if HTTP_X_FORWARDED_FOR
// has a value then the client is operating via a proxy
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
  {
 $userIP = $_SERVER['REMOTE_ADDR'];
  }
  // return the IP we've figured out:
  return $userIP;
}

function thank() {
$sql = "INSERT INTO $table ip VALUES '".userIP()."';";
mysql_query($sql);
}

function checkip(){
$match = "SELECT * FROM $table
WHERE ip = '".userIP()."';"; 
$qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); 
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
return false;
} else { 
return true;
}
}

if (!checkip()) {
echo '<a href="'.thank().'"> Thanks ME </a>';
} else {
echo 'I\'m sorry, you have already thanked me.';
}
echo '<font size="10">$thanks</font>';
?>

Link to comment
https://forums.phpfreaks.com/topic/44905-error/#findComment-218031
Share on other sites

$match = "SELECT * FROM $table

WHERE ip = '".userIP()."';";

 

That one is doing something wrong. I suggest you concenate $table and get rid of the return, be sure there is a space before WHERE:

 

$match = "SELECT * FROM '".$table."' WHERE ip = '".userIP()."';";

 

Full-Demon

Link to comment
https://forums.phpfreaks.com/topic/44905-error/#findComment-218035
Share on other sites

Ah I see the problem I think. $thanks hasn't been defined in the function itself. You should do this:

 

function checkip($thanks) { ... }

 

And when you call the funtion, use this: checkip($thanks)

 

Be sure you don't call it in another function, or you have to do that with the other function too.

 

Full-Demon

Link to comment
https://forums.phpfreaks.com/topic/44905-error/#findComment-218066
Share on other sites

Ah, thanks!

Well now there are no errors, but my script doesn't work. Even though it never did :D

 

When you click the button it is supposed to record your ip address in the table in the database and then it should refresh(still need to figure this out) and you shouldn't be able to click the button from that ip address again, and another thing I'm trying to figure out is how to make $thanks equal to something in the table in the database. This something is named "amount" and I would like $thanks to equal it.

 

<?php
include('config.php');

// connect to the mysql server 
$con = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); 

// select the database 
mysql_select_db($database) or die ("Could not select database because ".mysql_error()); 

function userIP()
{
//This returns the True IP of the client calling the requested page
// Checks to see if HTTP_X_FORWARDED_FOR
// has a value then the client is operating via a proxy
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
  {
 $userIP = $_SERVER['REMOTE_ADDR'];
  }
  // return the IP we've figured out:
  return $userIP;
}

$thanks=0;

function thank($table) {
$sql = "INSERT INTO ".$table." ip VALUES '".userIP()."';";
mysql_query($sql);
}

function checkip($table){
$match = "SELECT * FROM ".$table." WHERE ip = '".userIP()."';";
$qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); 
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
return false;
} else { 
return true;
}
}

if (!checkip($table)) {
echo '<a href="'.thank($table).'"> Thanks ME </a>';
} else {
echo 'I\'m sorry, you have already thanked me.';
}
echo '<font size="10">'.$thanks.'</font>';
?>

Link to comment
https://forums.phpfreaks.com/topic/44905-error/#findComment-218073
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.