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:
output:Quote:
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:
php:Quote:
That works not. Can you fix it?


Minor bug on SQL and PHP. Example I have Car with Volvo.
input:Quote:
https://cars.com?car=Volvo |
cars - ip - count Volvo - 200.0.0.01 - 3 Volvo - 300.5.0.07 - 1 VW - 500.2.0.04 - 1 |
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; |
//$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); } |