Jump to content

Recommended Posts

Everytime I try and post as a guest, when guest positing is enabled, It never seems to do anything besides give me a blank page. http://www.commentbb.com/demo/testing/

 

Why is this?

 

Code:

 

<?php session_start(); ?>
<?php require "global_settings.php"; ?>
<title><?php echo $sitetitle; ?></title>
<center><style type="text/css">

a:link {
color:#24374C;
text-decoration:bold;
}

a:visited {
color:#24374C;
text-decoration:bold;
}

a:active {
outline: none;
color:#24374C;
text-decoration:bold;
}

body {background-color:#b0c4de}

div.box {
width:250px;
padding:10px;
border:3px double #000000;
margin:10px;
background-color:#74AFF2;
}

p
{
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dotted;
border-left-style:solid;
}

div.menu-blue {
BORDER-RIGHT: #333366 1px solid;
BORDER-LEFT: #6699cc 1px solid;
BORDER-TOP: #6699cc 1px solid;
BORDER-BOTTOM: #333366 1px solid;

FONT-WEIGHT: normal;
FONT-SIZE: 2px;
COLOR: #ffffff;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
BACKGROUND-COLOR: #23559C;
TEXT-DECORATION: none;
font-stretch : condensed;
}

.menu-top  {
BORDER-RIGHT: 1px solid #333366; BORDER-TOP: 1px solid #6699CC; FONT-WEIGHT: normal; FONT-SIZE: 2px; BORDER-LEFT: 1px solid #6699CC; COLOR: #FFFFFF; BORDER-BOTTOM: 1px solid #333366; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none;
font-stretch : condensed
}

</style>
<center>
<div class='menu-blue'>
<div align="center"> 
<table width="600" cellspacing="1" cellpadding="5" style="background-color:#23559C"> 
<tr> 
<td style="background-color:#FFFFFF"> 


    <div align="center"> 
    <table border="0"> 
    
    </form> 
    </table>
<?php

$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
$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.)";
}
}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/179126-why-doesnt-this-code-work/
Share on other sites

i agree.

 

showing all your CSS, etc., is gonna lose me every time.

 

does seem that you have several parts of your script written multiple times in there.  i can see your $before and $after arrays are defined twice.

 

look deeply into indenting your code.  will get you many more responses since this is not paid help, and the majority of people don't have hours upon hours of time to scour through roughly written code for you.

Fixed what you've stated above

 

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

$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('', '', '', '', '', '', '', '', '', '', '', '', '');
$output  = 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
     {

//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>$output - <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>

Put "error_reporting(E_ALL);" at the beginning of all of your scripts.  You may have errors that are not being reported.  If you get errors, post those and we can be more helpful.

 

Here are a couple of issues with that code.  I do not think any of these is causing the problem, but without the error messages, there's not much more we can say.

 

You are connecting to the database all over the place.  Do it only one, at the top of the script, before you even test if posting is allowed.  You only need one connection.

 

You do not need that while loop for users.  You should be getting only one user back, right?  If you get more than one, you will be posting the message more than once.

 

Your HTML does not look right.  You have no HEAD or BODY statements.  TITLE belongs in the HEAD, so does the style sheet (I think) but the rest should be in the BODY (why is the STYLE sheet CENTERed?):

<HTML>
<HEAD>
<TITLE>My Name</TITLE>
... other HEAD stuff here too
<STYLE>...</STYLE>
</HEAD>
<BODY>
... a while bunch of stuff here ...
</BODY>
</HTML>

 

Clean up the code a little, run it with error checking and post the results.  Also, when you get a blank page, use the "View Source" capability of your browser.  That will show you what the PHP script actually sent to the browser which may have an indication of why you don't see anything.

 

Above all else, be patient!  This is not the FREEK SQUAD Help Desk  :hail_freaks:.  We are responding in our spare time.

This reminds me of this quote.

“Debugging is twice as hard as writing the code in the first place.  Therefore, if you write the code as cleverly as possible, you are–by definition–not smart enough to debug it.”

(Brian Kernighan)

 

This means if you use 100% of your IQ/Skill to write a script and it has a bug, You will need 100% more Skill and IQ which you don't have to debug it. Your are now requiring the expertize of someone smarter then you.  xD

Still not working dude.

I don't know what to say.  Usually, my psychic powers of fixing code I can't see to remove errors I haven't been told about are perfect.  Did you read what I said in my last post?

 

Clean up the code a little, run it with error checking and post the results.

 

 

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.