php - I can't add IPs to my database. Why? -
so want able add different ips database. is:
if ($stmt = $conn->prepare("update csgo_servers set ips = ips + '$anip' + '|' id = ?")) { $stmt->bind_param("s", $id); $stmt->execute(); $stmt->close(); echo "ip added!"; } i want have different ips in longtext column that: 32.12.53.12|42.12.41.2|42.1.6.3.7. problem when it adds first let's 32.12 of ip , without |. help?
structure of table
mentioned in comments, having character-separated values in database (in case, separator |), bad idea. should normalize database - have more rows instead of doing that. it'll way easier work with!
why won't work is
mysql can't add strings + (like in javascript). that's telling mysql want mathematics (adding integers, e.g 1+1). means you're silently converting integers, why you're seeing first part of ip (the first part before period . integer, rest turnicated).
solution
can use concat() function achieve want - although mentioned above, i advise against structure, add last ip separator |.
with adding new ip bounded placeholder (like bind id), new code this. should bind every variable going query, otherwise it's little pointless.
if ($stmt = $conn->prepare("update csgo_servers set ips = concat(ips, '|', ?) id = ?")) { $stmt->bind_param("ss", $anip, $id); if ($stmt->execute()) echo "ip added!"; $stmt->close(); }
Comments
Post a Comment