Jump to content
MakeWebGames

Recommended Posts

Posted

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);
?> 
Posted

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

Posted

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 :)

Posted

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

Posted

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;
Posted

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);
?> 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...