please post all of your code
please post all of your code
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Okay, I have 3 pages right now... test.php, submit.php, comments.txt
Here is what is on my test.php page (I am withholding my database link and pswd). I think that I must have some words/pages mixed up.
<h1>Comments</h1>
<?php
// read comments from the database, a text file, a xml file, whatever
// loop through comments, and for each one:
echo "<p>".$comment['text']."</p>";
?>
<?php
$conn = mysql_connect("database_link","revelation13","password");
mysql_select_db("revelation13",$conn);
// get all the rows from the table named 'revelation13' in the database 'revelation13'
$getCommentsQuery = mysql_query("SELECT * FROM comments");
// this loops through the results from the query
while($row = mysql_fetch_array($getCommentsQuery)) {
// $row will be an associative array of data for a row during each iteration
// print the data that's in the column 'comments'
echo "<p>".$row['comments']."</p>";
}
?>
<form method="post" action="submit.php">
<p>Name: <input type="text" name="name" /></p>
<p>Comment:</p>
<textarea rows="5" cols="40" name="comment"></textarea>
<p><input type="submit" value="Post Comment" />
</form>
<?php
foreach (file('comments.txt') as $comment) {
echo $comment.'<br><hr><br>';
}
?>
Here is what is on my submit.php page:
<?php
if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
$file=fopen("comments.txt","r+");
$contents=fread($file,filesize("comments.txt")+1);
$contents=$contents."\n[".$_POST['name']."]".$_POST['comments'];
fwrite($file,$contents);
fclose($file);
}
?>
<?php
if(isset($_REQUEST['name']) && isset($_REQUEST['comment'])) {
$conn = mysql_connect("database_link","revelation13","password");
mysql_select_db("revelation13",$conn);
mysql_query("INSERT INTO comments (name, comment) VALUES('".mysql_real_escape_string($_REQUEST['name'])."', '".mysql_real_escape_string($_REQUEST['comment'])."' ");
echo "Thank you, your comment has been submitted.";
}
?>
<?php
if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
$file=fopen("comments.txt","r+");
$contents=fread($file,filesize("comments.txt")+1);
$contents=$contents."\n[".$_POST['name']."]".$_POST['comments'];
fwrite($file,$contents);
fclose($file);
header("Location: http://wwww.propheciesofrevelation.org/test.php");
}
?>
My comments.txt page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title></title>
</head>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
Comment:<br>
<textarea name="comments"></textarea>
<input type="submit" name="submit" value="Send">
</form>
</html>
I've been thinking about your question of what page I want to return to after submit. I would like for the page to return to the page where the person types in their post, the page where I intend to have other html on the page. I want to be able to see the post immediately after submitting.
How do I get it to do that?
Because when I write in the test.php page where comments.txt is now, the page goes only to the submit.php page after clicking on submit.
Dre
you might want to look over your code, you're trying to write it to a database and a text file, but the text file looks like it contains html when it shouldn't contain anything but what the php file wrote to it. try going back to page 2 where i give you a script. don't combine it with mysql and read all of the instructions and comments.
change read.php:
with:Code:for($a=0;$a<count($contents);$a++) { $formated_comments.=preg_replace("^/\[(.*?)\](.*?)/$",$format[1].'$1'.$format[2].$format[3].'$2'.$format[4],$contents[$a]); } $formated_comments.=$format[0]; ?>
Code:for($a=0;$a<count($contents);$a++) { $formated_comments.=preg_replace("^/\[(.*?)\](.*?)/$",$format[1].'$1'.$format[2].$format[3].'$2'.$format[4],$contents[$a]); } $formated_comments.=$format[5]; ?>
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Okay, I re-read everything. I removed the database info from everything again. And, I changed the code in the read.php file. I removed everything from the comments.txt page but it seems like that page is not doing anything. Are the comments supposed to appear on comments.txt?
Can I place the "example form" on the same page where I want to "echo the comments"?
I tried that and then I get this error: Warning: preg_replace(): No ending delimiter '^' found in /home/content/b/e/n/benedizione/html/read.php on line 30
Dre
Here is the working, customizable code. It will create comments.txt so you don't have to. The table's class is comments, the td's class that contains the name is name, and the td's class that contains the comment is text.
Last edited by Master_script_maker; 02-25-2008 at 08:58 PM.
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Benedizione (02-26-2008)
PHP Code:<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<div id="container">
<p><a href="..">Back to Tests</a></p>
<p>
If you submit a piece of text, this page will modify itself.<br />
</p>
<!-- COMMENTS START -->
<!-- COMMENTS END -->
<form method="post" action="write.php">
<textarea name="content" cols="20" rows="6">Test 1234</textarea>
<input type="submit" value="Submit" />
</form>
</div>
</body>
</html>PHP Code:<?php
if(isset($_POST["content"])) {
$content = $_POST["content"];
$content = strip_tags($content);
$fc = file_get_contents("index.php");
$seek = "<!-- COMMENTS START -->";
$start = stripos($fc,$seek)+strlen($seek)+1;
$split = explode($seek,$fc);
$split[0] .= "\n<p>" . $content."</p>";
$split = implode($seek,$split);
$h = fopen("index.php","w+");
fwrite($h,$split);
fclose($h);
Header("Location: index.php");
}
?>
Do I need to type in "propheciesofrevelation.org" where it says "localhost"? Or do I just leave that?
<?php
if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
if(!is_file("comments.txt")) {
$write=fopen("comments.txt","x+");
fclose($write);
}
$file=fopen("comments.txt","r+");
$contents=fread($file,filesize("comments.txt")+1);
$contents=$contents."\n[".$_POST['name']."]".$_POST['comments'].";";
fwrite($file,$contents);
fclose($file);
header("Location: http://localhost/comment/form.php");
}
?>
Bookmarks