Jump to content

Weird error?


MySQL_Narb

Recommended Posts

I've added a code error_reporting(E_ALL);

 

And it gives me this error: Notice: Undefined index: username in /home/commentb/public_html/demo/post.php on line 6

 

<?php require "global_navigation.php"; ?>
<?php

error_reporting(E_ALL);

$name = $_SESSION['username'];
$message = $_POST['message'];

if ($gposting ==0)
{

if ($_SESSION['username'])
  {

$ip = $_SERVER['REMOTE_ADDR'];

//protection
$before = array('^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE');
$after   = array('', '', '', '', '', '', '', '', '', '', '');
$output  = str_replace($before, $after, $message);

$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");

//extract
$extract = mysql_query("SELECT * FROM users WHERE username='$name'");
$numrows = mysql_num_rows($extract);

while ($row = mysql_fetch_assoc($extract))

{
           $banned = $row[banned];
           
if ($banned ==1) {
    echo "Sorry, your account is currently disabled.";
    }
    else
    {

       if (strlen($message)<=$charlong) {
     echo "Your message must be longer then $charlong characters.";
     }
  else
     {

//connect
$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");

//write
$write = mysql_query("INSERT INTO posts VALUES ('','$name','$output', '$ip')") or die(mysql_error());
$postcount = mysql_query("UPDATE users SET post_count = post_count + 1 WHERE username='$name'");

echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='index.php'>View it!</a></b>";
echo "<br /><br />Your IP $ip has been logged for security reasons. (We track all IP's, your information is safe with us! We track IP's to catch spammers.)";
}
}
}
}
else
{
echo "You must be logged in before posting.";
}
}
else
{

$name = $_SESSION['username'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];

if ($name =="") {
   $name = "Guest";
}

//protection
$before2 = array('^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE');
$after2   = array('', '', '', '', '', '', '', '', '', '', '', '', '');
$output2  = str_replace($before2, $after2, $message);

$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");

//extract
$extract = mysql_query("SELECT * FROM users WHERE username='$name'");
$numrows = mysql_num_rows($extract);

while ($row = mysql_fetch_assoc($extract))

{
           $banned = $row[banned];
           
if ($banned ==1) {
    echo "Sorry, your account is currently disabled.";
    }
    else
    {

       if (strlen($message)<=$charlong) {
     echo "Your message must be longer then $charlong characters.";
     }
  else
     {

//write
$write = mysql_query("INSERT INTO posts VALUES ('','$name','$output', '$ip')") or die(mysql_error());
$postcount = mysql_query("UPDATE users SET post_count = post_count + 1 WHERE username='$name'");

echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$output2 - <a href='index.php'>View it!</a></b>";
echo "<br /><br />Your IP $ip has been logged for security reasons. (We track all IP's, your information is safe with us! We track IP's to catch spammers.)";
}
}
}
}
?></font></td>
										</tr>
									</tbody>
								</table></td>
							</tr>
						</tbody>
					</table>
					</td>
				</tr>
			</tbody>
		</table>
		</center>
		<table class="tborder" cellpadding="4" cellspacing="1" width="67%">
			<tbody>
				<tr>
					<td class="thead"><font face="Trebuchet MS"><strong>  
					Copyright</strong></font></td>
				</tr>
				<tr>
					<td class="trow1">
					<table border="0" cellpadding="4" width="100%">
						<tbody>
							<tr>
								<td class="trow1">
								<p align="center">
<span class="smalltext" style="display: inline; visibility: visible; font-family: Trebuchet MS; font-weight: 700">
<a title="Simple Machines Forum" target="_blank" class="new_win" href="http://commentbb.com">
<font size="2">Powered by CommentBB 1.0 BETA</font></a><font size="2"> |
</font><a href="http://commentbb.com"><font size="2">CBB is © 2009, CommentBB 
INC</font></a></span></td>
							</tr>
						</tbody>
					</table></td>
				</tr>
			</tbody>
		</table> </div>
<font face="Trebuchet MS">
<!-- end: footer -->
<!-- end: portal --></font></body></html>

Link to comment
https://forums.phpfreaks.com/topic/179421-weird-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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