Might want to throw an echo mysql_error(); just below the update query execution. Does it spit anything out? (also, make sure you’ve got the latest version of that paste… i had to edit a couple of times)
So to take what guido has provided that into your case, AdWarm, I believe that would make your whole script reducable to…
<?php
require("./databaseconnection.php"); //Get Database Login Information
mysql_connect(localhost,$username,$password) or die(mysql_error());
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");
mysql_query('UPDATE leads LEFT OUTER JOIN ValidISP ON leads.IPISP = ValidISP.ISP SET leads.IPCheck = COALESCE(ValidISP.Status, "MANUAL") WHERE leads.IPCheck = "NO"');
echo mysql_error(); //just in case.
?>
(PS: Strongly consider moving into mysqli or PDO, as mysql (library) is being taken out of PHP (deprecated as of 5.5))
Thanks for the help so far both of you, how ever I’m still having a problem with this and iv been trying to work it out myself but my mind is completely baffeled as to why its not working
Can i be cheeky and ask for a bit more help please?
What records do you get when you run this query on your database?
SELECT * FROM leads LEFT OUTER JOIN ValidISP ON leads.IPISP = ValidISP.ISP WHERE leads.IPCheck = “NO”’
So the query did what it was supposed to do. Now you need to figure out why those entries have NULL for their match to ValidISP…
I can now tell you that your database is either missing data, or your data is not matching for some reason (I keep looking at the extraneous space characters on the ends of those names…)
I’ve checked, checked and double checked. I cant see any difference on the data in the database, no spaces before of after each data entry. I’m at a lost as to why, if i give you access to the database can you take a look at it for me please? i trust you.
SELECT * FROM `ValidISP` WHERE `ISP` = 'HUTCHISON 3G UK LIMITED '
1
resource(4) of type (mysql result)
ISP Checks completed!
Look closer at the end of that string. There’s a space between “LIMITED” and the closing '. It implies that the value in the ValidISP table has a space at the end, where the value in the leeds table does not.
Try this query:
SELECT CONCAT(“Thisisthestart”,ISP,“ThisIstheEnd”) FROM ValidISP;
and see if that helps you see any spaces on the front/end of the values.
I understand that, but i checked the data in the database and there is no space at the end of the data. As what we have been doing is just SQL it cant be the PHP code as there is none, iv checked the records, made sure theres no space at the end and PHPMYADMIN is saying there is no space at the end of the records. I’m really stuck here
If your database/PMA is open to the web, send me a PM with your login credentials and I will take a look. I’m telling you there are spaces on those fields that are causing the mismatch, though
There are no spaces there.
However, there IS a carriage return or newline character on the end of the ISPIP values of LeadID’s 10, 11, and 12. This would cause a mismatch. You need to trim your values. (probably need to trim every string in the database, if this has been going on for a while.)
I chopped the extraneous character off of LeadID 10, and it now returns a value of PASS instead of NULL when the query is executed.
LeadID 9 will still return NULL (and then be set to manual)… this is the correct behavior, as it does not have a matching entry in the ValidISP table.
Hmmm to the eye it doesnt look like there was a space as the cursor was at the end of the data, but if i press the arrow right then its still at the end of the data so your right about there being a space after it, which is strange. So that leaves 2 things then as to why a space is added at the end. Either the data in the table called geo has a space at the end of every record (just checked and can confirm there is no space). So then that leaves the PHP code adding the lead to the database, which iv also noticed another problem, dont know if you noticed but in the leads table under the Mobile field you can see they all have a ’ in it and it shouldn’t. Now my page is quite a long script, so below i have listed the code that i think only you need to.
// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
} // end make safe
//Get ISP Of IP Address
list($ip1, $ip2, $ip3, $ip4) = explode(".", $ip);
$ipnum = $ip1*(256*256*256)+$ip2*(256*256)+$ip3*256+$ip4;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");
$query = sprintf("SELECT * FROM `geo` WHERE %s BETWEEN `IP1` AND `IP2`",
quote_smart($ipnum));
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
$ipcountry=$row['Country'];
$ipcc=$row['Code'];
$ipisp=$row['ISP'];
}
//mysql_close();
//End
//Add Lead To Database
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");
$query2 = sprintf("INSERT INTO leads (ProgramID, ProgramName, AffID, SubID, AdID, ClickIP, LeadIP, Status, Referer, Payout, NetPayout, MerchantPayout, Title, FirstName, LastName, CompanyName, Address1, Address2, City, County, PostCode, Country, Telephone, Mobile, EmailAddress, TermsAgreed, EmailContact, TelephoneContact, PostContact, MobileSubmit, MobileOS, OS, Browser, UserAgent, IPISP, IPCC, IPCountry, POFCheck, EmailCheck, IPCheck, UserAgentCheck, FraudCheck, CountryCheck, TelephoneCheck, DuplicationCheck, UniqueID) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,'%s','%s',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
quote_smart($ProgramID),
quote_smart($ProgramName),
quote_smart($affid),
quote_smart($subid),
quote_smart($adid),
quote_smart($clickip),
quote_smart($ip),
quote_smart($status),
quote_smart($referer),
quote_smart($affpayout),
quote_smart($netpayout),
quote_smart($merchantpayout),
quote_smart($title),
quote_smart($firstname),
quote_smart($lastname),
quote_smart($companyname),
quote_smart($address1),
quote_smart($address2),
quote_smart($city),
quote_smart($county),
quote_smart($postcode),
quote_smart($country),
quote_smart($telephone),
quote_smart($mobilen),
quote_smart($emailaddress),
quote_smart($termsagreed),
quote_smart($emailcontact),
quote_smart($telephonecontact),
quote_smart($postcontact),
quote_smart($mobilesubmit),
quote_smart($mobileosoutput),
quote_smart($osoutput),
quote_smart($browseroutput),
quote_smart($useragent),
quote_smart($ipisp),
quote_smart($ipcc),
quote_smart($ipcountry),
quote_smart($pofcheck),
quote_smart($emailcheck),
quote_smart($ipcheck),
quote_smart($useragentcheck),
quote_smart($fraudcheck),
quote_smart($countrycheck),
quote_smart($telephonecheck),
quote_smart($duplicationcheck),
quote_smart($uniqueid));
//print $query2;
mysql_query($query2) or die(mysql_error());
mysql_close();
//End
Can you see why theres a space added for IPISP?
EDIT: looks like PHPMYADMIN doesnt show the extra space at the end, only MySQL Workbench shows it so since i was using PHPMYADMIN thats why i couldnt see the space at the end.