Reputation: 11
I try to update data in my row, but I can't, hmm I get message, that everything went good, but row doesn't change at all. I think I do something wrong with incrementing, I mean that data in row is a string, that's why ++ may not work on it. I use echo to see what data is in for example $ip, $lower etc, to see on what data script is going to work, and everything goes good, but UPDATE doesn't. This is my code:
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip_for_map;
$ip_data_for_map = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
$country_upper = $ip_data_for_map->geoplugin_countryCode;
echo $country_upper;
$country_lower = strtolower($country_upper);
echo $country_lower;
$main_for_table = 1;
$take_from_sql_country = "SELECT $country_lower FROM table WHERE main='$main_for_table'";
$country_taken_from_table = mysqli_query($dbc, $take_from_sql_country);
$row_sl_map = mysqli_fetch_assoc($country_taken_from_table);
$row_country_data = $row_sl_map['$country_lower'];
$row_final = $row_country_data++;
$update_countrys_row = "UPDATE table SET $country_lower='$row_final' WHERE main='$main_for_table'";
$update_country_final = mysqli_query($dbc, $update_countrys_row);
if(!$update_country_final)
{
echo 'BADSHIT';
}
else
{
echo 'BRAVO';
}
Upvotes: 0
Views: 65
Reputation: 324630
$row_country_data = $row_sl_map['$country_lower'];
This line is literally looking for an array key called $country_lower
, not the key contained in the variable $country_lower
.
Remove the single quotes.
It should also be noted that, even if the query results in no update (as is the case in your erroneous code), the query itself still succeeds.
Upvotes: 1