Jump to content

head first mysql php


phpbiginner

Recommended Posts

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

?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.