User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » comment box question Page [1]  
baonest
All American
47902 Posts
user info
edit post

ok, so i kinda found this script online.
this is for a personal site, just for fun. now, everything works, but how do i get the comment to show up on the website "something.php"? i can get up to when i click submit it will goto the website but then it will not show any comments.
i am using dreamweaver. i figured that i had to make a .php page so the comments can goto that.

help with a n000b

<h2 id="respond">Leave a Comment</h2>


<form action="something.php" method="post" id="commentform">


<p>
<input type="text" name="author" id="author" value="" size="30" tabindex="1" />
<label for="author">Name</label>

</p>

<p>
<input type="text" name="email" id="email" value="" size="30" tabindex="2" />
<label for="email">E-mail</label>
</p>

<label for="email">Comment</label>
<br />
<textarea name="comment" id="comment" cols="70" rows="10" tabindex="4"></textarea>
</p>

<p>
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
</p>

</form>

[Edited on May 15, 2008 at 11:19 AM. Reason : ]

5/15/2008 11:18:43 AM

baonest
All American
47902 Posts
user info
edit post

is there something i have to do to the "something.php" page? to make it accept the comments?

5/15/2008 11:25:03 AM

Fry
The Stubby
7781 Posts
user info
edit post

php code in something.php needs to get the post variables.

so to display a page that just says whatever was put in the "Name" text field:

<?php

echo $_POST['author'];

?>

where inside the brackets is the value of the name tag in the input. $_POST is an array of values passed by a form that uses method="post"

[Edited on May 15, 2008 at 11:27 AM. Reason : note: this data won't be saved unless you write to a file or saved to a db]

5/15/2008 11:26:31 AM

baonest
All American
47902 Posts
user info
edit post

hah, cool. ok so i kinda got the idea.

now i just gotta find out how it saves so it doesnt get re-written each time someone leaves a comment.

so when i find a way to save, that will give me the chance to also go into the .php file and erase test comments and stuff?

5/15/2008 11:45:49 AM

quagmire02
All American
44225 Posts
user info
edit post

in order to save anything submitted (to pull back up later), you're going to need a database of some sort...the easiest thing to do in this case might be a flat XML file or something

5/15/2008 12:01:35 PM

Fry
The Stubby
7781 Posts
user info
edit post

Quote :
"so when i find a way to save, that will give me the chance to also go into the .php file and erase test comments and stuff?"


this could only be done if you wrote directly to file.. which you probably don't want to even get started on. you'll want to learn how to set up a database ^ and probably use MySQL to do that. once you understand that, you'll see that you can delete the comments or whatever else you load into the database from the database-side versus a text file.

5/15/2008 12:10:44 PM

baonest
All American
47902 Posts
user info
edit post



time to read some online tutorials!

5/15/2008 12:18:59 PM

baonest
All American
47902 Posts
user info
edit post

ok. so i get that i need to make a database to save the info.

dreamweaver has an XML file i can make.

but i dont know where to start with it. and the net isnt really helping. well im sure it is, but im not understanding a lot of it.

when i click new file->XML

its blank. what do i put.

5/15/2008 2:49:21 PM

baonest
All American
47902 Posts
user info
edit post

ok so godaddy.com can create me SQL database.

thats sounds easy enough. now i dont know how to incorporate that into the webpage comment code and the something.php code.

5/15/2008 3:41:31 PM

Fry
The Stubby
7781 Posts
user info
edit post

http://www.php-mysql-tutorial.com/

5/16/2008 12:45:14 AM

quagmire02
All American
44225 Posts
user info
edit post

i think this is a lot more complex than you're thinking it's going to be...it's not HARD, but there is a bit of a learning curve

the first thing you're going to want to do (IMO) is create your form with all the fields you're going to want...second, create your database with those fields as your columns...i don't know what database tool you're using or what kind of SQL database you're using, so you're going to have to be more specific or figure that out on your own

my suggestion, for now, is to not use "something.php" but instead put <?php $PHP_SELF ?> in there (so it will refer to itself once your submit your form instead of looking for another document)...this might help you learn a little more quickly

my suggestion would also be to create something like a "connect.php" page that will have your user name, password, database connection information, table name, and the actual connection script in it, so that you can just include it into any other page

on that form page (which will be a .php page), you're going to want something like this (though anyone feel free to correct me, i'm doing this just before i have a day of boring meetings ):

<?php
include("connect.php");

if(isset($_POST['submit'])) {

$author = $_POST['author'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$query = "INSERT INTO $table (ID, AUTHOR, EMAIL, COMMENT) VALUES (SEQ_COMMENTS_DB.nextval, '$author', '$email', '$comment')";

$statement = oci_parse($connect, $query);
oci_execute($statement);

oci_free_statement($statement);

?>


in this example, $table and $connect are defined in the connect.php file, and this is structured using oracle (which you probably won't be using, but really, the structure is very similar...you're probably using mysql, but i haven't used mysql in years so i don't remember off the top of my head what's different)

anyway, this is just your insertion into the database page...i'll come back and do a display page a bit later, but i gotta run right now

5/16/2008 9:38:40 AM

baonest
All American
47902 Posts
user info
edit post

good deal.

yeah. that link above your post has also helped.

im using godaddy hosting and they have 1 free SQL database i can make.

so it asks for a new table, i named it comment and "number of fields" is 3 ( Name, Email, Comment )

so then on this page i insert the fields. do i do anything to the other spaces?





im actually starting to get the hang of this. i think i can do most of it except setup the database with different variables here and there.

[Edited on May 16, 2008 at 10:08 AM. Reason : ]

5/16/2008 10:06:04 AM

robster
All American
3545 Posts
user info
edit post

welcome to the web. It only gets easier from here

5/16/2008 1:44:12 PM

 Message Boards » Tech Talk » comment box question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.