Jump to content

Recommended Posts

<?php

include ("database.php");

// show comments

$result = mysql_query("SELECT * FROM gamecomments");

while($row = mysql_fetch_array($result))

  {

  echo $row['username'] . ": <Br> " . $row['comment'];

  echo "<p>";

}

ini_set ("display_errors", "1");

error_reporting(E_ALL);

 

 

 

if (isset($_POST['submit'])) {

 

 

 

        // now we insert it into the database

$insert = "INSERT INTO gamecomments (username, comment)

VALUES ('[$username]', '$_POST[comment]')";

 

$add_comment = mysql_query($insert);

{

echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=games.php\">";

  }

}

Would this work or something like this? need help still \=

<?php
include ("database.php");
// show comments
$result = mysql_query("SELECT * FROM gamecomments");
while($row = mysql_fetch_array($result))
  {
  echo addslashes($row['username']) . ": <Br> " . addslashes($row['comment']);
  echo "<p>";
}
      ini_set ("display_errors", "1");
      error_reporting(E_ALL);
      

      
      if (isset($_POST['submit'])) {
         
      	$username = real_escape_string($username);
		$_POST['comment'] = real_escape_String($comment);
         
           // now we insert it into the database
   $insert = "INSERT INTO gamecomments (username, comment)
   VALUES ('[$username]', '$_POST[comment]')";

   $add_comment = mysql_query($insert);
{
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=games.php\">";
  }
}
[code]

sorry, im really tired \=  so just that like? will prevent sql injection? and protect everything?

<?php
include ("database.php");
// show comments
$result = mysql_query("SELECT * FROM gamecomments");
while($row = mysql_fetch_array($result))
  {
  echo ($row['username']) . ": <Br> " . ($row['comment']);
  echo "<p>";
}
      ini_set ("display_errors", "1");
      error_reporting(E_ALL);
      

      
      if (isset($_POST['submit'])) {
         
         $username = mysql_real_escape_string($username);
		$_POST['comment'] = mysql_real_escape_string($comment);

           // now we insert it into the database
   $insert = "INSERT INTO gamecomments (username, comment)
   VALUES ('[$username]', '$_POST[comment]')";

   $add_comment = mysql_query($insert);
{
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=games.php\">";
  }
}

Where does $username come from?  Echoing row data isn't the same as constructing a variable.  Also, your assignment statement dealing with the comments is backwards.

 

The escape function will protect you from injection, but you should validate all incoming data.  When you display your comments, you'll need to combat against unwanted HTML and XSS attacks.

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.