Article 57WVK Minor bug on SQL and PHP

Minor bug on SQL and PHP

by
Oldy
from LinuxQuestions.org on (#57WVK)
Hi there,
Minor bug on SQL and PHP. Example I have Car with Volvo.

input:Quote:
https://cars.com?car=Volvo
output:Quote:
cars - ip - count
Volvo - 200.0.0.01 - 3
Volvo - 300.5.0.07 - 1
VW - 500.2.0.04 - 1
etc

I added (INSERT) one Volvo ($car) with and IP ($ip). (Volvo, 200.0.0.01, 1)
F5 then I UPDATE Volvo with my IP (Volvo, 200.0.0.01, 2)
Update it again with Volvo and IP (Volvo, 200.0.0.01, 3)
and so on
another man adds Volvo+IP (Volvo, 300.5.0.07, 1)
another man adds VW+IP (VW, 500.2.0.04, 1)
and so on
Do you understand what I mean?

database:Quote:
CREATE TABLE cars (
cars(100) NOT NULL,
ip varchar(50) NOT NULL,
count mediumint(8) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
php:Quote:
//$link = mysqli_connect(...); //success

$car=$_car["car"];
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
$count=0;

if($car && $ip) {
$sql_update="UPDATE cars
SET count = ".++$count."
WHERE car = '$car'"
AND ip = '$ip'";
if(mysqli_query($link, $sql_update)) {
echo "<br>Records were updated successfully.";
}
else {
echo "<br>Not updated ".mysqli_error($link)." ".mysqli_errno($link);
}

} //end if
else {
$sql_insert = "INSERT INTO cars (car, ip, count)
VALUES ('".$car."', '".$ip."', 1);";
if(mysqli_query($link, $sql_insert)) {
echo "<br>Records inserted successfully.";
}
else {
echo "<br>ERROR: Could not able to execute $sql_insert.".mysqli_error($link)." ".mysqli_errno($link);
}
}

// Close connection
mysqli_close($link);

}
That works not. Can you fix it?latest?d=yIl2AUoC8zA latest?i=QSr8CyVeQWU:OwEWSj8Vb0s:F7zBnMy latest?i=QSr8CyVeQWU:OwEWSj8Vb0s:V_sGLiP latest?d=qj6IDK7rITs latest?i=QSr8CyVeQWU:OwEWSj8Vb0s:gIN9vFwQSr8CyVeQWU
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments