maxso Posted December 23, 2008 Share Posted December 23, 2008 Hi, in this script I have tried to find the users ip and see if it is in the database. Currently I have been having problems. Parse error: parse error, unexpected T_VARIABLE in /home/www/cooladverts.freehostia.com/index.php on line 11 <html> <head /> <body> <?php $ip=$_SERVER['REMOTE_ADDR']; $con=mysql_connect('***********','****','****'); mysql_select_db('servers'); $get=mysql_query('SELECT ip FROM server1 WHERE IP='$ip''); $ip_exist=mysql_num_rows($get) if($ip_exist > 0){ echo "welcome again" } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/ Share on other sites More sharing options...
maxso Posted December 23, 2008 Author Share Posted December 23, 2008 line 11 is $get=mysql_query('SELECT ip FROM server1 WHERE IP='$ip''); Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722582 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 $get=mysql_query("SELECT ip FROM server1 WHERE IP='$ip'"); Should fix that problem. If you wanted to use single quotes inside single quotes you have to escape them. Simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722583 Share on other sites More sharing options...
maxso Posted December 23, 2008 Author Share Posted December 23, 2008 Now i have a problem with my if statement. Have i got this code wrong? Parse error: parse error, unexpected T_IF in /home/www/cooladverts.freehostia.com/index.php on line 15 if($ip_exist > 0){ echo "welcome again" } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722585 Share on other sites More sharing options...
Mikedean Posted December 23, 2008 Share Posted December 23, 2008 $ip_exist=mysql_num_rows($get); You need to terminate each line of PHP with a semicolon (';'). Edit: You should also add another one: echo "welcome again"; Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722587 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 Same here echo "welcome again" Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722590 Share on other sites More sharing options...
maxso Posted December 23, 2008 Author Share Posted December 23, 2008 Thank you for that, im always forgetting them. Also, when i add an else statement it gives me an error. Parse error: parse error, unexpected T_ELSE in /home/www/cooladverts.freehostia.com/index.php on line 17 if($ip_exist > 0){ echo "welcome again"; else { echo "new user"; } } Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722602 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 You don't end '}' the if statement: if($ip_exist > 0){ echo "welcome again"; } else { echo "new user"; } Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722606 Share on other sites More sharing options...
maxso Posted December 23, 2008 Author Share Posted December 23, 2008 no luck. its on this line else { Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722608 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 Please post ALL code and errors. The code I posted is correct... Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722611 Share on other sites More sharing options...
maxso Posted December 23, 2008 Author Share Posted December 23, 2008 Sorry, you were correct, my mistake. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/138215-solved-confused/#findComment-722617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.