phpbiginner Posted May 8, 2011 Share Posted May 8, 2011 hey guys how you doing? I've been having a little bit of problem with php, in fact I'm frustrated, so please if you can help me in any tight of way, please do, I've been trying to make this php code work, but it won't, i don't know what I'm doing wrong, I'm new to php and mysql every time i try it, it saids one thing Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\siteN\approvescore.php:3) in C:\xampp\htdocs\siteN\authorize.php on line 17 <?php require_once ('authorize.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - Approve a High Score</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Guitar Wars - Approve a High Score</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_GET['id']) && isset($_GET['date']) && isset($_GET['name']) && isset($_GET['score'])) { // Grab the score data from the GET $id = $_GET['id']; $date = $_GET['date']; $name = $_GET['name']; $score = $_GET['score']; $screenshot = $_GET['screenshot']; } else if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['score'])) { // Grab the score data from the POST $id = $_POST['id']; $name = $_POST['name']; $score = $_POST['score']; } else { echo '<p class="error">Sorry, no high score was specified for approval.</p>'; } if (isset($_POST['submit'])) { if ($_POST['confirm'] == 'Yes') { // Connect to the database $dbc = mysqli_connect('localhost', '999', 'adsd', 'guitarwars3'); // Approve the score by setting the approved column in the database $query = "UPDATE gtwars1 SET approved = 1 WHERE id = $id"; mysqli_query($dbc, $query); mysqli_close($dbc); // Confirm success with the user echo '<p>The high score of ' . $score . ' for ' . $name . ' was successfully approved.'; } else { echo '<p class="error">Sorry, there was a problem approving the high score.</p>'; } } else if (isset($id) && isset($name) && isset($date) && isset($score)) { echo '<p>Are you sure you want to approve the following high score?</p>'; echo '<p><strong>Name: </strong>' . $name . '<br /><strong>Date: </strong>' . $date . '<br /><strong>Score: </strong>' . $score . '</p>'; echo '<form method="post" action="approvescore.php">'; echo '<img src="' . GW_UPLOADPATH . $screenshot . '" width="160" alt="Score image" /><br />'; echo '<input type="radio" name="confirm" value="Yes" /> Yes '; echo '<input type="radio" name="confirm" value="No" checked="checked" /> No <br />'; echo '<input type="submit" value="Submit" name="submit" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="hidden" name="name" value="' . $name . '" />'; echo '<input type="hidden" name="score" value="' . $score . '" />'; echo '</form>'; } echo '<p><a href="admin.php"><< Back to admin page</a></p>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/ Share on other sites More sharing options...
fugix Posted May 8, 2011 Share Posted May 8, 2011 Can you show me the specific line that the error is referring to please Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212215 Share on other sites More sharing options...
trq Posted May 8, 2011 Share Posted May 8, 2011 If you posted your thread in the correct board you may have seen the massive sticky thread HEADER ERRORS - READ HERE BEFORE POSTING THEM which contains invaluable information on the exact cause of this very common new comer error. Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212239 Share on other sites More sharing options...
spiderwell Posted May 8, 2011 Share Posted May 8, 2011 If you posted your thread in the correct board you may have seen the massive sticky thread HEADER ERRORS - READ HERE BEFORE POSTING THEM which contains invaluable information on the exact cause of this very common new comer error. frustration? lol basically certain functions in php will not work if parts of the page have been sent to the browser, so you have to 'buffer' the output to prevent this. Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212265 Share on other sites More sharing options...
trq Posted May 8, 2011 Share Posted May 8, 2011 basically certain functions in php will not work if parts of the page have been sent to the browser, so you have to 'buffer' the output to prevent this. Or layout your code in a more logical manner. Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212278 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 basically certain functions in php will not work if parts of the page have been sent to the browser, so you have to 'buffer' the output to prevent this. Buffering the output is, in my opinion, a bad solution to this problem and adds unnecessary overhead and possible conflicts. The better solution is making sure things like sessions and headers are dealt with before any output is sent, and removing any BOMs from UTF-8 encoded files. Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212282 Share on other sites More sharing options...
spiderwell Posted May 8, 2011 Share Posted May 8, 2011 i agree with above, i do all my php execution before <html> just saves a lot of bother Quote Link to comment https://forums.phpfreaks.com/topic/235809-head-first-mysql-php/#findComment-1212312 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.