Well I gues it's usefull for starting to learn.But there are many opensource guestbooks outhere.Look at this one: http://nrg88.4ya.us/page_8_1.html
One of my friends has made it.
It's good if you're a newby in php.



lyndz wrote:how could i view the queries?
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);

Rommaster wrote:lyndz wrote:how could i view the queries?
What queries do you mean?
- Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);


lyndz wrote:Rommaster wrote:lyndz wrote:how could i view the queries?
What queries do you mean?
- Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);
I mean, how can I view the Signees to the page? I already tried it but, process.php return nothing

<form action="guestbook.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Comments: <textarea rows="6" name="comments" cols="27"></textarea>
<input type="Submit" name="submit">
</form>
<br>
<?php
isset($_POST['submit']) ? WriteEntry() : DisplayEntries();
function WriteEntry() {
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments'])) {
str_replace("!", "!", $_POST);
$string = $_POST['name'] . "!" . $_POST['email'] . "!" . $_POST['comments'] . "\r\n";
$handle = fopen("guestbook.txt", "ab");
fwrite($handle, $string);
fclose($handle);
DisplayEntries();
} else {
print "Please fill in all fields<br>";
DisplayEntries();
}
}
function DisplayEntries() {
$string = @file("guestbook.txt");
if (!$string) {
die();
}
foreach ($string as $i) {
trim($i);
list($name, $email, $comments) = explode("!", $i);
print "<hr><br><b>Name:</b> " . $name . "<br><b>Email:</b> " . $email . "<br><b>Comments:</b> " . $comments . "<br>";
}
}
?>

chiron wrote:Your forgetting about the people without access to MySQL. Flat file databases are the way foward.
- Code: Select all
<form action="guestbook.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Comments: <textarea rows="6" name="comments" cols="27"></textarea>
<input type="Submit" name="submit">
</form>
<br>
<?php
isset($_POST['submit']) ? WriteEntry() : DisplayEntries();
function WriteEntry() {
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments'])) {
str_replace("!", "!", $_POST);
$string = $_POST['name'] . "!" . $_POST['email'] . "!" . $_POST['comments'] . "\r\n";
$handle = fopen("guestbook.txt", "ab");
fwrite($handle, $string);
fclose($handle);
DisplayEntries();
} else {
print "Please fill in all fields<br>";
DisplayEntries();
}
}
function DisplayEntries() {
$string = @file("guestbook.txt");
if (!$string) {
die();
}
foreach ($string as $i) {
trim($i);
list($name, $email, $comments) = explode("!", $i);
print "<hr><br><b>Name:</b> " . $name . "<br><b>Email:</b> " . $email . "<br><b>Comments:</b> " . $comments . "<br>";
}
}
?>


Users browsing this forum: No registered users and 1 guest