Jump to content

comment system


Bojak

Recommended Posts

<!DOCTYPE html> 

<html>
<head>
	<title></title> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());


$result = mysql_query("SELECT comments FROM users");



?>
	</head> 
	
	<body>
		<form name="input" action="" method="get">
		<div id="commentsr">
		<?php
		echo $result["comments"]; 
		?>
		</div> 
		<textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
		<input type="submit" value="Submit">
		</form>
	</body> 
</html>

i am building a comment system that refuses to put the comment in the db and echo the comment to a page. i tried putting the comment in a div. that could also be a wrong way of doing it.

Link to comment
Share on other sites

almost, I have re-written your code.  It uses a few functions you may not have come across - if you don't know them please learn them before using them in your own code - have a look at this, it should work:

<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
$result = mysql_query("SELECT comments FROM users");
while($row = mysql_fetch_assoc($result)){
  if(!isset($dataString)){
    $dataString = $row['comments'];
  }
  else{
    $dataString .= "<br><br>{$row['comments']}";
  }
}

$page = <<<PAGE
<!DOCTYPE html> 
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <form name="input" action="" method="get">
        <div id="commentsr">
              $dataString
        </div>
        <textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
        <input type="submit" value="Submit">
        </form>
    </body> 
</html>
PAGE;
echo $page;
?>

       

Link to comment
Share on other sites

<!DOCTYPE html> 

<html>
<head>
	<title></title> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("user") or die(mysql_error());


// Get all the data from the "example" table
$result = mysql_query("SELECT comments FROM comments") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['comments'];
	echo "</td><td>"; 
	

} 

echo "</table>";

?>
	</head> 
	
	<body>
		<form name="input" action="" method="get">
		
		<textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
		<input type="submit" value="Submit">
		</form>
	</body> 
</html> 


Table 'users.comments' doesn't exist, i dont know why its saying this. thats not even my table name. my table name is users.

Link to comment
Share on other sites

Notice: Undefined variable: dataString in C:\wamp\www\comments.php on line 31

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\comments.php on line 6

 

Muddy_Funster i was given the above errors when trying your code.

Link to comment
Share on other sites

Table 'users.comments' doesn't exist, i dont know why its saying this. thats not even my table name. my table name is users.

 

 

that's because the query in your code in reply #5 doesn't contain the correct table name.

 

 

Notice: Undefined variable: dataString in C:\wamp\www\comments.php on line 31

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\comments.php on line 6

 

Muddy_Funster i was given the above errors when trying your code.

 

the or die(mysql_error()) logic that you do have in the code in reply #5 on the end of the mysql_query() statement, needs to be in your current code to get your code to tell you why the query is failing.

Link to comment
Share on other sites

<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
$result = mysql_query("SELECT comments FROM users");
while($row = mysql_fetch_assoc($result)){
  if(!isset($dataString)){
    $dataString = $row['comments'];
  }
  else{
    $dataString .= "<br><br>{$row['comments']}";
  }
}

$page = <<<PAGE
<!DOCTYPE html> 
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <form name="input" action="" method="get">
        <div id="commentsr">
              $dataString
        </div>
        <textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
        <input type="submit" value="Submit">
        </form>
    </body> 
</html>
PAGE;
echo $page;
?>

mac_gyver where would I add it and what exactly would I add?

Link to comment
Share on other sites

<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
$result = mysql_query("SELECT comments FROM users") or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
  if(!isset($dataString)){
    $dataString = $row['comments'] or die(mysql_error());
  }
  else{
    $dataString .= "<br><br>{$row['commens']}" or die(mysql_error());
  }
}
// http://forums.phpfreaks.com/topic/282059-comment-system/
$page = <<<PAGE
<!DOCTYPE html> 
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <form name="input" action="" method="get">
        <div id="commentsr">
              $dataString
        </div>
        <textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
        <input type="submit" value="Submit">
        </form>
    </body> 
</html>
PAGE;
echo $page;
?>

I changed lines 8, 11, 5 but im getting a new error. ( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\comments.php on line 5

Edited by Bojak
Link to comment
Share on other sites


Notice: Undefined variable: dataString in C:\wamp\www\comments.php on line 31

<?php

// Make a MySQL Connection

mysql_connect("127.0.0.1", "root", "") or die(mysql_error());

mysql_select_db("test") or die(mysql_error());

$result = mysql_query("SELECT comments FROM users") or die(mysql_error());

while($row = mysql_fetch_assoc($result)){

  if(!isset($dataString)){

    $dataString = $row['comments'];

  }

  else{

    $dataString .= "<br><br>{$row['commens']}";

  }

}

 

$page = <<<PAGE

<!DOCTYPE html>

<html>

<head>

    <title></title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>

    <body>

        <form name="input" action="" method="get">

        <div id="commentsr">

              $dataString

        </div>

        <textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>

        <input type="submit" value="Submit">

        </form>

    </body>

</html>

PAGE;

echo $page;

?>

Link to comment
Share on other sites

oops sorry

<?php
// Make a MySQL Connection
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$result = mysql_query("SELECT comments FROM users") or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
  if(!isset($dataString)){
    $dataString = $row['comments'];
  }
  else{
    $dataString .= "<br><br>{$row['commens']}";
  }
}
// http://forums.phpfreaks.com/topic/282059-comment-system/
$page = <<<PAGE
<!DOCTYPE html> 
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <form name="input" action="" method="get">
        <div id="commentsr">
              $dataString
        </div>
        <textarea id="myMessage" name="comments" cols="30" rows="10" style="width: 400px; height: 83px;"></textarea>
        <input type="submit" value="Submit">
        </form>
    </body> 
</html>
PAGE;
echo $page;
?>
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.