seany123 Posted November 22, 2008 Share Posted November 22, 2008 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 https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/ Share on other sites More sharing options...
dezkit Posted November 22, 2008 Share Posted November 22, 2008 Why would you have a header() statement on top of the page...? Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696334 Share on other sites More sharing options...
gevans Posted November 22, 2008 Share Posted November 22, 2008 <?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 https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696337 Share on other sites More sharing options...
seany123 Posted November 22, 2008 Author Share Posted November 22, 2008 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 https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696344 Share on other sites More sharing options...
gevans Posted November 22, 2008 Share Posted November 22, 2008 You didn't answer anything you were just asked. Hve you tried simply getting ride of the header at the start of your code? Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696349 Share on other sites More sharing options...
seany123 Posted November 22, 2008 Author Share Posted November 22, 2008 yes. it shows a white page. Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696355 Share on other sites More sharing options...
gevans Posted November 22, 2008 Share Posted November 22, 2008 try putting the header at the bottom of the page, that way your script will run then the page will be forwarded Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696361 Share on other sites More sharing options...
seany123 Posted November 22, 2008 Author Share Posted November 22, 2008 when i remove the header. it just gives me a white page.. i then check my database and it doesnt change anything. so having header at the bottom of the page wont change anything.. i will try though. Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696363 Share on other sites More sharing options...
seany123 Posted November 22, 2008 Author Share Posted November 22, 2008 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 https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696369 Share on other sites More sharing options...
samona Posted November 22, 2008 Share Posted November 22, 2008 you can't use the header() function when you have already sent output Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696382 Share on other sites More sharing options...
revraz Posted November 22, 2008 Share Posted November 22, 2008 The reason you get a white page is because you have errors in your code. You need to turn error reporting on and display them, so you can fix your code. Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696388 Share on other sites More sharing options...
seany123 Posted November 22, 2008 Author Share Posted November 22, 2008 The reason I have a white page is surely because im not asking for anything to be displayed. where do i turn error reporting on? on my host? Link to comment https://forums.phpfreaks.com/topic/133800-help-using-php-to-update-mysql-databases/#findComment-696389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.