skizzy Posted December 5, 2010 Share Posted December 5, 2010 im currently working on a new game and i can't seem to get this code to update a field in my db. can some please help me with this <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $gip=make_ip(); function make_ip(){ $inum1 = rand(0,255); $inum2 = rand(0,255); $inum3 = rand(0,255); $inum4 = rand(0,255); $ip = $inum1.'.'.$inum2.'.'.$inum3.'.'.$inum4; return $ip; } echo "Ip set to"; echo make_ip(); mysql_query("UPDATE users set Gameip=$gip WHERE userid=$userid",$c); ?> Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 5, 2010 Share Posted December 5, 2010 whats the error? Have you added Gameip to the users table? Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 there is no error and i added it to the table as it shows the ip my header but wontupdate the ip with the new the generated ip for the game im making Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 5, 2010 Share Posted December 5, 2010 change mysql_query("UPDATE users set Gameip=$gip WHERE userid=$userid",$c); To this: mysql_query("UPDATE `users` SET `Gameip` = ", $gip ," WHERE (`userid` = ". $userid .");",$c) or die(mysql_error()); Then see if it displays an error, and post back :) Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 here is the error i get after changing that Warning: mysql_query() expects at most 2 parameters, 4 given in C:\xampp\htdocs\ip.php on line 28 Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 5, 2010 Share Posted December 5, 2010 My bad, try this: mysql_query("UPDATE `users` SET `Gameip` = ". $gip ." WHERE (`userid` = ". $userid .");",$c) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 here is the error i get now Ip set to131.16.117.95You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.141.211 WHERE (`userid` = 1)' at line 1 Quote Link to comment Share on other sites More sharing options...
Lithium Posted December 5, 2010 Share Posted December 5, 2010 the original code ought to work... unless table is gameip (which i believe it is) and you are calling Gameip... Tables are case sensitive in most cases... also one minor detail... echo "Ip set to"; echo make_ip(); you are echoing one fake IP that ought to be set off though you already had one... so the correct line there ought to be... echo "Ip set to ".$gip; Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 well now i dont get any error but still wont update the db and the field GameIP is Correct <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $gip=make_ip(); function make_ip(){ $inum1 = rand(0,255); $inum2 = rand(0,255); $inum3 = rand(0,255); $inum4 = rand(0,255); $ip = $inum1.'.'.$inum2.'.'.$inum3.'.'.$inum4; return $ip; } echo "Ip set to ".$gip; mysql_query("UPDATE users set GameIP=$gip WHERE userid=$userid",$c); ?> Quote Link to comment Share on other sites More sharing options...
Lithium Posted December 5, 2010 Share Posted December 5, 2010 hmmm... GameIP field type is... INT? if it is... there lays your problem. change it to VARCHAR(15) and you might have your issue solved... Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 already is been since i made the field Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 5, 2010 Share Posted December 5, 2010 I know, change the old query to this one: ysql_query("UPDATE `users` SET `Gameip` = '". $gip ."' WHERE (`userid` = ". $userid .");",$c) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
skizzy Posted December 5, 2010 Author Share Posted December 5, 2010 thank you danny that worked great Quote Link to comment Share on other sites More sharing options...
Lithium Posted December 5, 2010 Share Posted December 5, 2010 @Danny: your query is exactly the same (yet tidier) so it won't make a a difference. Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 5, 2010 Share Posted December 5, 2010 is it -.- Notice the ' and ' kthxbi Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.