Timma Posted March 30, 2007 Share Posted March 30, 2007 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 More sharing options...
Full-Demon Posted March 30, 2007 Share Posted March 30, 2007 $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 More sharing options...
nikon Posted March 30, 2007 Share Posted March 30, 2007 You also forgot to close the: include('config.php') . Change to: include('config.php'); Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218019 Share on other sites More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 Thanks a lot you two, also while I'm here, How can I make it so that $thanks = amount, amount is a thing(I need to learn the lingo) in my database which auto rises as more ip addresses are added. Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218024 Share on other sites More sharing options...
Full-Demon Posted March 30, 2007 Share Posted March 30, 2007 Can you explain yourself a little bit more? I dont understand... Full-Demon Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218026 Share on other sites More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 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 More sharing options...
Full-Demon Posted March 30, 2007 Share Posted March 30, 2007 $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 More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 Nope still getting this error. 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 1 Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218049 Share on other sites More sharing options...
Full-Demon Posted March 30, 2007 Share Posted March 30, 2007 As far as I see you dont define the $table value. Whats the variable supposed to contain? Full-Demon Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218055 Share on other sites More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 According to my config.php it is: $table = "thanks"; Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218056 Share on other sites More sharing options...
Full-Demon Posted March 30, 2007 Share Posted March 30, 2007 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 More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 Ah, thanks! Well now there are no errors, but my script doesn't work. Even though it never did 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 More sharing options...
Timma Posted March 30, 2007 Author Share Posted March 30, 2007 Bump. Link to comment https://forums.phpfreaks.com/topic/44905-error/#findComment-218106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.