george Posted November 18, 2009 Share Posted November 18, 2009 if ($num_rows == 0) { $query = "INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('".$ip."','1','".$site."','".$referingURL."','".$Name."')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); } Can you see my error? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 if ($num_rows == 0) { $query = ("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name'"); $result = mysql_query($query) or die('Query failed: ' . mysql_error()); } You code different so I am not sure if this will work. Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 The referringURL may be NULL, so I have if ($_POST['referingURL']) { $referingURL=$_POST['referingURL']; } else { $referingURL='';} prior to the code in my first post. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Tell me if this works. Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 I will try that, with the exception of the unmatched ( . Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 Still tweeking. Link to comment Share on other sites More sharing options...
chibineku Posted November 18, 2009 Share Posted November 18, 2009 Have you checked every variable is written with the correct cases? $Name for example stands out, as your tendency seems to be to start with a lower case letter. Are you sure the problem isn't in the preceding or subsequent section? Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 The error I get with what you gave me is[18-Nov-2009 01:36:51] PHP Parse error: syntax error, unexpected ')' in /home2/getfit/public_html/countmein.php on line 28 $query = ("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name'"); I thought I needed another ) at the end of my string. $query = ("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name')"); But now I get an [18-Nov-2009 01:36:51] PHP Parse error: syntax error, unexpected ')' in /home2/getfit/public_html/countmein.php on line 28 Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 Opps, wrong error message. Now I get no error message, neither does it work. Previous variable code which could have an effect, if (isset($_POST['Name'])) { $Name = $_POST['Name']; } else { $Name = ''; } if (isset($_POST['referingURL'])) { $referingURL=$_POST['referingURL']; } else { $referingURL='';} I was hoping this would fix for the non existant referingURL, maybe not though? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Not sure maybe not, if there is nothing showing up, its an external error, the query is empty, might be my fault. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Put your full code in. Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 $ip = $_SERVER['REMOTE_ADDR']; $site = gethostbyaddr($_SERVER['REMOTE_ADDR']); $Name = $_POST['Name']; $referingURL = $_POST['referingURL']; if ($referingURL==NULL) {$referingURL = '';} $link = mysql_connect($db_server, $db_user, $db_passwd); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db($db_name, $link) or die('Could not select database'); $query = "SELECT * FROM VistngIPs WHERE addy_id = '".$ip."'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows == 0) {// $query = "INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('".$ip."','1','".$site."','".$referingURL."','".$Name."')";// $query = "(INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name')");//$query = ("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name'");$query = ("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name')"); $result = mysql_query($query) or die('Query failed: ' . mysql_error()); } if ($num_rows >= 1) { $query = "UPDATE VistngIPs SET count_em = count_em + 1 WHERE addy_id = '".$ip."'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); } mysql_free_result($result); mysql_close($link);// } ?> Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Put this in the beginning, mysql_query(" and this at the end "); So like this $query = mysql_query("INSERT INTO VistngIPs (addy_id, count_em, site, referingURL, Name) VALUES ('$ip','1','$site','$referingURL.','$Name'"); Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Try that, this is the first code you showed us. Link to comment Share on other sites More sharing options...
chibineku Posted November 18, 2009 Share Posted November 18, 2009 It looks like you're using single line comments: // to try to comment out code with a line break in it. That'll cause unexpected T_ whatever. Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 If I remove referringURL and Name from the query, it works fine. referringURL and Name are passed (or should be) using AJAX to the code provided, and the referringURL value is NULL. I removed all comments. When I add back referringURL and Name, the error reappears Link to comment Share on other sites More sharing options...
george Posted November 18, 2009 Author Share Posted November 18, 2009 I have it working now. Thanks to all. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Congrats you win!! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.