godsent Posted March 28, 2009 Share Posted March 28, 2009 I dont really know how to define my problem name, this is makes me go crazy and put my hairs out of my head. Ok i got function to turn IP into some user ID function getID($ip) { $try = explode('.', $ip); $id = $try[0] + $try[1] + $try[2] + ($try[3] * 2) - 13; return $id; } So with 127.0.0.1 it should be: 116, if i echo getId($ip); it shows correctly 116. BUT then im trying to save it into SQL it always saves 103!!! I have no idea why, and can't find problem. I feel so stupid The whole code looks like this: <?php $c = $_GET['c']; $nick = htmlspecialchars($_POST['nickname']); $comment = htmlspecialchars($_POST['comment']); $date[0] = date('Y-m-d h:i'); $date[1] = date('Y-m-d'); $ip = $_SERVER['REMOTE_ADDR']; $id = getID($ip); echo $id; //Says 116 its OK! if (strlen($nick) > 15) { $message = "Nick too long (LIMIT: 15)"; } else { if ($c == 1 && $nick != NULL && $comment != NULL) { $read_first = @mysql_query("SELECT * FROM `list` WHERE `name` = '$nick'"); $column = @mysql_fetch_array($read_first); $bans = $column['bans']; $ips = $column['ips']; $newAction = "$ips $ip"; $futureAction = $bans+1; if (equalsWith($ip, $ips)) { $message = "You can report same user one time only."; $stop = true; } if ($stop != true) { $query = "SELECT * FROM list WHERE `name` ='$nick';"; $res = mysql_query($query); if (mysql_num_rows($res) != 0) { mysql_query("UPDATE list SET bans = bans-1 WHERE name ='$nick'"); $message = "<a href='?do=users&view=$nick'>$nick</a> already reported $futureAction kartus."; } else { mysql_query("INSERT INTO list (name, bans, dates, ips) VALUES('$nick', '-1', '$date[1]', '$ip' ) ") or die(mysql_error()); $message = "<a href='?do=users&view=$nick'>$nick</a> reported succesfuly."; } mysql_query("INSERT INTO comments (name, comment, date, poster) VALUES('$nick', '$comment', '$date[0]', "$id') ") or die(mysql_error()); mysql_query("UPDATE list SET ips = '$newAction' WHERE name ='$nick'"); } } else { $message = "Fill all gaps."; } } ?> This is insane, where is no problem in my code, i have no idea what the problem is Link to comment https://forums.phpfreaks.com/topic/151497-stupid-problem/ Share on other sites More sharing options...
Kieran Menor Posted March 28, 2009 Share Posted March 28, 2009 mysql_query("INSERT INTO comments (name, comment, date, poster) VALUES('$nick', '$comment', '$date[0]', "$id') ") or die(mysql_error()); I see a start quote/end quote mismatch there. Link to comment https://forums.phpfreaks.com/topic/151497-stupid-problem/#findComment-795702 Share on other sites More sharing options...
dpacmittal Posted March 28, 2009 Share Posted March 28, 2009 Did you copy-paste the code? if so, there's a double quote instead of single quote in front of $id. this: mysql_query("INSERT INTO comments (name, comment, date, poster) VALUES('$nick', '$comment', '$date[0]', "$id') ") or die(mysql_error()); should be this: mysql_query("INSERT INTO comments (name, comment, date, poster) VALUES('$nick', '$comment', '$date[0]', '$id') ") or die(mysql_error()); Other than this, I didnt find anything wrong with the code. Link to comment https://forums.phpfreaks.com/topic/151497-stupid-problem/#findComment-795703 Share on other sites More sharing options...
godsent Posted March 28, 2009 Author Share Posted March 28, 2009 close please, problem was that i was saving ID to sql not the IP Link to comment https://forums.phpfreaks.com/topic/151497-stupid-problem/#findComment-795709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.