• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Leaving comments

cococomics

New Member
Hello everyone. More questions for the photo site. Is there a relatively simple script I can use to let people leave a comment on individual photos? for example:


[heres the picture]
__________________________

[field for name]
[field for comment]
[submit button]

[other peoples' comments]
__________________________


Thanks to anyone that can help. I am trying to learn PHP but i've been told it will take a very long time, and I certainly believe it!
 
Okay well I got it to where the page with the commentbox itself no longer says I have an error, I did it like this. (w/ my password where it says "<my password>")

my code said:
<?php
$sql_host = "localhost"; /*
$sql_login = "fedora_main"; You have to change
$sql_psswd = "<my password>"; these variables...
$sql_base = "fedora_comments"; */
$sql_table = "tbl_comments";
$id = addslashes($_GET["id"]);
$id = htmlentities($id);
$nickname = addslashes($_POST["nickname"]);
// Remember that we use post method
$nickname = htmlentities($nickname);
$comment = addslashes($_POST["comment"]);
$comment = htmlentities($comment);
$host = $_SERVER["REMOTE_ADDR"];
$date = date("Y-m-d");
$time = date("H:i");
if ($nickname && $comment && $id)
{ $db = mysql_connect($sql_host, $sql_login, $sql_psswd);
mysql_select_db($sql_base, $db);
$sql = "INSERT INTO $sql_table(id, Number, Comment, Information, RemoteIP) VALUES('', '$id', '$comment', '$nickname ($date @ $time)', '$host')";
mysql_query($sql) or die("MySQL Error");
mysql_close();
echo "<script>window.location = 'comments.php?id=".$id."</script>";
}
?>


<?php
$dbh=mysql_connect ("localhost", "fedora_main", "titanic") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("fedora_comments");
mysql_select_db("fedora_main, fedora_comments");
$sql = "SELECT * FROM tbl_comments WHERE Number = '$id' ORDER BY id Desc";
$req = mysql_query($sql) or die("<font size=\"1\" face=\"Verdana\" color=\"#FF0000\">Sorry, a MySQL error occurred!");
$res = mysql_numrows($req);
if($res == 0) { echo "<center><font size=\"2\" face=\"Verdana\"><i>No comment.</i></center>"; }
while($data = mysql_fetch_array($req))
{ echo "<table width=\"350\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\">
<tr><td bgcolor=\"#000000\">
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#434343\">
<tr><td><font size=\"1\" face=\"Verdana\">Comment from ".stripslashes($data['Information'])." :<br>
<i>".stripslashes($data['Comment'])."</i>
</td></tr></table></td></tr></table><br>\n";
}
mysql_close();
?>

<form name="addcomment" method="post">
<table width="350" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="150">Name:</td>
<td><input name="nickname" type="text" size="30"></td>
</tr>
<tr>
<td>Comment:</td>
<td><input name="comment" type="text" size="30" height="25"></td>
</tr>
<tr>
<td></td>
<td><input name="reset" type="reset" value="Clear">
<input name="post" type="submit" value="Submit"></td>
</tr>
</table>
</form>

However, Now, when I type in a name and comment, and press submit, It goes to a page that simply says 'MySQL Error'. Does anyone see anything wrong with my code above? I am quite new at this, so my guess is there's something wrong with it. Thanks!
 
jstgermain said:
where can I get cutnews?
http://cutephp.com/cutenews/

cococomics said:
However, Now, when I type in a name and comment, and press submit, It goes to a page that simply says 'MySQL Error'. Does anyone see anything wrong with my code above? I am quite new at this, so my guess is there's something wrong with it. Thanks!

I'm not too good in PHP, but I think you should try posting help to the person who wrote the script. Maybe showing us the page might help?
 
Last edited:
The page I put the code above for is at http://www.fedoraphotos.com/Photos/comments.php . The page where the tutorial was, was mentioned in a link above. http://www.h07.net/?view=tutorials&act=tutorial&id=1 . I will send an email to the person who wrote it, but in the meantime, is there anyone here who can see my problem? I did everything the tutorial said, step by step, and it didn't work, so i changed my code to what was above, and it seemed to work but came up with the error I described up there.
 
cococomics said:
The page I put the code above for is at http://www.fedoraphotos.com/Photos/comments.php . The page where the tutorial was, was mentioned in a link above. http://www.h07.net/?view=tutorials&act=tutorial&id=1 . I will send an email to the person who wrote it, but in the meantime, is there anyone here who can see my problem? I did everything the tutorial said, step by step, and it didn't work, so i changed my code to what was above, and it seemed to work but came up with the error I described up there.

I think I found the error. The second PHP part of the script, you weren't suppose to edit any of it, what I mean is, you were just suppose to copy and paste it:

PHP:
<?php 
$db = mysql_connect($sql_host, $sql_login, $sql_psswd); 
mysql_select_db($sql_base, $db); 
$sql = "SELECT * FROM $sql_table WHERE Number = '$id' ORDER BY id Desc"; 
$req = mysql_query($sql) or die("<font size=\"1\" face=\"Verdana\" color=\"#FF0000\">Sorry, a MySQL error occurred!"); 
$res = mysql_numrows($req); 
if($res == 0) { echo "<center><font size=\"2\" face=\"Verdana\"><i>No comment.</i></center>"; } 
while($data = mysql_fetch_array($req)) 
{ echo "<table width=\"350\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\"> 
<tr><td bgcolor=\"#000000\"> 
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#434343\"> 
<tr><td><font size=\"1\" face=\"Verdana\">Comment from ".stripslashes($data['Information'])." :<br> 
<i>".stripslashes($data['Comment'])."</i> 
</td></tr></table></td></tr></table><br>\n"; 
} 
mysql_close(); 
?>

Whereas, you edited this part:

PHP:
$db = mysql_connect($sql_host, $sql_login, $sql_psswd); 
mysql_select_db($sql_base, $db);

With your own info, you weren't suppose to do that. The part you only edit with your own MySQL info, is the top PHP part of the code:

PHP:
$sql_host = "xxxxxxxx"; /* 
$sql_login = "xxxxxxxx"; You have to change 
$sql_psswd = "xxxxxxxx"; these variables... 
$sql_base = "xxxxxxxx"; */

Hope that made sense.

jstgermain said:

No prob.

LYT-Michael said:
Coppermine or Gallery?

Huh?
 
PHP:
$sql_host = "xxxxxxxx";
$sql_login = "xxxxxxxx"; // You have to change
$sql_psswd = "xxxxxxxx"; // these variables...
$sql_base = "xxxxxxxx";

Make sure that you take out the comment marks (/* and */) too. I just changed them to // in the above code.
 
Back
Top