Jump to content

help using php to update mysql databases


seany123

Recommended Posts

okay so basically i want for a page to update mysql databse.

 

i want it to take away 1000 from $player->money.

and i want it to change the value of $player->city_id to 2.

 

This is the script ive tried out but it just redirects and nothing else happens.

 

<?php
header("Location: http://www.URL.com");
?>
<?php
include("lib.php");
define("PAGENAME", "Travel2");
?>

<?php
{
$query = $db->execute("update `players` set `money`=?, `city_id`=2 where `id`='player['id']'", array($player->money - 1000));
}
?>

<?php
header("Location: http://www.URL.com"); //the first thing your page does is redirect the user, do you need this?

include("lib.php");
define("PAGENAME", "Travel2");


$query = $db->execute("UPDATE players SET money='?', city_id=2 WHERE id='player[id]'", array($player->money - 1000));

?>

 

Does lib.php have a databse connection and a class that you've assigned to $db??

 

and execute should be a function, can you post it?

my functions.php

 


<?php

//Function to check if user is logged in, and if so, return user data as an object
function check_user($secret_key, &$db)
{
if (!isset($_SESSION['userid']) || !isset($_SESSION['hash']))
{
	header("Location: index.php");
	exit;
}
else
{
	$check = $_SESSION['userid'] . $_SERVER['REMOTE_ADDR'] . $secret_key;
	if ($check != $_SESSION['hash'])
	{
		session_unset();
		session_destroy();
		header("Location: index.php");
		exit;
	}
	else
	{
		$query = $db->execute("select * from `players` where `id`=?", array($_SESSION['userid']));
		$userarray = $query->fetchrow();
		if ($query->recordcount() == 0)
		{
			session_unset();
			session_destroy();
			header("Location: index.php");
			exit;
		}
		foreach($userarray as $key=>$value)
		{
			$user->$key = $value;
		}
		return $user;
	}
}
}

//Gets the number of unread messages
function unread_messages($id, &$db)
{
$query = $db->getone("select count(*) as `count` from `mail` where `to`=? and `status`='unread'", array($id));
return $query['count'];
}

//Gets new log messages
function unread_log($id, &$db)
{
$query = $db->getone("select count(*) as `count` from `user_log` where `player_id`=? and `status`='unread'", array($id));
return $query['count'];
}

//Insert a log message into the user logs
function addlog($id, $msg, &$db)
{
$insert['player_id'] = $id;
$insert['msg'] = $msg;
$insert['time'] = time();
$query = $db->autoexecute('user_log', $insert, 'INSERT');
}

?>

 

okay when putting the Header() at the bottom of the page i get this error...

 

 

Warning: Cannot modify header information - headers already sent by (output started at /home/www/-------/------.php:6) in /home/www/-------/------.php on line 13.

 

line 13 is the header()

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.