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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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');
}

?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.