denoteone Posted May 19, 2009 Share Posted May 19, 2009 I am trying to add a value to a field in a table WHERE To otehr values of that field match. something like $query = "INSERT (visitor_whois) VALUES ( '$ip_info') INTO visitor_list WHERE visitor_day = '$today' and visitor_month = '$month'"; $result = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR); but I am getting an error that is not helping me. Any ideas Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/ Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 You don't use a WHERE clause with INSERT... Maybe you want an UPDATE?? Now, what exactly are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837560 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 I am thinking it is UPDATE I am researching now. Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837561 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 Thanks Maq you beat me. lol I will post when I have a solution Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837564 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 I got the UPDATE to work. now I am having issues with mysql_fetch_array $query = "SELECT * FROM visitor_list WHERE visitor_day = '$today' and visitor_month = '$month'"; $result = mysql_query($query)or die (mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $string = file_get_contents("http://www.websitehere.com/soap/client-example-city.php?ip={$row['visitor_ip']}"); echo $string; I am trying to send the vaule of $row['visitor_ip'] on the end of the url is this the best way to do it? Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837576 Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 Yes, that should work. You may want to put it in a string variable first then pass it to file_get_contents. Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837579 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 i put the string in a variable but this is the warning I am getting. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/ipupdate.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837593 Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 That usually means your query is failing, but it's syntactically correct. You do have some spacing issues. Right before your '=' you have 2 spaces, should be one, but this wouldn't throw this warning. You don't get an error output for: ? $result = mysql_query($query)or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837599 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 so my while statement is working but for some reason the variable {$row['visitor_ip']} is not changing which it should since it is different in every row. Any thoughts? here is my full code: ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); require_once('visitors_connections.php');//the file with connection code and functions //get the required data $today= date("d"); $month= date("m"); mysql_select_db($database_visitors, $visitors); $query = "SELECT * FROM visitor_list WHERE visitor_day = '$today' and visitor_month = '$month'"; $result = mysql_query($query)or die (mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $website = "http://www.websitehere.com/soap/client-example-city.php?ip{$row['visitor_ip']}"; echo $website; $string = file_get_contents($website); if (strpos($string,"org")){ $orginfo = explode("org", $string); $city = $orginfo[1]; $output = explode('"',$city); $ip_info = $output[2]; }else { $ip_info = 'I was unable to find data on this IP'; } $ip_info = mysql_real_escape_string($ip_info); $query = "UPDATE visitor_list SET visitor_whois = '$ip_info' WHERE visitor_day = '$today' and visitor_month = '$month'"; $result = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR); } Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837603 Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 Your code looks correct, are you sure there aren't multiple IP's that match those conditions? Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837612 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 yes there are about 20 different ips that match those conditions. I though that this would make and array out of them and then loop through the array updating the visitor_whois filed for the IP. I am obviously not correct. Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837617 Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 Use: mysql_fetch_assoc NOT: mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837622 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 Warning: Wrong parameter count for mysql_fetch_assoc() in /var/www/html/ipupdate.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837623 Share on other sites More sharing options...
denoteone Posted May 19, 2009 Author Share Posted May 19, 2009 when I add $query = "SELECT visitor_ip FROM visitor_list WHERE visitor_day = '$today' and visitor_month = '$month'"; $result = mysql_query($query)or die (mysql_error()); print_r(mysql_fetch_assoc($result)); it is only getting one IP address there should be like 2o rows that all have the same day and month all with different visitor_ip entries. I need to run a for loop for everyone of those different ip's Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837633 Share on other sites More sharing options...
Maq Posted May 19, 2009 Share Posted May 19, 2009 That should work but try: $query = "SELECT DISTINCT visitor_ip FROM visitor_list WHERE visitor_day = '$today' and visitor_month = '$month'"; Quote Link to comment https://forums.phpfreaks.com/topic/158802-insert-into-where/#findComment-837638 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.